diff --git a/README.md b/README.md index 3e71ccd..145e991 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ The plugin is known to work with the configuration described below: * [jQuery](http://jquery.com/) (>=1.8) * [jQuery UI](http://jqueryui.com/) (>=1.8) * [Widget Factory](http://api.jqueryui.com/jQuery.widget/) - * [Hammer.js](http://hammerjs.github.io/) (>=2.08) + * [Hammer.js](http://hammerjs.github.io/) (=2.01) * [jquery.hammer.js](https://github.com/hammerjs/jquery.hammer.js) (>=2.0.0) * [Zoetrope](https://github.com/benplum/Zoetrope) (>=3.0) * [jquery-mousewheel](https://github.com/brandonaaron/jquery-mousewheel) (>=3.0) diff --git a/demo.html b/demo.html index 856f70f..ebc4eb0 100644 --- a/demo.html +++ b/demo.html @@ -5,7 +5,6 @@ - @@ -51,7 +50,6 @@

Centred in a div - Dynamic Width

dragable: false }); $img.imgViewer("option", "onClick", test); - $img.imgViewer("option","zoomable", false); if ($img.imgViewer("option","zoomable")) $toggleZ.text("Zoom Off"); else diff --git a/imgViewer.jquery.json b/imgViewer.jquery.json index 754c3e6..f49a097 100644 --- a/imgViewer.jquery.json +++ b/imgViewer.jquery.json @@ -22,7 +22,7 @@ "dependencies": { "jquery": ">=1.8", "jquery-ui": ">=1.8", - "hammer.js": ">=2.0.8", + "hammer.js": "=2.0.1", "jquery.hammer.js": ">=2.0.0", "zoetrope": ">=3.0", "jquery-mousewheel": ">=3.0" diff --git a/libs/hammer.min.js b/libs/hammer.min.js index edadee1..1d5a6c7 100644 --- a/libs/hammer.min.js +++ b/libs/hammer.min.js @@ -1,7 +1,9 @@ -/*! Hammer.JS - v2.0.8 - 2016-04-23 +/*! Hammer.JS - v2.0.1 - 2014-07-15 * http://hammerjs.github.io/ * - * Copyright (c) 2016 Jorik Tangelder; + * Copyright (c) 2014 Jorik Tangelder ; * Licensed under the MIT license */ -!function(a,b,c,d){"use strict";function e(a,b,c){return setTimeout(j(a,c),b)}function f(a,b,c){return Array.isArray(a)?(g(a,c[b],c),!0):!1}function g(a,b,c){var e;if(a)if(a.forEach)a.forEach(b,c);else if(a.length!==d)for(e=0;e\s*\(/gm,"{anonymous}()@"):"Unknown Stack Trace",f=a.console&&(a.console.warn||a.console.log);return f&&f.call(a.console,e,d),b.apply(this,arguments)}}function i(a,b,c){var d,e=b.prototype;d=a.prototype=Object.create(e),d.constructor=a,d._super=e,c&&la(d,c)}function j(a,b){return function(){return a.apply(b,arguments)}}function k(a,b){return typeof a==oa?a.apply(b?b[0]||d:d,b):a}function l(a,b){return a===d?b:a}function m(a,b,c){g(q(b),function(b){a.addEventListener(b,c,!1)})}function n(a,b,c){g(q(b),function(b){a.removeEventListener(b,c,!1)})}function o(a,b){for(;a;){if(a==b)return!0;a=a.parentNode}return!1}function p(a,b){return a.indexOf(b)>-1}function q(a){return a.trim().split(/\s+/g)}function r(a,b,c){if(a.indexOf&&!c)return a.indexOf(b);for(var d=0;dc[b]}):d.sort()),d}function u(a,b){for(var c,e,f=b[0].toUpperCase()+b.slice(1),g=0;g1&&!c.firstMultiple?c.firstMultiple=D(b):1===e&&(c.firstMultiple=!1);var f=c.firstInput,g=c.firstMultiple,h=g?g.center:f.center,i=b.center=E(d);b.timeStamp=ra(),b.deltaTime=b.timeStamp-f.timeStamp,b.angle=I(h,i),b.distance=H(h,i),B(c,b),b.offsetDirection=G(b.deltaX,b.deltaY);var j=F(b.deltaTime,b.deltaX,b.deltaY);b.overallVelocityX=j.x,b.overallVelocityY=j.y,b.overallVelocity=qa(j.x)>qa(j.y)?j.x:j.y,b.scale=g?K(g.pointers,d):1,b.rotation=g?J(g.pointers,d):0,b.maxPointers=c.prevInput?b.pointers.length>c.prevInput.maxPointers?b.pointers.length:c.prevInput.maxPointers:b.pointers.length,C(c,b);var k=a.element;o(b.srcEvent.target,k)&&(k=b.srcEvent.target),b.target=k}function B(a,b){var c=b.center,d=a.offsetDelta||{},e=a.prevDelta||{},f=a.prevInput||{};b.eventType!==Ea&&f.eventType!==Ga||(e=a.prevDelta={x:f.deltaX||0,y:f.deltaY||0},d=a.offsetDelta={x:c.x,y:c.y}),b.deltaX=e.x+(c.x-d.x),b.deltaY=e.y+(c.y-d.y)}function C(a,b){var c,e,f,g,h=a.lastInterval||b,i=b.timeStamp-h.timeStamp;if(b.eventType!=Ha&&(i>Da||h.velocity===d)){var j=b.deltaX-h.deltaX,k=b.deltaY-h.deltaY,l=F(i,j,k);e=l.x,f=l.y,c=qa(l.x)>qa(l.y)?l.x:l.y,g=G(j,k),a.lastInterval=b}else c=h.velocity,e=h.velocityX,f=h.velocityY,g=h.direction;b.velocity=c,b.velocityX=e,b.velocityY=f,b.direction=g}function D(a){for(var b=[],c=0;ce;)c+=a[e].clientX,d+=a[e].clientY,e++;return{x:pa(c/b),y:pa(d/b)}}function F(a,b,c){return{x:b/a||0,y:c/a||0}}function G(a,b){return a===b?Ia:qa(a)>=qa(b)?0>a?Ja:Ka:0>b?La:Ma}function H(a,b,c){c||(c=Qa);var d=b[c[0]]-a[c[0]],e=b[c[1]]-a[c[1]];return Math.sqrt(d*d+e*e)}function I(a,b,c){c||(c=Qa);var d=b[c[0]]-a[c[0]],e=b[c[1]]-a[c[1]];return 180*Math.atan2(e,d)/Math.PI}function J(a,b){return I(b[1],b[0],Ra)+I(a[1],a[0],Ra)}function K(a,b){return H(b[0],b[1],Ra)/H(a[0],a[1],Ra)}function L(){this.evEl=Ta,this.evWin=Ua,this.pressed=!1,x.apply(this,arguments)}function M(){this.evEl=Xa,this.evWin=Ya,x.apply(this,arguments),this.store=this.manager.session.pointerEvents=[]}function N(){this.evTarget=$a,this.evWin=_a,this.started=!1,x.apply(this,arguments)}function O(a,b){var c=s(a.touches),d=s(a.changedTouches);return b&(Ga|Ha)&&(c=t(c.concat(d),"identifier",!0)),[c,d]}function P(){this.evTarget=bb,this.targetIds={},x.apply(this,arguments)}function Q(a,b){var c=s(a.touches),d=this.targetIds;if(b&(Ea|Fa)&&1===c.length)return d[c[0].identifier]=!0,[c,c];var e,f,g=s(a.changedTouches),h=[],i=this.target;if(f=c.filter(function(a){return o(a.target,i)}),b===Ea)for(e=0;e-1&&d.splice(a,1)};setTimeout(e,cb)}}function U(a){for(var b=a.srcEvent.clientX,c=a.srcEvent.clientY,d=0;d=f&&db>=g)return!0}return!1}function V(a,b){this.manager=a,this.set(b)}function W(a){if(p(a,jb))return jb;var b=p(a,kb),c=p(a,lb);return b&&c?jb:b||c?b?kb:lb:p(a,ib)?ib:hb}function X(){if(!fb)return!1;var b={},c=a.CSS&&a.CSS.supports;return["auto","manipulation","pan-y","pan-x","pan-x pan-y","none"].forEach(function(d){b[d]=c?a.CSS.supports("touch-action",d):!0}),b}function Y(a){this.options=la({},this.defaults,a||{}),this.id=v(),this.manager=null,this.options.enable=l(this.options.enable,!0),this.state=nb,this.simultaneous={},this.requireFail=[]}function Z(a){return a&sb?"cancel":a&qb?"end":a&pb?"move":a&ob?"start":""}function $(a){return a==Ma?"down":a==La?"up":a==Ja?"left":a==Ka?"right":""}function _(a,b){var c=b.manager;return c?c.get(a):a}function aa(){Y.apply(this,arguments)}function ba(){aa.apply(this,arguments),this.pX=null,this.pY=null}function ca(){aa.apply(this,arguments)}function da(){Y.apply(this,arguments),this._timer=null,this._input=null}function ea(){aa.apply(this,arguments)}function fa(){aa.apply(this,arguments)}function ga(){Y.apply(this,arguments),this.pTime=!1,this.pCenter=!1,this._timer=null,this._input=null,this.count=0}function ha(a,b){return b=b||{},b.recognizers=l(b.recognizers,ha.defaults.preset),new ia(a,b)}function ia(a,b){this.options=la({},ha.defaults,b||{}),this.options.inputTarget=this.options.inputTarget||a,this.handlers={},this.session={},this.recognizers=[],this.oldCssProps={},this.element=a,this.input=y(this),this.touchAction=new V(this,this.options.touchAction),ja(this,!0),g(this.options.recognizers,function(a){var b=this.add(new a[0](a[1]));a[2]&&b.recognizeWith(a[2]),a[3]&&b.requireFailure(a[3])},this)}function ja(a,b){var c=a.element;if(c.style){var d;g(a.options.cssProps,function(e,f){d=u(c.style,f),b?(a.oldCssProps[d]=c.style[d],c.style[d]=e):c.style[d]=a.oldCssProps[d]||""}),b||(a.oldCssProps={})}}function ka(a,c){var d=b.createEvent("Event");d.initEvent(a,!0,!0),d.gesture=c,c.target.dispatchEvent(d)}var la,ma=["","webkit","Moz","MS","ms","o"],na=b.createElement("div"),oa="function",pa=Math.round,qa=Math.abs,ra=Date.now;la="function"!=typeof Object.assign?function(a){if(a===d||null===a)throw new TypeError("Cannot convert undefined or null to object");for(var b=Object(a),c=1;ch&&(b.push(a),h=b.length-1):e&(Ga|Ha)&&(c=!0),0>h||(b[h]=a,this.callback(this.manager,e,{pointers:b,changedPointers:[a],pointerType:f,srcEvent:a}),c&&b.splice(h,1))}});var Za={touchstart:Ea,touchmove:Fa,touchend:Ga,touchcancel:Ha},$a="touchstart",_a="touchstart touchmove touchend touchcancel";i(N,x,{handler:function(a){var b=Za[a.type];if(b===Ea&&(this.started=!0),this.started){var c=O.call(this,a,b);b&(Ga|Ha)&&c[0].length-c[1].length===0&&(this.started=!1),this.callback(this.manager,b,{pointers:c[0],changedPointers:c[1],pointerType:za,srcEvent:a})}}});var ab={touchstart:Ea,touchmove:Fa,touchend:Ga,touchcancel:Ha},bb="touchstart touchmove touchend touchcancel";i(P,x,{handler:function(a){var b=ab[a.type],c=Q.call(this,a,b);c&&this.callback(this.manager,b,{pointers:c[0],changedPointers:c[1],pointerType:za,srcEvent:a})}});var cb=2500,db=25;i(R,x,{handler:function(a,b,c){var d=c.pointerType==za,e=c.pointerType==Ba;if(!(e&&c.sourceCapabilities&&c.sourceCapabilities.firesTouchEvents)){if(d)S.call(this,b,c);else if(e&&U.call(this,c))return;this.callback(a,b,c)}},destroy:function(){this.touch.destroy(),this.mouse.destroy()}});var eb=u(na.style,"touchAction"),fb=eb!==d,gb="compute",hb="auto",ib="manipulation",jb="none",kb="pan-x",lb="pan-y",mb=X();V.prototype={set:function(a){a==gb&&(a=this.compute()),fb&&this.manager.element.style&&mb[a]&&(this.manager.element.style[eb]=a),this.actions=a.toLowerCase().trim()},update:function(){this.set(this.manager.options.touchAction)},compute:function(){var a=[];return g(this.manager.recognizers,function(b){k(b.options.enable,[b])&&(a=a.concat(b.getTouchAction()))}),W(a.join(" "))},preventDefaults:function(a){var b=a.srcEvent,c=a.offsetDirection;if(this.manager.session.prevented)return void b.preventDefault();var d=this.actions,e=p(d,jb)&&!mb[jb],f=p(d,lb)&&!mb[lb],g=p(d,kb)&&!mb[kb];if(e){var h=1===a.pointers.length,i=a.distance<2,j=a.deltaTime<250;if(h&&i&&j)return}return g&&f?void 0:e||f&&c&Na||g&&c&Oa?this.preventSrc(b):void 0},preventSrc:function(a){this.manager.session.prevented=!0,a.preventDefault()}};var nb=1,ob=2,pb=4,qb=8,rb=qb,sb=16,tb=32;Y.prototype={defaults:{},set:function(a){return la(this.options,a),this.manager&&this.manager.touchAction.update(),this},recognizeWith:function(a){if(f(a,"recognizeWith",this))return this;var b=this.simultaneous;return a=_(a,this),b[a.id]||(b[a.id]=a,a.recognizeWith(this)),this},dropRecognizeWith:function(a){return f(a,"dropRecognizeWith",this)?this:(a=_(a,this),delete this.simultaneous[a.id],this)},requireFailure:function(a){if(f(a,"requireFailure",this))return this;var b=this.requireFail;return a=_(a,this),-1===r(b,a)&&(b.push(a),a.requireFailure(this)),this},dropRequireFailure:function(a){if(f(a,"dropRequireFailure",this))return this;a=_(a,this);var b=r(this.requireFail,a);return b>-1&&this.requireFail.splice(b,1),this},hasRequireFailures:function(){return this.requireFail.length>0},canRecognizeWith:function(a){return!!this.simultaneous[a.id]},emit:function(a){function b(b){c.manager.emit(b,a)}var c=this,d=this.state;qb>d&&b(c.options.event+Z(d)),b(c.options.event),a.additionalEvent&&b(a.additionalEvent),d>=qb&&b(c.options.event+Z(d))},tryEmit:function(a){return this.canEmit()?this.emit(a):void(this.state=tb)},canEmit:function(){for(var a=0;af?Ja:Ka,c=f!=this.pX,d=Math.abs(a.deltaX)):(e=0===g?Ia:0>g?La:Ma,c=g!=this.pY,d=Math.abs(a.deltaY))),a.direction=e,c&&d>b.threshold&&e&b.direction},attrTest:function(a){return aa.prototype.attrTest.call(this,a)&&(this.state&ob||!(this.state&ob)&&this.directionTest(a))},emit:function(a){this.pX=a.deltaX,this.pY=a.deltaY;var b=$(a.direction);b&&(a.additionalEvent=this.options.event+b),this._super.emit.call(this,a)}}),i(ca,aa,{defaults:{event:"pinch",threshold:0,pointers:2},getTouchAction:function(){return[jb]},attrTest:function(a){return this._super.attrTest.call(this,a)&&(Math.abs(a.scale-1)>this.options.threshold||this.state&ob)},emit:function(a){if(1!==a.scale){var b=a.scale<1?"in":"out";a.additionalEvent=this.options.event+b}this._super.emit.call(this,a)}}),i(da,Y,{defaults:{event:"press",pointers:1,time:251,threshold:9},getTouchAction:function(){return[hb]},process:function(a){var b=this.options,c=a.pointers.length===b.pointers,d=a.distanceb.time;if(this._input=a,!d||!c||a.eventType&(Ga|Ha)&&!f)this.reset();else if(a.eventType&Ea)this.reset(),this._timer=e(function(){this.state=rb,this.tryEmit()},b.time,this);else if(a.eventType&Ga)return rb;return tb},reset:function(){clearTimeout(this._timer)},emit:function(a){this.state===rb&&(a&&a.eventType&Ga?this.manager.emit(this.options.event+"up",a):(this._input.timeStamp=ra(),this.manager.emit(this.options.event,this._input)))}}),i(ea,aa,{defaults:{event:"rotate",threshold:0,pointers:2},getTouchAction:function(){return[jb]},attrTest:function(a){return this._super.attrTest.call(this,a)&&(Math.abs(a.rotation)>this.options.threshold||this.state&ob)}}),i(fa,aa,{defaults:{event:"swipe",threshold:10,velocity:.3,direction:Na|Oa,pointers:1},getTouchAction:function(){return ba.prototype.getTouchAction.call(this)},attrTest:function(a){var b,c=this.options.direction;return c&(Na|Oa)?b=a.overallVelocity:c&Na?b=a.overallVelocityX:c&Oa&&(b=a.overallVelocityY),this._super.attrTest.call(this,a)&&c&a.offsetDirection&&a.distance>this.options.threshold&&a.maxPointers==this.options.pointers&&qa(b)>this.options.velocity&&a.eventType&Ga},emit:function(a){var b=$(a.offsetDirection);b&&this.manager.emit(this.options.event+b,a),this.manager.emit(this.options.event,a)}}),i(ga,Y,{defaults:{event:"tap",pointers:1,taps:1,interval:300,time:250,threshold:9,posThreshold:10},getTouchAction:function(){return[ib]},process:function(a){var b=this.options,c=a.pointers.length===b.pointers,d=a.distancee;e++)c.call(d,a[e],e,a);else for(e in a)a.hasOwnProperty(e)&&c.call(d,a[e],e,a)}function f(a,c,d){for(var e=Object.keys(c),f=0,g=e.length;g>f;f++)(!d||d&&a[e[f]]===b)&&(a[e[f]]=c[e[f]]);return a}function g(a,b){return f(a,b,!0)}function h(a,b,c){var d,e=b.prototype;d=a.prototype=Object.create(e),d.constructor=a,d._super=e,c&&f(d,c)}function i(a,b){return function(){return a.apply(b,arguments)}}function j(a,c){return typeof a==eb?a.apply(c?c[0]||b:b,c):a}function k(a,c){return a===b?c:a}function l(a,b,c){e(p(b),function(b){a.addEventListener(b,c,!1)})}function m(a,b,c){e(p(b),function(b){a.removeEventListener(b,c,!1)})}function n(a,b){for(;a;){if(a==b)return!0;a=a.parentNode}return!1}function o(a,b){return a.indexOf(b)>-1}function p(a){return a.trim().split(/\s+/g)}function q(a,b,c){if(a.indexOf&&!c)return a.indexOf(b);for(var d=0,e=a.length;e>d;d++)if(c&&a[d][c]==b||!c&&a[d]===b)return d;return-1}function r(a){return Array.prototype.slice.call(a,0)}function s(a,b){for(var c=[],d=[],e=0,f=a.length;f>e;e++){var g=b?a[e][b]:a[e];q(d,g)<0&&c.push(a[e]),d[e]=g}return c}function t(a,c){for(var d,e,f=c[0].toUpperCase()+c.slice(1),g=0,h=cb.length;h>g;g++)if(d=cb[g],e=d?d+f:c,e in a)return e;return b}function u(){return jb++}function v(b,c){var d=this;this.manager=b,this.callback=c,this.domHandler=function(a){j(d.manager.options.enable,[d.manager])&&d.handler(a)},this.evEl&&l(this.manager.element,this.evEl,this.domHandler),this.evWin&&l(a,this.evWin,this.domHandler)}function w(a){var b;return new(b=mb?J:nb?K:lb?M:I)(a,x)}function x(a,b,c){var d=c.pointers.length,e=c.changedPointers.length,f=b&tb&&d-e===0,g=b&(vb|wb)&&d-e===0;c.isFirst=f,c.isFinal=g,f&&(a.session={}),c.eventType=b,y(a,c),a.emit("hammer.input",c),a.recognize(c)}function y(a,b){var c=a.session,d=b.pointers,e=d.length;c.firstInput||(c.firstInput=A(b)),e>1&&!c.firstMultiple?c.firstMultiple=A(b):1===e&&(c.firstMultiple=!1);var f=c.firstInput,g=c.firstMultiple,h=g?g.center:f.center,i=B(d);b.timeStamp=ib(),b.deltaTime=b.timeStamp-f.timeStamp,b.deltaX=i.x-h.x,b.deltaY=i.y-h.y,b.center=i,b.angle=F(h,i),b.distance=E(h,i),b.offsetDirection=D(b.deltaX,b.deltaY),b.scale=g?H(g.pointers,d):1,b.rotation=g?G(g.pointers,d):0;var j=a.element;n(b.srcEvent.target,j)&&(j=b.srcEvent.target),b.target=j,z(c,b)}function z(a,c){var d=a.lastInterval;d||(d=a.lastInterval=A(c));var e,f,g,h,i=c.timeStamp-d.timeStamp;if(i>sb||d.velocity===b){var j=d.deltaX-c.deltaX,k=d.deltaY-c.deltaY,l=C(i,j,k);f=l.x,g=l.y,e=hb(l.x)>hb(l.y)?l.x:l.y,h=D(j,k)}else e=d.velocity,f=d.velocityX,g=d.velocityY,h=d.direction;c.velocity=e,c.velocityX=f,c.velocityY=g,c.direction=h}function A(a){for(var b=[],c=0;ce;e++)c+=a[e].clientX,d+=a[e].clientY;return{x:gb(c/b),y:gb(d/b)}}function C(a,b,c){return{x:b/a||0,y:c/a||0}}function D(a,b){return a===b?xb:hb(a)>=hb(b)?a>0?yb:zb:b>0?Ab:Bb}function E(a,b,c){c||(c=Fb);var d=b[c[0]]-a[c[0]],e=b[c[1]]-a[c[1]];return Math.sqrt(d*d+e*e)}function F(a,b,c){c||(c=Fb);var d=b[c[0]]-a[c[0]],e=b[c[1]]-a[c[1]];return 180*Math.atan2(e,d)/Math.PI}function G(a,b){return F(b[1],b[0],Gb)-F(a[1],a[0],Gb)}function H(a,b){return E(b[0],b[1],Gb)/E(a[0],a[1],Gb)}function I(){this.evEl=Ib,this.evWin=Jb,this.allow=!0,this.pressed=!1,v.apply(this,arguments)}function J(){this.evEl=Mb,this.evWin=Nb,v.apply(this,arguments),this.store=this.manager.session.pointerEvents=[]}function K(){this.evEl=Pb,this.targetIds={},v.apply(this,arguments)}function L(a,b){var c,d,e=b.targetIds,f=r(a.targetTouches),g=r(a.changedTouches),h=[];if("touchstart"==a.type)for(c=0,d=f.length;d>c;c++)e[f[c].identifier]=!0;for(c=0,d=g.length;d>c;c++)e[g[c].identifier]&&h.push(g[c]),("touchend"==a.type||"touchcancel"==a.type)&&delete e[g[c].identifier];return[s(f.concat(h),"identifier"),h]}function M(){v.apply(this,arguments);var a=i(this.handler,this);this.touch=new K(this.manager,a),this.mouse=new I(this.manager,a)}function N(a,b){this.manager=a,this.set(b)}function O(a){if(o(a,Vb))return Vb;var b=o(a,Wb),c=o(a,Xb);return b&&c?Wb+" "+Xb:b||c?b?Wb:Xb:o(a,Ub)?Ub:Tb}function P(a){this.id=u(),this.manager=null,this.options=g(a||{},this.defaults),this.options.enable=k(this.options.enable,!0),this.state=Yb,this.simultaneous={},this.requireFail=[]}function Q(a){return a&bc?"cancel":a&_b?"end":a&$b?"move":a&Zb?"start":""}function R(a){return a==Bb?"down":a==Ab?"up":a==yb?"left":a==zb?"right":""}function S(a,b){var c=b.manager;return c?c.get(a):a}function T(){P.apply(this,arguments)}function U(){T.apply(this,arguments),this.pX=null,this.pY=null}function V(){T.apply(this,arguments)}function W(){P.apply(this,arguments),this._timer=null,this._input=null}function X(){T.apply(this,arguments)}function Y(){T.apply(this,arguments)}function Z(){P.apply(this,arguments),this.pTime=!1,this.pCenter=!1,this._timer=null,this._input=null,this.count=0}function $(a,b){return b=b||{},b.recognizers=k(b.recognizers,$.defaults.preset),new _(a,b)}function _(a,b){b=b||{},this.options=g(b,$.defaults),this.handlers={},this.session={},this.recognizers=[],this.element=a,this.input=w(this),this.touchAction=new N(this,this.options.touchAction),ab(this,!0),e(b.recognizers,function(a){var b=this.add(new a[0](a[1]));a[2]&&b.recognizeWith(a[2]),a[3]&&b.requireFailure(a[2])},this)}function ab(a,b){var c=a.element,d=a.options.cssProps;e(d,function(a,d){c.style[t(c.style,d)]=b?a:""});var f=b&&function(){return!1};"none"==d.userSelect&&(c.onselectstart=f),"none"==d.userDrag&&(c.ondragstart=f)}function bb(a,b){var c=document.createEvent("Event");c.initEvent(a,!0,!0),c.gesture=b,b.target.dispatchEvent(c)}var cb=["","webkit","moz","MS","ms","o"],db=document.createElement("div"),eb="function",fb="undefined",gb=Math.round,hb=Math.abs,ib=Date.now,jb=1,kb=/mobile|tablet|ip(ad|hone|od)|android/i,lb="ontouchstart"in a,mb=t(a,"PointerEvent")!==b,nb=lb&&kb.test(navigator.userAgent),ob="touch",pb="pen",qb="mouse",rb="kinect",sb=25,tb=1,ub=2,vb=4,wb=8,xb=1,yb=2,zb=4,Ab=8,Bb=16,Cb=yb|zb,Db=Ab|Bb,Eb=Cb|Db,Fb=["x","y"],Gb=["clientX","clientY"];v.prototype={handler:function(){},destroy:function(){this.elEvents&&m(this.manager.element,this.elEvents,this.domHandler),this.winEvents&&m(a,this.winEvents,this.domHandler)}};var Hb={mousedown:tb,mousemove:ub,mouseup:vb,mouseout:wb},Ib="mousedown",Jb="mousemove mouseout mouseup";h(I,v,{handler:function(a){var b=Hb[a.type];if(b&tb&&0===a.button&&(this.pressed=!0),b&ub&&1!==a.which&&(b=vb),this.pressed&&this.allow){var c=a.relatedTarget||a.toElement||a.target;"mouseout"==a.type&&"HTML"!=c.nodeName&&(b=ub),b&(vb|wb)&&(this.pressed=!1),this.callback(this.manager,b,{pointers:[a],changedPointers:[a],pointerType:qb,srcEvent:a})}}});var Kb={pointerdown:tb,pointermove:ub,pointerup:vb,pointercancel:wb,pointerout:wb},Lb={2:ob,3:pb,4:qb,5:rb},Mb="pointerdown",Nb="pointermove pointerout pointerup pointercancel";a.MSPointerEvent&&(Mb="MSPointerDown",Nb="MSPointerMove MSPointerOut MSPointerUp MSPointerCancel"),h(J,v,{handler:function(a){var b=this.store,c=!1,d=a.type.toLowerCase().replace("ms",""),e=Kb[d],f=Lb[a.pointerType]||a.pointerType,g=a.relatedTarget||a.toElement||a.target;"pointerout"==d&&"HTML"!=g.nodeName&&(e=ub),e&tb&&(0===a.button||f==ob)?b.push(a):e&(vb|wb)&&(c=!0);var h=q(b,a.pointerId,"pointerId");0>h||(b[h]=a,this.callback(this.manager,e,{pointers:b,changedPointers:[a],pointerType:f,srcEvent:a}),c&&b.splice(h,1))}});var Ob={touchstart:tb,touchmove:ub,touchend:vb,touchcancel:wb},Pb="touchstart touchmove touchend touchcancel";h(K,v,{handler:function(a){var b=L(a,this);this.callback(this.manager,Ob[a.type],{pointers:b[0],changedPointers:b[1],pointerType:ob,srcEvent:a})}}),h(M,v,{handler:function(a,b,c){var d=c.pointerType==ob,e=c.pointerType==qb;if(d)this.mouse.allow=!1;else if(e&&!this.mouse.allow)return;b&(vb|wb)&&(this.mouse.allow=!0),this.callback(a,b,c)},destroy:function(){this.touch.destroy(),this.mouse.destroy()}});var Qb=t(db.style,"touchAction"),Rb=Qb!==b,Sb="compute",Tb="auto",Ub="manipulation",Vb="none",Wb="pan-x",Xb="pan-y";N.prototype={set:function(a){a==Sb&&(a=this.compute()),Rb&&(this.manager.element.style[Qb]=a),this.actions=a.toLowerCase().trim()},update:function(){this.set(this.manager.options.touchAction)},compute:function(){var a=[];return e(this.manager.recognizers,function(b){j(b.options.enable,[b])&&(a=a.concat(b.getTouchAction()))}),O(a.join(" "))},preventDefaults:function(a){if(!Rb){var b=a.srcEvent,c=a.offsetDirection;if(this.manager.session.prevented)return void b.preventDefault();var d=this.actions,e=o(d,Vb),f=o(d,Xb),g=o(d,Wb);return e||f&&g||f&&c&Cb||g&&c&Db?this.preventSrc(b):void 0}},preventSrc:function(a){this.manager.session.prevented=!0,a.preventDefault()}};var Yb=1,Zb=2,$b=4,_b=8,ac=_b,bc=16,cc=32;P.prototype={defaults:{},set:function(a){return f(this.options,a),this.manager&&this.manager.touchAction.update(),this},recognizeWith:function(a){if(d(a,"recognizeWith",this))return this;var b=this.simultaneous;return a=S(a,this),b[a.id]||(b[a.id]=a,a.recognizeWith(this)),this},dropRecognizeWith:function(a){return d(a,"dropRecognizeWith",this)?this:(a=S(a,this),delete this.simultaneous[a.id],this)},requireFailure:function(a){if(d(a,"requireFailure",this))return this;var b=this.requireFail;return a=S(a,this),-1===q(b,a)&&(b.push(a),a.requireFailure(this)),this},dropRequireFailure:function(a){if(d(a,"dropRequireFailure",this))return this;a=S(a,this);var b=q(this.requireFail,a);return b>-1&&this.requireFail.splice(b,1),this},hasRequireFailures:function(){return this.requireFail.length>0},canRecognizeWith:function(a){return!!this.simultaneous[a.id]},emit:function(a){this.manager.emit(this.options.event,a),this.manager.emit(this.options.event+Q(this.state),a)},tryEmit:function(a){return this.canEmit()?this.emit(a):void(this.state=cc)},canEmit:function(){for(var a=0;af?yb:zb,c=f!=this.pX,d=Math.abs(a.deltaX)):(e=0===g?xb:0>g?Ab:Bb,c=g!=this.pY,d=Math.abs(a.deltaY))),a.direction=e,c&&d>b.threshold&&e&b.direction},attrTest:function(a){return T.prototype.attrTest.call(this,a)&&(this.state&Zb||!(this.state&Zb)&&this.directionTest(a))},emit:function(a){this.pX=a.deltaX,this.pY=a.deltaY,this._super.emit.call(this,a);var b=R(a.direction);b&&this.manager.emit(this.options.event+b,a)}}),h(V,T,{defaults:{event:"pinch",threshold:0,pointers:2},getTouchAction:function(){return[Vb]},attrTest:function(a){return this._super.attrTest.call(this,a)&&(Math.abs(a.scale-1)>this.options.threshold||this.state&Zb)},emit:function(a){if(this._super.emit.call(this,a),1!==a.scale){var b=a.scale<1?"in":"out";this.manager.emit(this.options.event+b,a)}}}),h(W,P,{defaults:{event:"press",pointers:1,time:500,threshold:5},getTouchAction:function(){return[Tb]},process:function(a){var b=this.options,d=a.pointers.length===b.pointers,e=a.distanceb.time;if(this._input=a,!e||!d||a.eventType&(vb|wb)&&!f)this.reset();else if(a.eventType&tb)this.reset(),this._timer=c(function(){this.state=ac,this.tryEmit()},b.time,this);else if(a.eventType&vb)return ac;return cc},reset:function(){clearTimeout(this._timer)},emit:function(a){this.state===ac&&(a&&a.eventType&vb?this.manager.emit(this.options.event+"up",a):(this._input.timeStamp=ib(),this.manager.emit(this.options.event,this._input)))}}),h(X,T,{defaults:{event:"rotate",threshold:0,pointers:2},getTouchAction:function(){return[Vb]},attrTest:function(a){return this._super.attrTest.call(this,a)&&(Math.abs(a.rotation)>this.options.threshold||this.state&Zb)}}),h(Y,T,{defaults:{event:"swipe",threshold:10,velocity:.65,direction:Cb|Db,pointers:1},getTouchAction:function(){return U.prototype.getTouchAction.call(this)},attrTest:function(a){var b,c=this.options.direction;return c&(Cb|Db)?b=a.velocity:c&Cb?b=a.velocityX:c&Db&&(b=a.velocityY),this._super.attrTest.call(this,a)&&c&a.direction&&hb(b)>this.options.velocity&&a.eventType&vb},emit:function(a){this.manager.emit(this.options.event,a);var b=R(a.direction);b&&this.manager.emit(this.options.event+b,a)}}),h(Z,P,{defaults:{event:"tap",pointers:1,taps:1,interval:300,time:250,threshold:2,posThreshold:10},getTouchAction:function(){return[Ub]},process:function(a){var b=this.options,d=a.pointers.length===b.pointers,e=a.distancee;e++)b=this.recognizers[e],this.session.stopped===ec||d&&b!=d&&!b.canRecognizeWith(d)?b.reset():b.recognize(a),!d&&b.state&(Zb|$b|_b)&&(d=c.curRecognizer=b)}},get:function(a){if(a instanceof P)return a;for(var b=this.recognizers,c=0;cd;d++)c[d](b)}},destroy:function(){this.element&&ab(this,!1),this.handlers={},this.session={},this.input.destroy(),this.element=null}},f($,{INPUT_START:tb,INPUT_MOVE:ub,INPUT_END:vb,INPUT_CANCEL:wb,STATE_POSSIBLE:Yb,STATE_BEGAN:Zb,STATE_CHANGED:$b,STATE_ENDED:_b,STATE_RECOGNIZED:ac,STATE_CANCELLED:bc,STATE_FAILED:cc,DIRECTION_NONE:xb,DIRECTION_LEFT:yb,DIRECTION_RIGHT:zb,DIRECTION_UP:Ab,DIRECTION_DOWN:Bb,DIRECTION_HORIZONTAL:Cb,DIRECTION_VERTICAL:Db,DIRECTION_ALL:Eb,Manager:_,Input:v,TouchAction:N,Recognizer:P,AttrRecognizer:T,Tap:Z,Pan:U,Swipe:Y,Pinch:V,Rotate:X,Press:W,on:l,off:m,each:e,merge:g,extend:f,inherit:h,bindFn:i,prefixed:t}),typeof define==eb&&define.amd?define(function(){return $}):typeof module!=fb&&module.exports?module.exports=$:a.Hammer=$}(window); +//# sourceMappingURL=hammer.min.map \ No newline at end of file diff --git a/libs/jquery.hammer.js b/libs/jquery.hammer.js index e444b5c..d2dd0fc 100644 --- a/libs/jquery.hammer.js +++ b/libs/jquery.hammer.js @@ -1,16 +1,8 @@ -(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($, Hammer, dataAttr) { function hammerify(el, options) { var $el = $(el); - if(!$el.data("hammer")) { - $el.data("hammer", new Hammer($el[0], options)); + if(!$el.data(dataAttr)) { + $el.data(dataAttr, new Hammer($el[0], options)); } } @@ -24,10 +16,10 @@ Hammer.Manager.prototype.emit = (function(originalEmit) { return function(type, data) { originalEmit.call(this, type, data); - $(this.element).trigger({ + jQuery(this.element).triggerHandler({ type: type, gesture: data }); }; })(Hammer.Manager.prototype.emit); -})); +})(jQuery, Hammer, "hammer"); diff --git a/src/imgViewer.js b/src/imgViewer.js index 856a852..6dd8851 100644 --- a/src/imgViewer.js +++ b/src/imgViewer.js @@ -41,7 +41,7 @@ // the pixel coordinate of the original image at the center of the viewport self.vCenter = {}; // a flag used to decide if a mouse click is part of a drag or a proper click - self.dragging = false; + self.drag = false; self.pinch = false; // a flag used to check the target image has loaded self.ready = false; @@ -217,13 +217,37 @@ self.update(); } } + $zimg.on("pan", function(ev) { + ev.preventDefault(); + console.log(ev.type); + if (!self.drag) { + self.drag = true; + self.dragXorg = self.vCenter.x; + self.dragYorg = self.vCenter.y; + startRenderLoop(); + } else { + self.vCenter.x = self.dragXorg - ev.gesture.deltaX/self.options.zoom; + self.vCenter.y = self.dragYorg - ev.gesture.deltaY/self.options.zoom; + } + }); + + $zimg.on( "panend", function(ev) { + ev.preventDefault(); + if (self.drag) { + self.drag = false; + stopRenderLoop(); + self.update(); + } + }); - $zimg.on( "panstart" , function(ev) { +/* $zimg.on( "panstart" , function(ev) { ev.preventDefault(); if (!self.pinch) { + self.drag = true; self.dragXorg = self.vCenter.x; self.dragYorg = self.vCenter.y; startRenderLoop(); + console.log("panstart"); } }); @@ -232,16 +256,19 @@ if (!self.pinch) { self.vCenter.x = self.dragXorg - ev.gesture.deltaX/self.options.zoom; self.vCenter.y = self.dragYorg - ev.gesture.deltaY/self.options.zoom; + console.log("panmove"); } }); $zimg.on( "panend", function(ev) { ev.preventDefault(); if (!self.pinch) { + self.drag = false; stopRenderLoop(); self.update(); } }); +*/ }, /* * Unbind events @@ -259,8 +286,7 @@ _unbind_drag_events: function() { var self = this; var $zimg = $(self.zimg); - $zimg.off("panstart"); - $zimg.off("panmove"); + $zimg.off("pan"); $zimg.off("panend"); },