mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-24 16:17:57 -05:00
51 lines
No EOL
1.3 KiB
CoffeeScript
51 lines
No EOL
1.3 KiB
CoffeeScript
CocoView = require './CocoView'
|
|
|
|
module.exports = class ModalView extends CocoView
|
|
className: "modal hide fade"
|
|
modalTitle: "Man Bites God"
|
|
closeButton: true
|
|
closesOnClickOutside: true
|
|
modalWidthPercent: null
|
|
|
|
shortcuts:
|
|
'esc': 'hide'
|
|
|
|
constructor: (options) ->
|
|
options ?= {}
|
|
@className = @className.replace " fade", "" if options.instant
|
|
@closeButton = options.closeButton if options.closeButton?
|
|
@modalTitle = options.modalTitle if options.modalTitle
|
|
@modalWidthPercent = options.modalWidthPercent if options.modalWidthPercent
|
|
super options
|
|
|
|
getRenderData: (context={}) =>
|
|
context = super(context)
|
|
context.closeButton = @closeButton
|
|
context.modalTitle = @modalTitle
|
|
context
|
|
|
|
subscriptions:
|
|
{}
|
|
|
|
afterRender: ->
|
|
super()
|
|
if @modalWidthPercent
|
|
@$el.css width: "#{@modalWidthPercent}%", "margin-left": "#{-@modalWidthPercent / 2}%"
|
|
@$el.on 'hide', =>
|
|
@onHidden() unless @hidden
|
|
@hidden = true
|
|
|
|
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)
|
|
|
|
hide: ->
|
|
@$el.removeClass('fade').modal "hide"
|
|
|
|
onHidden: -> |