Created
August 10, 2012 08:19
-
-
Save fredsterss/3312580 to your computer and use it in GitHub Desktop.
KILL ALL ZOMBIES
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### | |
Example view usage | |
### | |
# add popovers to all elements | |
# with the popover class, but | |
# don't trigger the fuckers | |
$('.popover').popover({ trigger: 'manual' }) | |
# toggle the popover when the | |
# button is clicked | |
@$el.find('button.popover').on 'click', (e) -> | |
# toggle the popover | |
$(this).popover 'toggle' | |
### | |
We use a 'parent' app view | |
to load all other views into. | |
This guy forces some basic convention | |
on our views and cleans up all the mess we | |
leave. | |
### | |
class AppView extends Backbone.View | |
showView: (view) -> | |
# if a currentView exists, close | |
# it before rendering the new view | |
if @currentView? | |
# call the extended function | |
@currentView.close() | |
# then render the new view | |
@currentView = view | |
@currentView.render() | |
# and slot it into the DOM | |
$('#content').html(@currentView.el) | |
# Then extend the BBone.View to add | |
# some helper functions to kill | |
# all the zombies, format dates, | |
# interpret scores etc. (partial) | |
_.extend Backbone.View.prototype, { | |
# remove zombies when .close() is | |
# called on the view | |
close: -> | |
# remove all events | |
this.remove() | |
this.unbind() | |
# call the view's onclose | |
# function | |
if this.onClose | |
this.onClose() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment