(function(factory) { if (typeof define === 'function' && define.amd) { define(['jquery', 'hammerjs'], factory); } else if (typeof exports === 'object') { factory(require('jquery'), require('hammerjs')); } else { factory(jquery, hammer); } }(function($, hammer) { function hammerify(el, options) { var $el = $(el); if(!$el.data("hammer")) { $el.data("hammer", new hammer($el[0], options)); } } $.fn.hammer = function(options) { return this.each(function() { hammerify(this, options); }); }; // extend the emit method to also trigger jquery events hammer.manager.prototype.emit = (function(originalemit) { return function(type, data) { originalemit.call(this, type, data); $(this.element).trigger({ type: type, gesture: data }); }; })(hammer.manager.prototype.emit); }));