2014-01-03 13:32:13 -05:00
|
|
|
CocoView = require './CocoView'
|
|
|
|
|
|
|
|
module.exports = class ModalView extends CocoView
|
2014-01-23 21:49:29 -05:00
|
|
|
className: "modal fade"
|
2014-01-03 13:32:13 -05:00
|
|
|
closeButton: true
|
|
|
|
closesOnClickOutside: true
|
|
|
|
modalWidthPercent: null
|
2014-04-10 14:13:33 -04:00
|
|
|
plain: false
|
2014-06-13 16:35:57 -04:00
|
|
|
|
|
|
|
events:
|
|
|
|
'click a': 'toggleModal'
|
|
|
|
'click button': 'toggleModal'
|
|
|
|
'click li': 'toggleModal'
|
2014-02-18 13:03:57 -05:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
shortcuts:
|
|
|
|
'esc': 'hide'
|
|
|
|
|
|
|
|
constructor: (options) ->
|
|
|
|
options ?= {}
|
|
|
|
@className = @className.replace " fade", "" if options.instant
|
|
|
|
@closeButton = options.closeButton if options.closeButton?
|
|
|
|
@modalWidthPercent = options.modalWidthPercent if options.modalWidthPercent
|
|
|
|
super options
|
|
|
|
|
2014-02-11 17:58:45 -05:00
|
|
|
getRenderData: (context={}) ->
|
2014-01-03 13:32:13 -05:00
|
|
|
context = super(context)
|
|
|
|
context.closeButton = @closeButton
|
|
|
|
context
|
|
|
|
|
|
|
|
subscriptions:
|
|
|
|
{}
|
|
|
|
|
|
|
|
afterRender: ->
|
|
|
|
super()
|
|
|
|
if @modalWidthPercent
|
2014-01-27 21:44:05 -05:00
|
|
|
@$el.find('.modal-dialog').css width: "#{@modalWidthPercent}%"
|
2014-02-18 13:03:57 -05:00
|
|
|
@$el.on 'hide.bs.modal', =>
|
2014-01-03 13:32:13 -05:00
|
|
|
@onHidden() unless @hidden
|
|
|
|
@hidden = true
|
2014-04-10 14:13:33 -04:00
|
|
|
@$el.find('.background-wrapper').addClass('plain') if @plain
|
2014-02-18 13:03:57 -05:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
afterInsert: ->
|
|
|
|
super()
|
|
|
|
# This makes sure if you press enter right after opening the players guide,
|
|
|
|
# it doesn't just reopen the modal.
|
|
|
|
$(document.activeElement).blur()
|
|
|
|
|
|
|
|
showLoading: ($el) ->
|
|
|
|
$el = @$el.find('.modal-body') unless $el
|
|
|
|
super($el)
|
|
|
|
|
2014-02-18 13:03:57 -05:00
|
|
|
hide: ->
|
2014-04-17 18:44:19 -04:00
|
|
|
@trigger 'hide'
|
2014-01-03 13:32:13 -05:00
|
|
|
@$el.removeClass('fade').modal "hide"
|
|
|
|
|
2014-02-18 13:03:57 -05:00
|
|
|
onHidden: ->
|
2014-04-17 18:44:19 -04:00
|
|
|
@trigger 'hidden'
|
2014-02-18 13:03:57 -05:00
|
|
|
|
|
|
|
destroy: ->
|
|
|
|
@hide() unless @hidden
|
|
|
|
@$el.off 'hide.bs.modal'
|
|
|
|
super()
|