SHARE
TWEET

Untitled

a guest Nov 12th, 2019 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ###
  2. @author Dawid Winiarczyk <dawid.winiarczyk@gmail.com>
  3. generated by js2coffee.org
  4. ###
  5. app.namespace 'app.core.popupsHtml'
  6. app.core.popupsHtml =
  7.     _cache: {}
  8.     _default: {}
  9.     _tmp:
  10.         opened: []
  11.         z_index: 100
  12.  
  13.     init: ->
  14.         @_default =
  15.             on_show: @closeAll # setIndex || closeAll
  16.             force_stay: false # with false while execute closeAll method this popup will be skipped
  17.             overlay: false
  18.  
  19.         return
  20.  
  21.     setIndex: ->
  22.         @node.style.zIndex = app.core.popups._tmp.z_index++
  23.         return
  24.  
  25.     closePopup: (pVal) ->
  26.         pVal = @getCache(pVal)  if 'string' is typeof pVal
  27.         return  if false is @isShowed(pVal.node.id)
  28.         pVal.node.className += ' hidden'
  29.         index = @_tmp.opened.indexOf(pVal)
  30.         @_tmp.opened.slice index, 1
  31.         return
  32.  
  33.     closeAll: ->
  34.         that = app.core.popups
  35.         i = 0
  36.  
  37.         while i < that._tmp.opened.length
  38.             popup = that._tmp.opened[i]
  39.             that.closePopup popup  if false is popup.cfg.force_stay
  40.             i++
  41.         return
  42.  
  43.     setConfig: (pNode) ->
  44.         nodeOnShow = pNode.getAttribute('data-on-show')
  45.         nodeForceStay = pNode.getAttribute('data-force-stay')
  46.         nodeForceStay = 'true' is nodeForceStay  if 'string' is typeof nodeOverlay
  47.         nodeOverlay = pNode.getAttribute('data-overlay')
  48.         nodeOverlay = 'true' is nodeOverlay  if 'string' is typeof nodeOverlay
  49.         force_stay: nodeForceStay or @_default.force_stay
  50.         on_show: this[nodeOnShow] or @_default.on_show
  51.         overlay: nodeOverlay or @_default.overlay
  52.  
  53.     pushCache: (pId) ->
  54.         node = document.getElementById(pId)
  55.         throw new Error('#' + pId + ' not found')  if null is node
  56.         @_cache[pId] =
  57.             node: node
  58.             cfg: @setConfig(node)
  59.  
  60.     getCache: (pId) ->
  61.         return @_cache[pId]  if @_cache[pId]
  62.         @pushCache pId
  63.  
  64.     isShowed: (pId) ->
  65.         -1 >= @getCache(pId).node.className.indexOf('hidden')
  66.  
  67.     showOverlay: (pId) ->
  68.         popup = @getCache(pId)
  69.         return false  if false is popup.cfg.overlay
  70.         overlay = document.getElementById('overlay')
  71.         overlay.className = 'overlay'
  72.         return
  73.  
  74.     hideOverlay: ->
  75.         overlay = document.getElementById('overlay')
  76.         return  if null is overlay
  77.         overlay.className = 'overlay hidden'
  78.         return
  79.  
  80.     show: (pId, pCallback) ->
  81.         return  if @isShowed(pId)
  82.         pCallback = pCallback or ->
  83.  
  84.         popup = @getCache(pId)
  85.         popup.cfg.on_show.call popup
  86.         @showOverlay pId
  87.         @_tmp.opened.push popup
  88.         popup.node.className = popup.node.className.replace('hidden', '')
  89.         pCallback()
  90.         return
  91.  
  92.     hide: (pId) ->
  93.         @closePopup pId
  94.         @closeAll()
  95.         @hideOverlay()
  96.         return
  97.  
  98. app.core.popupsHtml.init()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top