Last active
December 12, 2015 06:39
-
-
Save Crisfole/4731104 to your computer and use it in GitHub Desktop.
My Backbone Base View (adds a few extra handy methods to Backbone.View) Notes: 1. I always use parentheses 2. I always include `return` except: * When returning `this` at the end of the method * When the method is a single line (in which case I like to put it in-line with the method name) 3. I tend to overuse fat-arrows. I'm totally aware of thi…
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
class CP.Views.BaseView extends Backbone.View | |
# Methods for showing and hiding the view | |
show: () => | |
@$el.show() | |
@ | |
hide: () => | |
@$el.hide() | |
@ | |
toggle: (show) => | |
@$el.toggle.apply(@$el, arguments) | |
@ | |
# Be sure to call `super()` in all subclasses' `unload` method | |
unload: () => | |
@off() | |
@undelegateEvents() | |
@ | |
# Methods for testing visibility and presence in Dom | |
# Thanks to SLaks (http://stackoverflow.com/a/3086084/456188) for the fastest way to do this. | |
inDom: () => $.contains(document.documentElement, @el) | |
isVisible: () => @$el.is(":visible") | |
onScreen: () => @inDom() and @isVisible() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that I recently switched to overriding the 'remove' method rather than using unload