-
-
Save phindmarsh/3444127 to your computer and use it in GitHub Desktop.
Hammer.js integration with AngularJS without the jQuery plugin
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
/** | |
* Inspired by AngularJS' implementation of "click dblclick mousedown..." | |
* | |
* This ties in the Hammer events to attributes like: | |
* | |
* hm-tap="add_something()" | |
* hm-swipe="remove_something()" | |
* | |
* and also has support for Hammer options with: | |
* | |
* hm-tap-opts="{hold: false}" | |
* | |
* or any other of the "hm-event" listed underneath. | |
*/ | |
angular.forEach('hmTap:tap hmDoubletap:doubletap hmHold:hold hmTransformstart:transformstart hmTransform:transform hmTransforend:transformend hmDragstart:dragstart hmDrag:drag hmDragend:dragend hmSwipe:swipe hmRelease:release'.split(' '), function(name) { | |
var directive = name.split(':'); | |
var directiveName = directive[0]; | |
var eventName = directive[1]; | |
pmk.directive(directiveName, ['$parse', function($parse) { | |
return function(scope, element, attr) { | |
var fn = $parse(attr[directiveName]), | |
opts = $parse(attr[directiveName + 'Opts'])(scope, {}), | |
hammer = new Hammer(element[0], opts); | |
hammer['on'+ eventName] = function(event) { | |
scope.$apply(function(){ | |
fn(scope, {$event:event}); | |
}) | |
}; | |
}; | |
}]); | |
}); |
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
somewhere near the bottom of the page: | |
<!-- Hammer JS for multi-touch events --> | |
<script src="static/js/libs/hammer.js"></script> | |
<!-- AngularJS libs --> | |
<script src="static/js/libs/angular/angular-1.0.1.min.js"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment