Guest User

Untitled

a guest
Oct 15th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. class DOMWindow
  2. constructor: () ->
  3. @DOMWindowOverlay = '#DOMWindowOverlay'
  4. @_DOMWindowOverlay = @DOMWindowOverlay.replace(/^\#/,"")
  5. @DOMWindow = '#DOMWindow'
  6. @_DOMWindow = @DOMWindow.replace(/^\#/,"")
  7.  
  8. @Lightbox = ".view"
  9.  
  10. render: () ->
  11. $('body').append "<div id=\"#{@_DOMWindowOverlay}\"></div>"
  12. $(@DOMWindowOverlay).append "<div id=\"#{@_DOMWindow}\"></div>"
  13.  
  14. $('html').css
  15. overflow: "hidden"
  16. $(@DOMWindowOverlay).css
  17. overflow: 'hidden'
  18.  
  19. $(@DOMWindow).html "This sentence will be the view in the browser. Alternatively you can use Ajax (like $.ajax) to put contents."
  20.  
  21. w = $(@DOMWindow).children().outerWidth()
  22.  
  23. $(@DOMWindow).css
  24. position: 'fixed'
  25. top: document.documentElement.clientHeight
  26. 'margin-left': -1*w/2
  27.  
  28.  
  29. $(@DOMWindow).animate
  30. top: 50
  31. , 400 , =>
  32. $(@DOMWindow).css
  33. position: 'absolute'
  34. $(@DOMWindowOverlay).css
  35. 'overflow-x': 'auto'
  36. 'overflow-y': 'scroll'
  37.  
  38. # Bind event for Hide
  39. $(window).keydown (e) =>
  40. if e.which is 27 # ESC
  41. @hider()
  42. $(@DOMWindowOverlay + " .close").click (e) =>
  43. e.preventDefault()
  44. @hider()
  45.  
  46. hider: () ->
  47. $(@DOMWindowOverlay).css
  48. overflow: 'hidden'
  49. $(@DOMWindow).addClass 'rotation'
  50. $(@DOMWindow).css
  51. position: 'fixed'
  52. $(@DOMWindow).animate
  53. top: document.documentElement.clientHeight + 50
  54. , 200, =>
  55. $('html').css
  56. overflow: 'auto'
  57. $(@DOMWindowOverlay).fadeOut 100, () =>
  58. $(@DOMWindowOverlay).remove()
  59.  
  60.  
  61. $ ->
  62. dw = new DOMWindow()
  63. $(document).on "click", "#link-to-trigger-DOMWindow", (e) ->
  64. e.preventDefault()
  65. dw.render()
Add Comment
Please, Sign In to add comment