UNPKG

988 BJavaScriptView Raw
1(function(factory) {
2 if (typeof define === 'function' && define.amd) {
3 define(['jquery', 'hammerjs'], factory);
4 } else if (typeof exports === 'object') {
5 factory(require('jquery'), require('hammerjs'));
6 } else {
7 factory(jQuery, Hammer);
8 }
9}(function($, Hammer) {
10 function hammerify(el, options) {
11 var $el = $(el);
12 if(!$el.data("hammer")) {
13 $el.data("hammer", new Hammer($el[0], options));
14 }
15 }
16
17 $.fn.hammer = function(options) {
18 return this.each(function() {
19 hammerify(this, options);
20 });
21 };
22
23 // extend the emit method to also trigger jQuery events
24 Hammer.Manager.prototype.emit = (function(originalEmit) {
25 return function(type, data) {
26 originalEmit.call(this, type, data);
27 $(this.element).trigger({
28 type: type,
29 gesture: data
30 });
31 };
32 })(Hammer.Manager.prototype.emit);
33}));