Skip to content

Instantly share code, notes, and snippets.

@derrickko
Created June 25, 2012 21:54
Show Gist options
  • Save derrickko/2991554 to your computer and use it in GitHub Desktop.
Save derrickko/2991554 to your computer and use it in GitHub Desktop.
Backbone View Manager
class ViewManager
containerId: "#mainContent"
constructor: ->
@container = $(@containerId)
@currentView = null
@modalView = null
Backbone.View::close = ->
@remove()
@unbind()
@onClose() if @onClose
show: (view) ->
@destroyModal if @modalView
@currentView.close() if @currentView
@currentView = view
@container.html @currentView.render().el
@container.fadeIn "fast"
destroyModal: ->
# modal destroy code
@modalView.close()
showModal: (view, opts) ->
@modalView.close() if @modalView
@modalView = view
# modal initialization code
@modalView
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment