Skip to content

Instantly share code, notes, and snippets.

@davidvanleeuwen
Created May 9, 2013 19:49
Show Gist options
  • Save davidvanleeuwen/5550062 to your computer and use it in GitHub Desktop.
Save davidvanleeuwen/5550062 to your computer and use it in GitHub Desktop.
class Backbone.Marionette.Modals extends Backbone.Marionette.Region
modals: []
zIndex: 0
show: (modal, options = {}) ->
@ensureEl()
modal.render()
@$el.append modal.el
Marionette.triggerMethod.call(modal, "show")
Marionette.triggerMethod.call(this, "show", modal)
@currentView = modal
@modals.push(modal)
@zIndex++
close: ->
modal = @currentView
return if !modal or modal.isClosed
if modal.close
modal.close()
else if modal.remove
modal.remove()
@modals.splice(_.indexOf(@modals, modal), 1)
@zIndex--
@currentView = @modals[@zIndex-1]
Marionette.triggerMethod.call(this, "close")
closeAll: ->
@close() for modal in @modals
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment