Guest User

Untitled

a guest
Dec 11th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.28 KB | None | 0 0
  1. orderCats = (old, member) ->
  2. +$(old).data('order') - +$(member).data('order')
  3.  
  4. class App.CatsView extends Backbone.View
  5. events: ->
  6. 'mouseenter li': 'showFoto'
  7. 'mouseleave li': 'hideFoto'
  8. 'click .category': 'goToCat'
  9.  
  10. blockToCat: false
  11.  
  12. insideDishes: false
  13.  
  14. changingCat: false
  15.  
  16. changeCat: (evt) ->
  17. newCatId = $(evt.currentTarget).find('a').data('id')
  18. newCat = App.categories.get(newCatId)
  19.  
  20. unless @changingCat
  21. @changingCat = true
  22. App.currentCatView.exit =>
  23. App.currentCatView = new App.CategoryView
  24. el: '#cat-list'
  25. model: newCat
  26. App.currentCatView.show true, =>
  27. @changingCat = false
  28. App.currentCatView.select()
  29. App.menuView.updateSubMenu()
  30. , {}, true
  31.  
  32. goToCat: (evt) ->
  33. id = evt.currentTarget.id
  34.  
  35. if !@blockToCat and id != 'download' and !@insideDishes
  36.  
  37. @insideDishes = true
  38.  
  39. App.menuView.blocked = true
  40. @blockToCat = true
  41.  
  42. boxes = @$el.find('.category').not("##{id}").get().sort(orderCats)
  43. boxes.push(evt.currentTarget)
  44.  
  45. seedtime = 0
  46. speed = 180
  47. ended = 0
  48. size = boxes.length
  49.  
  50. $(boxes).each (i, box) =>
  51. setTimeout =>
  52. self = this
  53. $(box).fadeTo 500, 0, ->
  54. ended++
  55. if ended == size
  56. $(boxes).css('display', 'none')
  57. App.currentCatView = new App.CategoryView
  58. el: '#cat-list'
  59. model: App.categories.get(+this.id.split("-").last())
  60. App.currentCatView.show true, ->
  61. App.menuView.updateSubMenu()
  62. self.showTopCats(true)
  63. , seedtime
  64. seedtime += speed
  65.  
  66. fadeOutCats: (elem, callback) ->
  67. # (elem, ->)
  68. # (->)
  69. if !callback and $.isFunction(elem)
  70. callback = elem
  71. elem = null
  72.  
  73. boxes = []
  74.  
  75. App.menuView.blocked = true
  76. @blockToCat = true
  77.  
  78. if elem
  79. id = elem.id
  80. boxes = @$el.find('.category').not("##{id}").get().sort(orderCats)
  81. boxes.push(elem)
  82. else
  83. boxes = @$el.find('.category').get().sort(orderCats)
  84.  
  85. seedtime = 0
  86. speed = 180
  87. ended = 0
  88. size = boxes.length
  89.  
  90. $(boxes).each (i, box) =>
  91. setTimeout =>
  92. self = this
  93. $(box).fadeTo 500, 0, ->
  94. ended++
  95. if ended == size
  96. $(boxes).css('display', 'none')
  97. callback?.call(this)
  98. , seedtime
  99. seedtime += speed
  100.  
  101.  
  102. showTopCats: (animate) ->
  103. distance = $('html').width() - $('#menu').offset().left + 5
  104.  
  105. if animate
  106. $.notOverflow (restore) =>
  107. @placeSubElement '#line1', distance, =>
  108. @showSubMenu true, =>
  109. @placeSubElement '#line2', distance, =>
  110. @placeSubElement '#dload', distance, =>
  111. App.menuView.blocked = false
  112. @blockToCat = false
  113. restore()
  114. else
  115. $('#line1').css {top: '0px', display: 'block'}
  116. @showSubMenu(false)
  117. $('#line2').css {top: '0px', display: 'block'}
  118. $('#dload').css
  119. 'top': '0px'
  120. '*display': 'inline'
  121. 'zoom': 1
  122. 'display': 'inline-block'
  123.  
  124. showSubMenu: (animate, callback) ->
  125. distance = $('html').width() - $('#menu').offset().left + 5
  126.  
  127. smenu = $('#submenu')
  128.  
  129. if $.trim(smenu.html()) == ''
  130. html = @collection.reduce (final, cat, it) =>
  131. final += "<li class='subcat #{if cat == App.currentCat then 'selected' else ''}'>\
  132. <a href='javascript:void(0);' data-id='#{cat.id}'>#{cat.get('name')}</a>#{ if it < @collection.size() - 1 then "<span class='point'>.</span>" else ''}</li>"
  133. , ""
  134.  
  135. smenu.html(html).css({
  136. left: "#{if animate then distance else 0}px",
  137. width: $('#menu').width(),
  138. display: 'block'
  139. })
  140.  
  141. if animate
  142. smenu.css('display', 'block').animate {left: '0px'}, 1000, callback
  143. else
  144. callback?()
  145.  
  146. placeSubElement: (elem, distance, cb) ->
  147. $(elem).css({
  148. left: "#{distance}px",
  149. display: 'block'
  150. }).animate {left: '0px'}, 1000, -> cb?()
  151.  
  152. exit: (afterFunction, data) ->
  153. if not @insideDishes
  154. @$el.css('display', 'none')
  155. @insideDishes = false
  156. afterFunction()
  157. else
  158. @hideSubMenus true, =>
  159. App.currentCatView.exit =>
  160. @insideDishes = false
  161. afterFunction()
  162. , data
  163.  
  164. hideSubMenus: (animate, callback) ->
  165. distance = $('html').width() - $('#menu').offset().left + 5
  166. dpx = "#{distance}px"
  167. if animate
  168. $.notOverflow (restore) =>
  169. self = this
  170. $('#dload').fadeOut(1000).animate {left: dpx}, {
  171. duration: 1000
  172. queue: false
  173. complete: ->
  174. $('#line2').fadeOut(1000).animate {left: dpx}, {
  175. duration: 1000
  176. queue: false
  177. complete: ->
  178. $('#submenu').css('left', '0px').fadeOut(1000).animate {left: dpx}, {
  179. duration: 1000
  180. queue: false
  181. complete: ->
  182. $('#line1').fadeOut(1000).animate {left: dpx}, {
  183. duration: 1000
  184. queue: false
  185. complete: ->
  186. restore()
  187. callback?()
  188. }
  189. }
  190. }
  191. }
  192.  
  193. appear: (cb) ->
  194. @$el.css('display', 'block')
  195. App.router.to('menus')
  196. @show true, cb
  197.  
  198. showFoto: (evt) ->
  199. evt.stopPropagation()
  200.  
  201. li = $(evt.currentTarget)
  202. li.find('.backimage').fadeIn()
  203.  
  204. hideFoto: (evt) ->
  205. evt.stopPropagation()
  206.  
  207. li = $(evt.currentTarget)
  208. li.find('.backimage').fadeOut()
  209.  
  210. show: (animate, callback) ->
  211. # Hide the intro
  212. $('#intro').css('display', 'none')
  213. # Go Menu
  214. App.menuView.go('#to-cats')
  215. # Position things
  216. @positionLogo()
  217. @positionCategories()
  218. # Categories!
  219. if animate
  220. @randomPositionCategories(callback)
  221. else
  222. @staticPositionCategories()
  223. callback?()
  224.  
  225. positionCategories: ->
  226. templ = (cat, text) =>
  227. id = if cat.id then "cate-#{cat.id}" else cat
  228. foto = if cat.get then cat.get('foto') else ""
  229. $.trim("""
  230. <li class="category" id="#{id}" data-order="#{if cat.get then cat.get('order') else @collection.length + 1}">
  231. <div class="backimage">
  232. #{if cat.get then "<img src=#{foto}>" else ""}
  233. </div>
  234. <div class="phantomparent">
  235. <a href="javascript:void();">
  236. #{if cat.get then cat.get('name') else text}
  237. </a>
  238. <a href="javascript:void();" class="phantom">lorem ipsum</a>
  239. </div>
  240. </li>
  241. """)
  242.  
  243. list = @collection.reduce (end, cat) ->
  244. end += templ(cat)
  245. , ""
  246.  
  247. # Download Button
  248. list += templ('download', 'Download PDF')
  249.  
  250. @$el.html("<ul>#{list}</ul>")
  251.  
  252. staticPositionCategories: ->
  253. @$el.find('.category').css('visibility', 'visible')
  254.  
  255. randomPositionCategories: (callback) ->
  256. boxes = $(@$el.find('.category').get().sort(orderCats))
  257.  
  258. boxes.css
  259. opacity: '0'
  260. visibility: 'visible'
  261.  
  262. seedtime = 0
  263. speed = 180
  264.  
  265. boxes.each (i, box) ->
  266. setTimeout =>
  267. $(box).fadeTo 500, 1, ->
  268. if i == boxes.length - 1
  269. callback?()
  270. , seedtime
  271. seedtime += speed
  272.  
  273. positionLogo: ->
  274. $('#aside-logo').css
  275. display: 'block'
  276. top: '0px'
Add Comment
Please, Sign In to add comment