Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###
- @author Dawid Winiarczyk <dawid.winiarczyk@gmail.com>
- generated by js2coffee.org
- ###
- app.namespace 'app.core.popupsHtml'
- app.core.popupsHtml =
- _cache: {}
- _default: {}
- _tmp:
- opened: []
- z_index: 100
- init: ->
- @_default =
- on_show: @closeAll # setIndex || closeAll
- force_stay: false # with false while execute closeAll method this popup will be skipped
- overlay: false
- return
- setIndex: ->
- @node.style.zIndex = app.core.popups._tmp.z_index++
- return
- closePopup: (pVal) ->
- pVal = @getCache(pVal) if 'string' is typeof pVal
- return if false is @isShowed(pVal.node.id)
- pVal.node.className += ' hidden'
- index = @_tmp.opened.indexOf(pVal)
- @_tmp.opened.slice index, 1
- return
- closeAll: ->
- that = app.core.popups
- i = 0
- while i < that._tmp.opened.length
- popup = that._tmp.opened[i]
- that.closePopup popup if false is popup.cfg.force_stay
- i++
- return
- setConfig: (pNode) ->
- nodeOnShow = pNode.getAttribute('data-on-show')
- nodeForceStay = pNode.getAttribute('data-force-stay')
- nodeForceStay = 'true' is nodeForceStay if 'string' is typeof nodeOverlay
- nodeOverlay = pNode.getAttribute('data-overlay')
- nodeOverlay = 'true' is nodeOverlay if 'string' is typeof nodeOverlay
- force_stay: nodeForceStay or @_default.force_stay
- on_show: this[nodeOnShow] or @_default.on_show
- overlay: nodeOverlay or @_default.overlay
- pushCache: (pId) ->
- node = document.getElementById(pId)
- throw new Error('#' + pId + ' not found') if null is node
- @_cache[pId] =
- node: node
- cfg: @setConfig(node)
- getCache: (pId) ->
- return @_cache[pId] if @_cache[pId]
- @pushCache pId
- isShowed: (pId) ->
- -1 >= @getCache(pId).node.className.indexOf('hidden')
- showOverlay: (pId) ->
- popup = @getCache(pId)
- return false if false is popup.cfg.overlay
- overlay = document.getElementById('overlay')
- overlay.className = 'overlay'
- return
- hideOverlay: ->
- overlay = document.getElementById('overlay')
- return if null is overlay
- overlay.className = 'overlay hidden'
- return
- show: (pId, pCallback) ->
- return if @isShowed(pId)
- pCallback = pCallback or ->
- popup = @getCache(pId)
- popup.cfg.on_show.call popup
- @showOverlay pId
- @_tmp.opened.push popup
- popup.node.className = popup.node.className.replace('hidden', '')
- pCallback()
- return
- hide: (pId) ->
- @closePopup pId
- @closeAll()
- @hideOverlay()
- return
- app.core.popupsHtml.init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement