Sha256: 99dfb1e0f30c8e718d2d40c8cfc847dceec1e35e644203a27e2d28719950b9a8

Contents?: true

Size: 1.65 KB

Versions: 10

Compression:

Stored size: 1.65 KB

Contents

unless Backbone?
  throw new Error("Backbone is not defined. Please include the latest version from http://documentcloud.github.com/backbone/backbone.js")

class Backbone.Marionette.Modals extends Backbone.Marionette.Region
  modals: []
  zIndex: 0

  show: (modal, options = {}) ->
    @ensureEl()

    if @modals.length > 0
      lastModal = _.last(@modals)
      lastModal.modalEl.addClass("#{lastModal.prefix}-modal--stacked")
      secondLastModal = @modals[@modals.length-1]
      secondLastModal?.modalEl.removeClass("#{secondLastModal.prefix}-modal--stacked-reverse")

    modal.render()
    modal.regionEnabled = true

    @$el.show()
    @$el.append modal.el

    modal.$el.css(background: 'none') if @modals.length > 0

    Marionette.triggerMethod.call(modal, "show")
    Marionette.triggerMethod.call(this, "show", modal)

    @currentView = modal

    m.undelegateModalEvents() for m in @modals

    modal.on('modal:close', @close)

    @modals.push(modal)
    @zIndex++

  close: =>
    modal = @currentView
    return if !modal or modal.isClosed

    if modal.close
      modal.close()
    else if modal.remove
      modal.remove()

    modal.off('modal:close', @close)

    @modals.splice(_.indexOf(@modals, modal), 1)

    @zIndex--

    @currentView  = @modals[@zIndex-1]

    lastModal     = _.last(@modals)

    if lastModal
      lastModal.modalEl.addClass("#{lastModal.prefix}-modal--stacked-reverse")
      _.delay =>
        lastModal.modalEl.removeClass("#{lastModal.prefix}-modal--stacked")
      , 300

      lastModal.delegateModalEvents() if @zIndex isnt 0

    Marionette.triggerMethod.call(this, "close")

  closeAll: ->
    @close() for modal in @modals

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
marionette-modal-1.0.0.9 src/backbone.marionette.modals.coffee
marionette-modal-1.0.0.8 src/backbone.marionette.modals.coffee
marionette.modal-1.0.0.7 src/backbone.marionette.modals.coffee
marionette.modal-1.0.0.6 src/backbone.marionette.modals.coffee
marionette.modal-1.0.0.5 src/backbone.marionette.modals.coffee
marionette.modal-1.0.0.4 src/backbone.marionette.modals.coffee
marionette.modal-1.0.0.3 src/backbone.marionette.modals.coffee
marionette.modal-1.0.0.2 src/backbone.marionette.modals.coffee
marionette.modal-1.0.0.1 src/backbone.marionette.modals.coffee
marionette.modal-1.0.0 src/backbone.marionette.modals.coffee