Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Layout extends Backbone.Model
- content: "Empty"
- defaults:
- active: true
- initialize: ->
- toggle: ->
- @set 'active', !@get('active')
- collapse: ->
- @destroy()
- @view.remove()
- layoutList.last().set('active',true)
- class LayoutList extends Backbone.Collection
- model: Layout
- activeLayout: ->
- _.filter @, (layout) -> layout.get('active') is true
- disableAll: ->
- _.each @.toArray(), (layout) -> layout.set('active',false)
- class LayoutView extends Backbone.View
- tagName: "div"
- template: _.template $("#LayoutTemplate").html()
- events:
- "click .expand": "expand"
- "click .collapse": "collapse"
- expand: =>
- newLayout = new Layout()
- layoutList.add newLayout
- layoutList.disableAll()
- layoutList.last().set('active',true)
- collapse: ->
- @model.collapse()
- initialize: ->
- @model.bind 'change', @render
- @model.view = @
- render: =>
- templateHtml = @template
- layout: @model
- layoutCount: layoutList.length
- @.$el.html templateHtml
- @
- toggleActive: ->
- @model.toggle()
- remove: ->
- $(@el).remove()
- class App extends Backbone.View
- el: "#app"
- initialize : ->
- layoutList.bind 'add', @addOne
- layoutList.bind 'reset', @addAll
- layoutList.bind 'all', @render
- addOne: (layout) =>
- view = new LayoutView
- model: layout
- list: layoutList
- @.$el.append view.render().el
- addAll: ->
- layoutList.each @addOne
- render: =>
- @
- layoutList = new LayoutList()
- app = new App
- initLayout = new Layout()
- layoutList.add initLayout
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement