Created
July 5, 2013 17:57
-
-
Save wookiehangover/5936165 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(function(root){ | |
var Backbone = root.Backbone; | |
var _ = root._; | |
var $ = Backbone.$; | |
if( !Backbone || !$.fn.hammer ){ | |
return; | |
} | |
var delegateEvents = Backbone.View.prototype.delegateEvents; | |
var undelegateEvents = Backbone.View.prototype.undelegateEvents; | |
Backbone.View.prototype.delegateEvents = function(){ | |
var events = this.hammerEvents; | |
if( events ){ | |
var options = this.hammerOptions || {}; | |
var hammerContext = _.extend({}, this, { | |
$el: this.hammer(options) | |
}); | |
delegateEvents.call(hammerContext, events); | |
} | |
return delegateEvents.apply(this, arguments); | |
}; | |
Backbone.View.prototype.undelegateEvents = function(){ | |
this.hammer().off('.delegateEvents' + this.cid); | |
return undelegateEvents.apply(this, arguments); | |
}; | |
Backbone.View.prototype.hammer = function(options){ | |
return this.$el.hammer(options); | |
}; | |
})(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi do you have a working sample for this plugin?