app/assets/javascripts/backbone/views/popup/_popup.js.coffee
589014c7
 Xmpp.Views.Popup ||= {}
 
 class Xmpp.Views.Popup.PopupView extends Backbone.View
   superTemplate: JST["backbone/templates/popup/popup"]
0e8bb3a5
   el: $('#js-popups')
589014c7
 
0e8bb3a5
   @popups = {}
 
   constructor: ->
     super
     PopupView.popups[@cid] = this
 
   superEvents: ->
     result = {}
     result["click .#{@className} .close"] = 'close'
     result
910e0f23
 
589014c7
   render: (childHtml) ->
0e8bb3a5
     $(@el).find('.popup').hide()
     _.each(PopupView.popups, (view) ->
       view.undelegateEvents()
     )
 
     thisView = PopupView.popups[@cid]
     thisView.delegateEvents()
 
     $(@el).append(@superTemplate(inside: childHtml, class: @className))
6f81cea1
     $('.inactive-layer').fadeIn(50)
910e0f23
 
   close: (e) ->
     e.preventDefault()
0e8bb3a5
     @remove(e)
6f81cea1
     $('.inactive-layer').fadeOut(50)
910e0f23
 
0e8bb3a5
   remove: (e) ->
910e0f23
     @stopListening()
0e8bb3a5
     @undelegateEvents()
     $(e.currentTarget).closest('.popup').remove()
 
     delete PopupView.popups[@cid]
 
     firstFoundView = _.find(PopupView.popups, (view) -> view) # najde prvy view
     if firstFoundView
       $(@el).find('.popup').first().show()
       firstFoundView.delegateEvents()