2014-01-03 13:32:13 -05:00
|
|
|
CocoView = require './CocoView'
|
|
|
|
|
|
|
|
module.exports = class ModalView extends CocoView
|
2014-06-30 22:16:26 -04: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-08-31 18:08:52 -04:00
|
|
|
instant: false
|
2014-11-29 14:39:37 -05:00
|
|
|
template: require 'templates/core/modal-base'
|
2014-06-30 22:16:26 -04:00
|
|
|
|
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) ->
|
2015-10-13 11:22:13 -04:00
|
|
|
@className = @className.replace ' fade', '' if options?.instant or @instant
|
|
|
|
@closeButton = options.closeButton if options?.closeButton?
|
|
|
|
@modalWidthPercent = options.modalWidthPercent if options?.modalWidthPercent
|
2015-10-12 19:46:30 -04:00
|
|
|
super arguments...
|
2015-10-13 11:22:13 -04:00
|
|
|
@options ?= {}
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
subscriptions:
|
|
|
|
{}
|
|
|
|
|
|
|
|
afterRender: ->
|
|
|
|
super()
|
2014-07-08 02:23:36 -04:00
|
|
|
if Backbone.history.fragment is "employers"
|
|
|
|
$(@$el).find(".background-wrapper").each ->
|
|
|
|
$(this).addClass("employer-modal-background-wrapper").removeClass("background-wrapper")
|
2014-08-31 18:08:52 -04:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
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)
|
|
|
|
|
2016-08-15 15:43:28 -04:00
|
|
|
# TODO: Combine hide/onHidden such that backbone 'hide/hidden.bs.modal' events and our 'hide/hidden' events are more 1-to-1
|
|
|
|
# For example:
|
|
|
|
# pressing 'esc' or using `currentModal.hide()` triggers 'hide', 'hide.bs.modal', 'hidden', 'hidden.bs.modal'
|
|
|
|
# clicking outside the modal triggers 'hide.bs.modal', 'hidden', 'hidden.bs.modal' (but not 'hide')
|
2014-02-18 13:03:57 -05:00
|
|
|
hide: ->
|
2014-04-17 18:44:19 -04:00
|
|
|
@trigger 'hide'
|
2016-08-15 15:43:28 -04:00
|
|
|
@$el.removeClass('fade').modal 'hide' unless @destroyed
|
2014-01-03 13:32:13 -05:00
|
|
|
|
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()
|