From c9711ac6fe03f9bd453dbeb61fb494eae25376b1 Mon Sep 17 00:00:00 2001 From: Jan Nicklas Date: Sun, 11 Aug 2013 11:40:32 +0200 Subject: [PATCH 1/2] Fixes issue #331 - "jquery.hammer.js can't used in requirejs" --- dist/jquery.hammer.js | 19 +++++++++++++++---- dist/jquery.hammer.min.js | 3 +-- plugins/jquery.hammer.js | 19 +++++++++++++++---- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/dist/jquery.hammer.js b/dist/jquery.hammer.js index d135a9991..f4b36b637 100644 --- a/dist/jquery.hammer.js +++ b/dist/jquery.hammer.js @@ -1435,12 +1435,13 @@ else { })(this); -(function($, undefined) { - 'use strict'; +(function(undefined) { + 'use strict'; + var init = function(Hammer, $) { // no jQuery or Zepto! if($ === undefined) { - return; + return Hammer; } /** @@ -1541,4 +1542,14 @@ else { }); }; -})(window.jQuery || window.Zepto); + return Hammer; + }; + + + if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) { + define(["hammer", "jquery"], init); + } else { + init(window.Hammer, window.jQuery || window.Zepto); + } + +}()); diff --git a/dist/jquery.hammer.min.js b/dist/jquery.hammer.min.js index 9620ddf56..a9bd98f0c 100644 --- a/dist/jquery.hammer.min.js +++ b/dist/jquery.hammer.min.js @@ -3,5 +3,4 @@ * * Copyright (c) 2013 Jorik Tangelder ; * Licensed under the MIT license */ - -(function(t,e){"use strict";function n(){if(!i.READY){i.event.determineEventTypes();for(var t in i.gestures)i.gestures.hasOwnProperty(t)&&i.detection.register(i.gestures[t]);i.event.onTouch(i.DOCUMENT,i.EVENT_MOVE,i.detection.detect),i.event.onTouch(i.DOCUMENT,i.EVENT_END,i.detection.detect),i.READY=!0}}var i=function(t,e){return new i.Instance(t,e||{})};i.defaults={stop_browser_behavior:{userSelect:"none",touchAction:"none",touchCallout:"none",contentZooming:"none",userDrag:"none",tapHighlightColor:"rgba(0,0,0,0)"}},i.HAS_POINTEREVENTS=t.navigator.pointerEnabled||t.navigator.msPointerEnabled,i.HAS_TOUCHEVENTS="ontouchstart"in t,i.MOBILE_REGEX=/mobile|tablet|ip(ad|hone|od)|android|silk/i,i.NO_MOUSEEVENTS=i.HAS_TOUCHEVENTS&&t.navigator.userAgent.match(i.MOBILE_REGEX),i.EVENT_TYPES={},i.DIRECTION_DOWN="down",i.DIRECTION_LEFT="left",i.DIRECTION_UP="up",i.DIRECTION_RIGHT="right",i.POINTER_MOUSE="mouse",i.POINTER_TOUCH="touch",i.POINTER_PEN="pen",i.EVENT_START="start",i.EVENT_MOVE="move",i.EVENT_END="end",i.DOCUMENT=t.document,i.plugins={},i.READY=!1,i.Instance=function(t,e){var r=this;return n(),this.element=t,this.enabled=!0,this.options=i.utils.extend(i.utils.extend({},i.defaults),e||{}),this.options.stop_browser_behavior&&i.utils.stopDefaultBrowserBehavior(this.element,this.options.stop_browser_behavior),i.event.onTouch(t,i.EVENT_START,function(t){r.enabled&&i.detection.startDetect(r,t)}),this},i.Instance.prototype={on:function(t,e){for(var n=t.split(" "),i=0;n.length>i;i++)this.element.addEventListener(n[i],e,!1);return this},off:function(t,e){for(var n=t.split(" "),i=0;n.length>i;i++)this.element.removeEventListener(n[i],e,!1);return this},trigger:function(t,e){var n=i.DOCUMENT.createEvent("Event");n.initEvent(t,!0,!0),n.gesture=e;var r=this.element;return i.utils.hasParent(e.target,r)&&(r=e.target),r.dispatchEvent(n),this},enable:function(t){return this.enabled=t,this}};var r=null,o=!1,a=!1;i.event={bindDom:function(t,e,n){for(var i=e.split(" "),r=0;i.length>r;r++)t.addEventListener(i[r],n,!1)},onTouch:function(t,e,n){var s=this;this.bindDom(t,i.EVENT_TYPES[e],function(c){var u=c.type.toLowerCase();if(!u.match(/mouse/)||!a){u.match(/touch/)||u.match(/pointerdown/)||u.match(/mouse/)&&1===c.which?o=!0:u.match(/mouse/)&&1!==c.which&&(o=!1),u.match(/touch|pointer/)&&(a=!0);var h=0;o&&(i.HAS_POINTEREVENTS&&e!=i.EVENT_END?h=i.PointerEvent.updatePointer(e,c):u.match(/touch/)?h=c.touches.length:a||(h=u.match(/up/)?0:1),h>0&&e==i.EVENT_END?e=i.EVENT_MOVE:h||(e=i.EVENT_END),(h||null===r)&&(r=c),n.call(i.detection,s.collectEventData(t,e,s.getTouchList(r,e),c)),i.HAS_POINTEREVENTS&&e==i.EVENT_END&&(h=i.PointerEvent.updatePointer(e,c))),h||(r=null,o=!1,a=!1,i.PointerEvent.reset())}})},determineEventTypes:function(){var t;t=i.HAS_POINTEREVENTS?i.PointerEvent.getEvents():i.NO_MOUSEEVENTS?["touchstart","touchmove","touchend touchcancel"]:["touchstart mousedown","touchmove mousemove","touchend touchcancel mouseup"],i.EVENT_TYPES[i.EVENT_START]=t[0],i.EVENT_TYPES[i.EVENT_MOVE]=t[1],i.EVENT_TYPES[i.EVENT_END]=t[2]},getTouchList:function(t){return i.HAS_POINTEREVENTS?i.PointerEvent.getTouchList():t.touches?t.touches:(t.indentifier=1,[t])},collectEventData:function(t,e,n,r){var o=i.POINTER_TOUCH;return(r.type.match(/mouse/)||i.PointerEvent.matchType(i.POINTER_MOUSE,r))&&(o=i.POINTER_MOUSE),{center:i.utils.getCenter(n),timeStamp:(new Date).getTime(),target:r.target,touches:n,eventType:e,pointerType:o,srcEvent:r,preventDefault:function(){this.srcEvent.preventManipulation&&this.srcEvent.preventManipulation(),this.srcEvent.preventDefault&&this.srcEvent.preventDefault()},stopPropagation:function(){this.srcEvent.stopPropagation()},stopDetect:function(){return i.detection.stopDetect()}}}},i.PointerEvent={pointers:{},getTouchList:function(){var t=this,e=[];return Object.keys(t.pointers).sort().forEach(function(n){e.push(t.pointers[n])}),e},updatePointer:function(t,e){return t==i.EVENT_END?this.pointers={}:(e.identifier=e.pointerId,this.pointers[e.pointerId]=e),Object.keys(this.pointers).length},matchType:function(t,e){if(!e.pointerType)return!1;var n={};return n[i.POINTER_MOUSE]=e.pointerType==e.MSPOINTER_TYPE_MOUSE||e.pointerType==i.POINTER_MOUSE,n[i.POINTER_TOUCH]=e.pointerType==e.MSPOINTER_TYPE_TOUCH||e.pointerType==i.POINTER_TOUCH,n[i.POINTER_PEN]=e.pointerType==e.MSPOINTER_TYPE_PEN||e.pointerType==i.POINTER_PEN,n[t]},getEvents:function(){return["pointerdown MSPointerDown","pointermove MSPointerMove","pointerup pointercancel MSPointerUp MSPointerCancel"]},reset:function(){this.pointers={}}},i.utils={extend:function(t,n,i){for(var r in n)t[r]!==e&&i||(t[r]=n[r]);return t},hasParent:function(t,e){for(;t;){if(t==e)return!0;t=t.parentNode}return!1},getCenter:function(t){for(var e=[],n=[],i=0,r=t.length;r>i;i++)e.push(t[i].pageX),n.push(t[i].pageY);return{pageX:(Math.min.apply(Math,e)+Math.max.apply(Math,e))/2,pageY:(Math.min.apply(Math,n)+Math.max.apply(Math,n))/2}},getVelocity:function(t,e,n){return{x:Math.abs(e/t)||0,y:Math.abs(n/t)||0}},getAngle:function(t,e){var n=e.pageY-t.pageY,i=e.pageX-t.pageX;return 180*Math.atan2(n,i)/Math.PI},getDirection:function(t,e){var n=Math.abs(t.pageX-e.pageX),r=Math.abs(t.pageY-e.pageY);return n>=r?t.pageX-e.pageX>0?i.DIRECTION_LEFT:i.DIRECTION_RIGHT:t.pageY-e.pageY>0?i.DIRECTION_UP:i.DIRECTION_DOWN},getDistance:function(t,e){var n=e.pageX-t.pageX,i=e.pageY-t.pageY;return Math.sqrt(n*n+i*i)},getScale:function(t,e){return t.length>=2&&e.length>=2?this.getDistance(e[0],e[1])/this.getDistance(t[0],t[1]):1},getRotation:function(t,e){return t.length>=2&&e.length>=2?this.getAngle(e[1],e[0])-this.getAngle(t[1],t[0]):0},isVertical:function(t){return t==i.DIRECTION_UP||t==i.DIRECTION_DOWN},stopDefaultBrowserBehavior:function(t,e){var n,i=["webkit","khtml","moz","Moz","ms","o",""];if(e&&t.style){for(var r=0;i.length>r;r++)for(var o in e)e.hasOwnProperty(o)&&(n=o,i[r]&&(n=i[r]+n.substring(0,1).toUpperCase()+n.substring(1)),t.style[n]=e[o]);"none"==e.userSelect&&(t.onselectstart=function(){return!1})}}},i.detection={gestures:[],current:null,previous:null,stopped:!1,startDetect:function(t,e){this.current||(this.stopped=!1,this.current={inst:t,startEvent:i.utils.extend({},e),lastEvent:!1,name:""},this.detect(e))},detect:function(t){if(this.current&&!this.stopped){t=this.extendEventData(t);for(var e=this.current.inst.options,n=0,r=this.gestures.length;r>n;n++){var o=this.gestures[n];if(!this.stopped&&e[o.name]!==!1&&o.handler.call(o,t,this.current.inst)===!1){this.stopDetect();break}}return this.current&&(this.current.lastEvent=t),t.eventType==i.EVENT_END&&!t.touches.length-1&&this.stopDetect(),t}},stopDetect:function(){this.previous=i.utils.extend({},this.current),this.current=null,this.stopped=!0},extendEventData:function(t){var e=this.current.startEvent;if(e&&(t.touches.length!=e.touches.length||t.touches===e.touches)){e.touches=[];for(var n=0,r=t.touches.length;r>n;n++)e.touches.push(i.utils.extend({},t.touches[n]))}var o=t.timeStamp-e.timeStamp,a=t.center.pageX-e.center.pageX,s=t.center.pageY-e.center.pageY,c=i.utils.getVelocity(o,a,s);return i.utils.extend(t,{deltaTime:o,deltaX:a,deltaY:s,velocityX:c.x,velocityY:c.y,distance:i.utils.getDistance(e.center,t.center),angle:i.utils.getAngle(e.center,t.center),direction:i.utils.getDirection(e.center,t.center),scale:i.utils.getScale(e.touches,t.touches),rotation:i.utils.getRotation(e.touches,t.touches),startEvent:e}),t},register:function(t){var n=t.defaults||{};return n[t.name]===e&&(n[t.name]=!0),i.utils.extend(i.defaults,n,!0),t.index=t.index||1e3,this.gestures.push(t),this.gestures.sort(function(t,e){return t.indexe.index?1:0}),this.gestures}},i.gestures=i.gestures||{},i.gestures.Hold={name:"hold",index:10,defaults:{hold_timeout:500,hold_threshold:1},timer:null,handler:function(t,e){switch(t.eventType){case i.EVENT_START:clearTimeout(this.timer),i.detection.current.name=this.name,this.timer=setTimeout(function(){"hold"==i.detection.current.name&&e.trigger("hold",t)},e.options.hold_timeout);break;case i.EVENT_MOVE:t.distance>e.options.hold_threshold&&clearTimeout(this.timer);break;case i.EVENT_END:clearTimeout(this.timer)}}},i.gestures.Tap={name:"tap",index:100,defaults:{tap_max_touchtime:250,tap_max_distance:10,tap_always:!0,doubletap_distance:20,doubletap_interval:300},handler:function(t,e){if(t.eventType==i.EVENT_END){var n=i.detection.previous,r=!1;if(t.deltaTime>e.options.tap_max_touchtime||t.distance>e.options.tap_max_distance)return;n&&"tap"==n.name&&t.timeStamp-n.lastEvent.timeStamp0&&t.touches.length>e.options.swipe_max_touches)return;(t.velocityX>e.options.swipe_velocity||t.velocityY>e.options.swipe_velocity)&&(e.trigger(this.name,t),e.trigger(this.name+t.direction,t))}}},i.gestures.Drag={name:"drag",index:50,defaults:{drag_min_distance:10,correct_for_drag_min_distance:!0,drag_max_touches:1,drag_block_horizontal:!1,drag_block_vertical:!1,drag_lock_to_axis:!1,drag_lock_min_distance:25},triggered:!1,handler:function(t,n){if(i.detection.current.name!=this.name&&this.triggered)return n.trigger(this.name+"end",t),this.triggered=!1,e;if(!(n.options.drag_max_touches>0&&t.touches.length>n.options.drag_max_touches))switch(t.eventType){case i.EVENT_START:this.triggered=!1;break;case i.EVENT_MOVE:if(t.distancet.deltaY?i.DIRECTION_UP:i.DIRECTION_DOWN:0>t.deltaX?i.DIRECTION_LEFT:i.DIRECTION_RIGHT),this.triggered||(n.trigger(this.name+"start",t),this.triggered=!0),n.trigger(this.name,t),n.trigger(this.name+t.direction,t),(n.options.drag_block_vertical&&i.utils.isVertical(t.direction)||n.options.drag_block_horizontal&&!i.utils.isVertical(t.direction))&&t.preventDefault();break;case i.EVENT_END:this.triggered&&n.trigger(this.name+"end",t),this.triggered=!1}}},i.gestures.Transform={name:"transform",index:45,defaults:{transform_min_scale:.01,transform_min_rotation:1,transform_always_block:!1},triggered:!1,handler:function(t,n){if(i.detection.current.name!=this.name&&this.triggered)return n.trigger(this.name+"end",t),this.triggered=!1,e;if(!(2>t.touches.length))switch(n.options.transform_always_block&&t.preventDefault(),t.eventType){case i.EVENT_START:this.triggered=!1;break;case i.EVENT_MOVE:var r=Math.abs(1-t.scale),o=Math.abs(t.rotation);if(n.options.transform_min_scale>r&&n.options.transform_min_rotation>o)return;i.detection.current.name=this.name,this.triggered||(n.trigger(this.name+"start",t),this.triggered=!0),n.trigger(this.name,t),o>n.options.transform_min_rotation&&n.trigger("rotate",t),r>n.options.transform_min_scale&&(n.trigger("pinch",t),n.trigger("pinch"+(1>t.scale?"in":"out"),t));break;case i.EVENT_END:this.triggered&&n.trigger(this.name+"end",t),this.triggered=!1}}},i.gestures.Touch={name:"touch",index:-1/0,defaults:{prevent_default:!1,prevent_mouseevents:!1},handler:function(t,n){return n.options.prevent_mouseevents&&t.pointerType==i.POINTER_MOUSE?(t.stopDetect(),e):(n.options.prevent_default&&t.preventDefault(),t.eventType==i.EVENT_START&&n.trigger(this.name,t),e)}},i.gestures.Release={name:"release",index:1/0,handler:function(t,e){t.eventType==i.EVENT_END&&e.trigger(this.name,t)}},"function"==typeof define&&"object"==typeof define.amd&&define.amd?define(function(){return i}):"object"==typeof module&&"object"==typeof module.exports?module.exports=i:t.Hammer=i})(this),function(t,e){"use strict";t!==e&&(Hammer.event.bindDom=function(n,i,r){t(n).on(i,function(t){var n=t.originalEvent||t;n.pageX===e&&(n.pageX=t.pageX,n.pageY=t.pageY),n.target||(n.target=t.target),n.which===e&&(n.which=n.button),n.preventDefault||(n.preventDefault=t.preventDefault),n.stopPropagation||(n.stopPropagation=t.stopPropagation),r.call(this,n)})},Hammer.Instance.prototype.on=function(e,n){return t(this.element).on(e,n)},Hammer.Instance.prototype.off=function(e,n){return t(this.element).off(e,n)},Hammer.Instance.prototype.trigger=function(e,n){var i=t(this.element);return i.has(n.target).length&&(i=t(n.target)),i.trigger({type:e,gesture:n})},t.fn.hammer=function(e){return this.each(function(){var n=t(this),i=n.data("hammer");i?i&&e&&Hammer.utils.extend(i.options,e):n.data("hammer",new Hammer(this,e||{}))})})}(window.jQuery||window.Zepto); \ No newline at end of file +(function(f,p){function l(){if(!a.READY){a.event.determineEventTypes();for(var b in a.gestures)a.gestures.hasOwnProperty(b)&&a.detection.register(a.gestures[b]);a.event.onTouch(a.DOCUMENT,a.EVENT_MOVE,a.detection.detect);a.event.onTouch(a.DOCUMENT,a.EVENT_END,a.detection.detect);a.READY=!0}}var a=function(b,c){return new a.Instance(b,c||{})};a.defaults={stop_browser_behavior:{userSelect:"none",touchAction:"none",touchCallout:"none",contentZooming:"none",userDrag:"none",tapHighlightColor:"rgba(0,0,0,0)"}};a.HAS_POINTEREVENTS=f.navigator.pointerEnabled||f.navigator.msPointerEnabled;a.HAS_TOUCHEVENTS="ontouchstart"in f;a.MOBILE_REGEX=/mobile|tablet|ip(ad|hone|od)|android|silk/i;a.NO_MOUSEEVENTS=a.HAS_TOUCHEVENTS&&f.navigator.userAgent.match(a.MOBILE_REGEX);a.EVENT_TYPES={};a.DIRECTION_DOWN="down";a.DIRECTION_LEFT="left";a.DIRECTION_UP="up";a.DIRECTION_RIGHT="right";a.POINTER_MOUSE="mouse";a.POINTER_TOUCH="touch";a.POINTER_PEN="pen";a.EVENT_START="start";a.EVENT_MOVE="move";a.EVENT_END="end";a.DOCUMENT=f.document;a.plugins={};a.READY=!1;a.Instance=function(b,c){var d=this;l();this.element=b;this.enabled=!0;this.options=a.utils.extend(a.utils.extend({},a.defaults),c||{});this.options.stop_browser_behavior&&a.utils.stopDefaultBrowserBehavior(this.element,this.options.stop_browser_behavior);a.event.onTouch(b,a.EVENT_START,function(b){d.enabled&&a.detection.startDetect(d,b)});return this};a.Instance.prototype={on:function(b,c){for(var a=b.split(" "),e=0;e=e?0b.index?1:0});return this.gestures}};a.gestures=a.gestures||{};a.gestures.Hold={name:"hold",index:10,defaults:{hold_timeout:500,hold_threshold:1},timer:null,handler:function(b,c){switch(b.eventType){case a.EVENT_START:clearTimeout(this.timer);a.detection.current.name=this.name;this.timer=setTimeout(function(){"hold"==a.detection.current.name&&c.trigger("hold",b)},c.options.hold_timeout);break;case a.EVENT_MOVE:b.distance>c.options.hold_threshold&&clearTimeout(this.timer);break;case a.EVENT_END:clearTimeout(this.timer)}}};a.gestures.Tap={name:"tap",index:100,defaults:{tap_max_touchtime:250,tap_max_distance:10,tap_always:!0,doubletap_distance:20,doubletap_interval:300},handler:function(b,c){if(b.eventType==a.EVENT_END){var d=a.detection.previous,e=!1;b.deltaTime>c.options.tap_max_touchtime||b.distance>c.options.tap_max_distance||(d&&("tap"==d.name&&b.timeStamp-d.lastEvent.timeStampc.options.swipe_max_touches||!(b.velocityX>c.options.swipe_velocity||b.velocityY>c.options.swipe_velocity)||(c.trigger(this.name,b),c.trigger(this.name+b.direction,b))}};a.gestures.Drag={name:"drag",index:50,defaults:{drag_min_distance:10,correct_for_drag_min_distance:!0,drag_max_touches:1,drag_block_horizontal:!1,drag_block_vertical:!1,drag_lock_to_axis:!1,drag_lock_min_distance:25},triggered:!1,handler:function(b,c){if(a.detection.current.name!=this.name&&this.triggered)c.trigger(this.name+"end",b),this.triggered=!1;else if(!(0c.options.drag_max_touches))switch(b.eventType){case a.EVENT_START:this.triggered=!1;break;case a.EVENT_MOVE:if(b.distanceb.deltaY?a.DIRECTION_UP:a.DIRECTION_DOWN:b.direction=0>b.deltaX?a.DIRECTION_LEFT:a.DIRECTION_RIGHT);this.triggered||(c.trigger(this.name+"start",b),this.triggered=!0);c.trigger(this.name,b);c.trigger(this.name+b.direction,b);(c.options.drag_block_vertical&&a.utils.isVertical(b.direction)||c.options.drag_block_horizontal&&!a.utils.isVertical(b.direction))&&b.preventDefault();break;case a.EVENT_END:this.triggered&&c.trigger(this.name+"end",b),this.triggered=!1}}};a.gestures.Transform={name:"transform",index:45,defaults:{transform_min_scale:0.01,transform_min_rotation:1,transform_always_block:!1},triggered:!1,handler:function(b,c){if(a.detection.current.name!=this.name&&this.triggered)c.trigger(this.name+"end",b),this.triggered=!1;else if(!(2>b.touches.length))switch(c.options.transform_always_block&&b.preventDefault(),b.eventType){case a.EVENT_START:this.triggered=!1;break;case a.EVENT_MOVE:var d=Math.abs(1-b.scale),e=Math.abs(b.rotation);if(dc.options.transform_min_rotation&&c.trigger("rotate",b);d>c.options.transform_min_scale&&(c.trigger("pinch",b),c.trigger("pinch"+(1>b.scale?"in":"out"),b));break;case a.EVENT_END:this.triggered&&c.trigger(this.name+"end",b),this.triggered=!1}}};a.gestures.Touch={name:"touch",index:-Infinity,defaults:{prevent_default:!1,prevent_mouseevents:!1},handler:function(b,c){c.options.prevent_mouseevents&&b.pointerType==a.POINTER_MOUSE?b.stopDetect():(c.options.prevent_default&&b.preventDefault(),b.eventType==a.EVENT_START&&c.trigger(this.name,b))}};a.gestures.Release={name:"release",index:Infinity,handler:function(b,c){b.eventType==a.EVENT_END&&c.trigger(this.name,b)}};"function"==typeof define&&"object"==typeof define.amd&&define.amd?define(function(){return a}):"object"===typeof module&&"object"===typeof module.exports?module.exports=a:f.Hammer=a})(this);(function(f){var p=function(l,a){if(a===f)return l;l.event.bindDom=function(n,g,k){a(n).on(g,function(a){var c=a.originalEvent||a;c.pageX===f&&(c.pageX=a.pageX,c.pageY=a.pageY);c.target||(c.target=a.target);c.which===f&&(c.which=c.button);c.preventDefault||(c.preventDefault=a.preventDefault);c.stopPropagation||(c.stopPropagation=a.stopPropagation);k.call(this,c)})};l.Instance.prototype.on=function(f,g){return a(this.element).on(f,g)};l.Instance.prototype.off=function(f,g){return a(this.element).off(f,g)};l.Instance.prototype.trigger=function(f,g){var k=a(this.element);k.has(g.target).length&&(k=a(g.target));return k.trigger({type:f,gesture:g})};a.fn.hammer=function(f){return this.each(function(){var g=a(this),k=g.data("hammer");k?k&&f&&l.utils.extend(k.options,f):g.data("hammer",new l(this,f||{}))})};return l};"function"===typeof define&&"object"===typeof define.amd&&define.amd?define(["hammer","jquery"],p):p(window.Hammer,window.jQuery||window.Zepto)})(); \ No newline at end of file diff --git a/plugins/jquery.hammer.js b/plugins/jquery.hammer.js index 197b132d9..17a749b0c 100644 --- a/plugins/jquery.hammer.js +++ b/plugins/jquery.hammer.js @@ -1,9 +1,10 @@ -(function($, undefined) { - 'use strict'; +(function(undefined) { + 'use strict'; + var init = function(Hammer, $) { // no jQuery or Zepto! if($ === undefined) { - return; + return Hammer; } /** @@ -104,4 +105,14 @@ }); }; -})(window.jQuery || window.Zepto); + return Hammer; + }; + + + if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) { + define(["hammer", "jquery"], init); + } else { + init(window.Hammer, window.jQuery || window.Zepto); + } + +}()); From afc7e15fdb99e151abbf736f81660b4f31b42f5c Mon Sep 17 00:00:00 2001 From: Jan Nicklas Date: Wed, 14 Aug 2013 20:59:05 +0200 Subject: [PATCH 2/2] Fixes issue #331 - "jquery.hammer.js can't used in requirejs" --- dist/hammer.js | 2 +- dist/jquery.hammer.js | 4 ++-- plugins/jquery.hammer.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/hammer.js b/dist/hammer.js index becb29a61..fc271a34f 100644 --- a/dist/hammer.js +++ b/dist/hammer.js @@ -1421,7 +1421,7 @@ Hammer.gestures.Release = { // some AMD build optimizers, like r.js, check for specific condition patterns like the following: if(typeof define == 'function' && typeof define.amd == 'object' && define.amd) { // define as an anonymous module - define(function() { + define('hammer', function() { return Hammer; }); } diff --git a/dist/jquery.hammer.js b/dist/jquery.hammer.js index f4b36b637..ac565bf60 100644 --- a/dist/jquery.hammer.js +++ b/dist/jquery.hammer.js @@ -1421,7 +1421,7 @@ Hammer.gestures.Release = { // some AMD build optimizers, like r.js, check for specific condition patterns like the following: if(typeof define == 'function' && typeof define.amd == 'object' && define.amd) { // define as an anonymous module - define(function() { + define('hammer', function() { return Hammer; }); } @@ -1547,7 +1547,7 @@ else { if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) { - define(["hammer", "jquery"], init); + define('hammer-jquery', ['hammer', 'jquery'], init); } else { init(window.Hammer, window.jQuery || window.Zepto); } diff --git a/plugins/jquery.hammer.js b/plugins/jquery.hammer.js index 17a749b0c..1f504457c 100644 --- a/plugins/jquery.hammer.js +++ b/plugins/jquery.hammer.js @@ -110,7 +110,7 @@ if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) { - define(["hammer", "jquery"], init); + define('hammer-jquery', ['hammer', 'jquery'], init); } else { init(window.Hammer, window.jQuery || window.Zepto); }