Created
May 20, 2014 17:02
-
-
Save ppcano/7a5f0e551cd9b2db42b0 to your computer and use it in GitHub Desktop.
hammerJS + ember integration
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
Em.View.reopen({ | |
hammerOptions: null, | |
enableHammer: function() { | |
var gestures = ['drag', 'hold', 'release', 'swipe', 'tap', 'touch', 'transform']; | |
var options = this.get('hammerOptions'); | |
if ( options ) { | |
gestures.forEach(function(gesture) { | |
if ( !options[gesture] ) { | |
options[gesture] = false; | |
} | |
}); | |
this.hammer = new Hammer(this.get('element'), options); | |
} | |
}.on('didInsertElement'), | |
destroyHammer: function() { | |
if (this.hammer) { | |
this.hammer.dispose(); | |
this.hammer = null; | |
} | |
}.on('willDestroyElement') | |
}); | |
Ember.EventDispatcher.reopen({ | |
events: { | |
tap : 'tap', | |
click : 'click', // manage to preventDefault link-to views | |
focusin : 'focusIn', | |
focusout : 'focusOut', | |
submit : 'submit', | |
input : 'input', | |
change : 'change' | |
}, | |
_findNearestEventManager: function() { | |
return null; | |
} | |
}); | |
Ember.LinkView.reopen({ | |
hammerOptions: { | |
tap: true | |
}, | |
eventName: 'tap', | |
click: function(event) { | |
event.preventDefault(); | |
} | |
}); |
@mohamnag, below a possible integration. You could also ask in stackoverflow:
setupTap: function() {
this._super();
var self = this;
this.hammer = new Hammer(this.get('element'), {recognizers: []});
var tap = new Hammer.Tap();
tap.set('enable', function() {
return self.canRecognizeTap();
});
this.hammer.add(tap);
this.hammer.on('tap', function() {
self.tap();
});
}.on('didInsertElement')
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sorry for dummy question but I dont find how can I handle the events like swipe in my view. I tried to define a handler for swipe like this:
but non of the tap nor swipe events ever fire.
Im using ember 1.6.1 and hammer 2.0.2