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(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@mohamnag, below a possible integration. You could also ask in stackoverflow:
setupTap: function() {
this._super();
}.on('didInsertElement')