Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed IE related errors in gesture-simulate code and tests

  • Loading branch information...
commit 4567e1f8b1e638317af2d91acac45300208f3ad7 1 parent e9339af
@sdesai sdesai authored
View
17 build/gesture-simulate/gesture-simulate-debug.js
@@ -1,6 +1,5 @@
YUI.add('gesture-simulate', function(Y) {
-(function() {
/**
* Simulate high-level user gestures by generating a set of native DOM events.
*
@@ -8,7 +7,9 @@ YUI.add('gesture-simulate', function(Y) {
* @requires event-simulate, async-queue, node-screen
*/
-var gestureNames = {
+var NAME = "gesture-simulate",
+
+ gestureNames = {
tap: 1,
doubletap: 1,
press: 1,
@@ -1055,19 +1056,17 @@ Y.GestureSimulation.GESTURES = gestureNames;
* @static
*/
Y.Event.simulateGesture = function(node, name, options, cb) {
-
- if(node instanceof HTMLElement) {
- node = Y.Node.one(node);
- }
+
+ node = Y.one(node);
var sim = new Y.GestureSimulation(node);
name = name.toLowerCase();
-
+
if(!cb && Y.Lang.isFunction(options)) {
cb = options;
options = {};
}
-
+
options = options || {};
if (gestureNames[name]) {
@@ -1114,7 +1113,5 @@ Y.Event.simulateGesture = function(node, name, options, cb) {
}
};
-})();
-
}, '@VERSION@' ,{requires:['event-simulate', 'async-queue', 'node-screen']});
View
4 build/gesture-simulate/gesture-simulate-min.js
@@ -1,2 +1,2 @@
-YUI.add("gesture-simulate",function(a){(function(){var h={tap:1,doubletap:1,press:1,move:1,flick:1,pinch:1,rotate:1},e={touchstart:1,touchmove:1,touchend:1,touchcancel:1},o=a.config.doc,m,g=20,k,j,c={HOLD_TAP:10,DELAY_TAP:10,HOLD_PRESS:3000,MIN_HOLD_PRESS:1000,MAX_HOLD_PRESS:60000,DISTANCE_MOVE:200,DURATION_MOVE:1000,MAX_DURATION_MOVE:5000,MIN_VELOCITY_FLICK:1.3,DISTANCE_FLICK:200,DURATION_FLICK:1000,MAX_DURATION_FLICK:5000,DURATION_PINCH:1000},i="touchstart",q="touchmove",r="touchend",u="gesturestart",f="gesturechange",b="gestureend",v="mouseup",w="mousemove",s="mousedown",n="click",d="dblclick",p="x",t="y";function l(x){if(!x){a.error(NAME+": invalid target node");}this.node=x;this.target=a.Node.getDOMNode(x);k=this.node.getX()+this.target.getBoundingClientRect().width/2;j=this.node.getY()+this.target.getBoundingClientRect().height/2;}l.prototype={_toRadian:function(x){return x*(Math.PI/180);},_calculateDefaultPoint:function(x){if(!a.Lang.isArray(x)||x.length===0){x=[k,j];}else{if(x.length==1){x[1]=this.target.getBoundingClientRect().height/2;}x[0]=this.node.getX()+x[0];x[1]=this.node.getY()+x[1];}return x;},rotate:function(B,x,E,F,C,y,G){var D,A=E,z=F;if(!a.Lang.isNumber(A)||!a.Lang.isNumber(z)||A<0||z<0){D=(this.target.offsetWidth<this.target.offsetHeight)?this.target.offsetWidth/2:this.target.offsetHeight/2;A=D;z=D;}if(!a.Lang.isNumber(G)){a.error(NAME+"Invalid rotation detected.");}this.pinch(B,x,A,z,C,y,G);},pinch:function(J,W,M,C,y,D,L){var I,T=g,H,K=0,P=M,N=C,V,G,E,U,S,X,B,R,x,F,A={start:[],end:[]},z={start:[],end:[]},Q;W=this._calculateDefaultPoint(W);if(!a.Lang.isNumber(P)||!a.Lang.isNumber(N)||P<0||N<0){a.error(NAME+"Invalid startRadius and endRadius detected.");}if(!a.Lang.isNumber(y)||y<=0){y=c.DURATION_PINCH;}if(!a.Lang.isNumber(D)){D=0;}else{D=D%360;if(D<0){D+=360;}}if(!a.Lang.isNumber(L)){L=0;}a.AsyncQueue.defaults.timeout=T;I=new a.AsyncQueue();G=W[0];E=W[1];B=D;R=D+L;A.start=[G+P*Math.sin(this._toRadian(B)),E-P*Math.cos(this._toRadian(B))];A.end=[G+N*Math.sin(this._toRadian(R-B)),E-N*Math.cos(this._toRadian(R-B))];z.start=[G-P*Math.sin(this._toRadian(B)),E+P*Math.cos(this._toRadian(B))];z.end=[G-N*Math.sin(this._toRadian(R-B)),E+N*Math.cos(this._toRadian(R-B))];U=1;S=C/M;I.add({fn:function(){var Z,Y,ab,aa;Z={pageX:A.start[0],pageY:A.start[1],clientX:A.start[0],clientY:A.start[1]};Y={pageX:z.start[0],pageY:z.start[1],clientX:z.start[0],clientY:z.start[1]};aa=this._createTouchList([a.merge({identifier:K++},Z),a.merge({identifier:K++},Y)]);ab={pageX:(A.start[0]+z.start[0])/2,pageY:(A.start[0]+z.start[1])/2,clientX:(A.start[0]+z.start[0])/2,clientY:(A.start[0]+z.start[1])/2};this._simulateEvent(this.target,i,a.merge({touches:aa,targetTouches:aa,changedTouches:aa,scale:U,rotation:B},ab));if(a.UA.ios>=2){this._simulateEvent(this.target,u,a.merge({scale:U,rotation:B},ab));}},timeout:0,context:this});Q=Math.floor(y/T);V=(N-P)/Q;X=(S-U)/Q;x=(R-B)/Q;F=this._toRadian(R-B)/Q;for(var O=0;O<Q;O++){I.add({fn:function(ab){var af=P+(V)*ab,ad=G+af*Math.sin(B+F*ab),Z=E-af*Math.cos(B+F*ab),aa=G-af*Math.sin(B+F*ab),Y=E+af*Math.cos(B+F*ab),aj=(ad+aa)/2,ai=(Z+Y)/2,ah,ag,ae,ac;ah={pageX:ad,pageY:Z,clientX:ad,clientY:Z};ag={pageX:aa,pageY:Y,clientX:aa,clientY:Y};ac=this._createTouchList([a.merge({identifier:K++},ah),a.merge({identifier:K++},ag)]);ae={pageX:aj,pageY:ai,clientX:aj,clientY:ai};this._simulateEvent(this.target,q,a.merge({touches:ac,targetTouches:ac,changedTouches:ac,scale:U+X*ab,rotation:B+x*ab},ae));if(a.UA.ios>=2){this._simulateEvent(this.target,f,a.merge({scale:U+X*ab,rotation:B+x*ab},ae));}},args:[O],context:this});}I.add({fn:function(){var ab=this._getEmptyTouchList(),Z,Y,ac,aa;Z={pageX:A.end[0],pageY:A.end[1],clientX:A.end[0],clientY:A.end[1]};Y={pageX:z.end[0],pageY:z.end[1],clientX:z.end[0],clientY:z.end[1]};aa=this._createTouchList([a.merge({identifier:K++},Z),a.merge({identifier:K++},Y)]);ac={pageX:(A.end[0]+z.end[0])/2,pageY:(A.end[0]+z.end[1])/2,clientX:(A.end[0]+z.end[0])/2,clientY:(A.end[0]+z.end[1])/2};if(a.UA.ios>=2){this._simulateEvent(this.target,b,a.merge({scale:S,rotation:R},ac));}this._simulateEvent(this.target,r,a.merge({touches:ab,targetTouches:ab,changedTouches:aa,scale:S,rotation:R},ac));},context:this});if(J&&a.Lang.isFunction(J)){I.add({fn:J,context:this.node});}I.run();},tap:function(z,E,x,y,B){var G=new a.AsyncQueue(),F=this._getEmptyTouchList(),C,D,A;E=this._calculateDefaultPoint(E);if(!a.Lang.isNumber(x)||x<1){x=1;}if(!a.Lang.isNumber(y)){y=c.HOLD_TAP;}if(!a.Lang.isNumber(B)){B=c.DELAY_TAP;}D={pageX:E[0],pageY:E[1],clientX:E[0],clientY:E[1]};C=this._createTouchList([a.merge({identifier:0},D)]);for(A=0;A<x;A++){G.add({fn:function(){this._simulateEvent(this.target,i,a.merge({touches:C,targetTouches:C,changedTouches:C},D));},context:this,timeout:(A===0)?0:B});G.add({fn:function(){this._simulateEvent(this.target,r,a.merge({touches:F,targetTouches:F,changedTouches:C},D));},context:this,timeout:y});}if(x>1&&!((a.config.win&&("ontouchstart" in a.config.win))&&!(a.UA.chrome&&a.UA.chrome<6))){G.add({fn:function(){this._simulateEvent(this.target,d,D);},context:this});}if(z&&a.Lang.isFunction(z)){G.add({fn:z,context:this.node});}G.run();},flick:function(y,x,z,C,B){var A;x=this._calculateDefaultPoint(x);if(!a.Lang.isString(z)){z=p;}else{z=z.toLowerCase();if(z!==p&&z!==t){a.error(NAME+"(flick): Only x or y axis allowed");}}if(!a.Lang.isNumber(C)){C=c.DISTANCE_FLICK;}if(!a.Lang.isNumber(B)){B=c.DURATION_FLICK;}else{if(B>c.MAX_DURATION_FLICK){B=c.MAX_DURATION_FLICK;}}if(Math.abs(C)/B<c.MIN_VELOCITY_FLICK){B=Math.abs(C)/c.MIN_VELOCITY_FLICK;}A={start:a.clone(x),end:[(z===p)?x[0]+C:x[0],(z===t)?x[1]+C:x[1]]};this._move(y,A,B);},move:function(x,z,y){var A;if(!a.Lang.isObject(z)){z={point:this._calculateDefaultPoint([]),xdist:c.DISTANCE_MOVE,ydist:0};}else{if(!a.Lang.isArray(z.point)){z.point=this._calculateDefaultPoint([]);}else{z.point=this._calculateDefaultPoint(z.point);}if(!a.Lang.isNumber(z.xdist)){z.xdist=c.DISTANCE_MOVE;}if(!a.Lang.isNumber(z.ydist)){z.ydist=0;}}if(!a.Lang.isNumber(y)){y=c.DURATION_MOVE;
-}else{if(y>c.MAX_DURATION_MOVE){y=c.MAX_DURATION_MOVE;}}A={start:a.clone(z.point),end:[z.point[0]+z.xdist,z.point[1]+z.ydist]};this._move(x,A,y);},_move:function(z,F,A){var G,y=g,C,E,D,x=0;if(!a.Lang.isNumber(A)){A=c.DURATION_MOVE;}else{if(A>c.MAX_DURATION_MOVE){A=c.MAX_DURATION_MOVE;}}if(!a.Lang.isObject(F)){F={start:[k,j],end:[k+c.DISTANCE_MOVE,j]};}else{if(!a.Lang.isArray(F.start)){F.start=[k,j];}if(!a.Lang.isArray(F.end)){F.end=[k+c.DISTANCE_MOVE,j];}}a.AsyncQueue.defaults.timeout=y;G=new a.AsyncQueue();G.add({fn:function(){var I={pageX:F.start[0],pageY:F.start[1],clientX:F.start[0],clientY:F.start[1]},H=this._createTouchList([a.merge({identifier:x++},I)]);this._simulateEvent(this.target,i,a.merge({touches:H,targetTouches:H,changedTouches:H},I));},timeout:0,context:this});C=Math.floor(A/y);E=(F.end[0]-F.start[0])/C;D=(F.end[1]-F.start[1])/C;for(var B=0;B<C;B++){G.add({fn:function(J){var I=F.start[0]+(E*J),H=F.start[1]+(D*J),L={pageX:I,pageY:H,clientX:I,clientY:H},K=this._createTouchList([a.merge({identifier:x++},L)]);this._simulateEvent(this.target,q,a.merge({touches:K,targetTouches:K,changedTouches:K},L));},args:[B],context:this});}G.add({fn:function(){var I={pageX:F.end[0],pageY:F.end[1],clientX:F.end[0],clientY:F.end[1]},H=this._createTouchList([a.merge({identifier:x},I)]);this._simulateEvent(this.target,q,a.merge({touches:H,targetTouches:H,changedTouches:H},I));},timeout:0,context:this});G.add({fn:function(){var J={pageX:F.end[0],pageY:F.end[1],clientX:F.end[0],clientY:F.end[1]},I=this._getEmptyTouchList(),H=this._createTouchList([a.merge({identifier:x},J)]);this._simulateEvent(this.target,r,a.merge({touches:I,targetTouches:I,changedTouches:H},J));},context:this});if(z&&a.Lang.isFunction(z)){G.add({fn:z,context:this.node});}G.run();},_getEmptyTouchList:function(){if(!m){m=this._createTouchList([]);}return m;},_createTouchList:function(z){var A=[],y,x=this;if(!!z&&a.Lang.isArray(z)){if(a.UA.android&&a.UA.android>=4||a.UA.ios&&a.UA.ios>=2){a.each(z,function(B){if(!B.identifier){B.identifier=0;}if(!B.pageX){B.pageX=0;}if(!B.pageY){B.pageY=0;}if(!B.screenX){B.screenX=0;}if(!B.screenY){B.screenY=0;}A.push(o.createTouch(a.config.win,x.target,B.identifier,B.pageX,B.pageY,B.screenX,B.screenY));});y=o.createTouchList.apply(o,A);}else{if(a.UA.ios&&a.UA.ios<2){a.error(NAME+": No touch event simulation framework present.");}else{y=[];a.each(z,function(B){if(!B.identifier){B.identifier=0;}if(!B.clientX){B.clientX=0;}if(!B.clientY){B.clientY=0;}if(!B.pageX){B.pageX=0;}if(!B.pageY){B.pageY=0;}if(!B.screenX){B.screenX=0;}if(!B.screenY){B.screenY=0;}y.push({target:x.target,identifier:B.identifier,clientX:B.clientX,clientY:B.clientY,pageX:B.pageX,pageY:B.pageY,screenX:B.screenX,screenY:B.screenY});});y.item=function(B){return y[B];};}}}else{a.error(NAME+": Invalid touchPoints passed");}return y;},_simulateEvent:function(A,y,x){var z;if(e[y]){if((a.config.win&&("ontouchstart" in a.config.win))&&!(a.UA.chrome&&a.UA.chrome<6)){a.Event.simulate(A,y,x);}else{if(this._isSingleTouch(x.touches,x.targetTouches,x.changedTouches)){y={touchstart:s,touchmove:w,touchend:v}[y];x.button=0;x.relatedTarget=null;z=(y===v)?x.changedTouches:x.touches;x=a.mix(x,{screenX:z.item(0).screenX,screenY:z.item(0).screenY,clientX:z.item(0).clientX,clientY:z.item(0).clientY},true);a.Event.simulate(A,y,x);if(y==v){a.Event.simulate(A,n,x);}}else{a.error("_simulateEvent(): Event '"+y+"' has multi touch objects that can't be simulated in your platform.");}}}else{a.Event.simulate(A,y,x);}},_isSingleTouch:function(z,y,x){return(z&&(z.length<=1))&&(y&&(y.length<=1))&&(x&&(x.length<=1));}};a.GestureSimulation=l;a.GestureSimulation.defaults=c;a.GestureSimulation.GESTURES=h;a.Event.simulateGesture=function(B,A,z,x){if(B instanceof HTMLElement){B=a.Node.one(B);}var y=new a.GestureSimulation(B);A=A.toLowerCase();if(!x&&a.Lang.isFunction(z)){x=z;z={};}z=z||{};if(h[A]){switch(A){case"tap":y.tap(x,z.point,z.times,z.hold,z.delay);break;case"doubletap":y.tap(x,z.point,2);break;case"press":if(!a.Lang.isNumber(z.hold)){z.hold=c.HOLD_PRESS;}else{if(z.hold<c.MIN_HOLD_PRESS){z.hold=c.MIN_HOLD_PRESS;}else{if(z.hold>c.MAX_HOLD_PRESS){z.hold=c.MAX_HOLD_PRESS;}}}y.tap(x,z.point,1,z.hold);break;case"move":y.move(x,z.path,z.duration);break;case"flick":y.flick(x,z.point,z.axis,z.distance,z.duration);break;case"pinch":y.pinch(x,z.center,z.r1,z.r2,z.duration,z.start,z.rotation);break;case"rotate":y.rotate(x,z.center,z.r1,z.r2,z.duration,z.start,z.rotation);break;}}else{a.error(NAME+": Not a supported gesture simulation: "+A);}};})();},"@VERSION@",{requires:["event-simulate","async-queue","node-screen"]});
+YUI.add("gesture-simulate",function(d){var j="gesture-simulate",h={tap:1,doubletap:1,press:1,move:1,flick:1,pinch:1,rotate:1},e={touchstart:1,touchmove:1,touchend:1,touchcancel:1},p=d.config.doc,n,g=20,l,k,b={HOLD_TAP:10,DELAY_TAP:10,HOLD_PRESS:3000,MIN_HOLD_PRESS:1000,MAX_HOLD_PRESS:60000,DISTANCE_MOVE:200,DURATION_MOVE:1000,MAX_DURATION_MOVE:5000,MIN_VELOCITY_FLICK:1.3,DISTANCE_FLICK:200,DURATION_FLICK:1000,MAX_DURATION_FLICK:5000,DURATION_PINCH:1000},i="touchstart",r="touchmove",s="touchend",v="gesturestart",f="gesturechange",a="gestureend",w="mouseup",x="mousemove",t="mousedown",o="click",c="dblclick",q="x",u="y";function m(y){if(!y){d.error(j+": invalid target node");}this.node=y;this.target=d.Node.getDOMNode(y);l=this.node.getX()+this.target.getBoundingClientRect().width/2;k=this.node.getY()+this.target.getBoundingClientRect().height/2;}m.prototype={_toRadian:function(y){return y*(Math.PI/180);},_calculateDefaultPoint:function(y){if(!d.Lang.isArray(y)||y.length===0){y=[l,k];}else{if(y.length==1){y[1]=this.target.getBoundingClientRect().height/2;}y[0]=this.node.getX()+y[0];y[1]=this.node.getY()+y[1];}return y;},rotate:function(C,y,F,G,D,z,H){var E,B=F,A=G;if(!d.Lang.isNumber(B)||!d.Lang.isNumber(A)||B<0||A<0){E=(this.target.offsetWidth<this.target.offsetHeight)?this.target.offsetWidth/2:this.target.offsetHeight/2;B=E;A=E;}if(!d.Lang.isNumber(H)){d.error(j+"Invalid rotation detected.");}this.pinch(C,y,B,A,D,z,H);},pinch:function(K,X,N,D,z,E,M){var J,U=g,I,L=0,Q=N,O=D,W,H,F,V,T,Y,C,S,y,G,B={start:[],end:[]},A={start:[],end:[]},R;X=this._calculateDefaultPoint(X);if(!d.Lang.isNumber(Q)||!d.Lang.isNumber(O)||Q<0||O<0){d.error(j+"Invalid startRadius and endRadius detected.");}if(!d.Lang.isNumber(z)||z<=0){z=b.DURATION_PINCH;}if(!d.Lang.isNumber(E)){E=0;}else{E=E%360;if(E<0){E+=360;}}if(!d.Lang.isNumber(M)){M=0;}d.AsyncQueue.defaults.timeout=U;J=new d.AsyncQueue();H=X[0];F=X[1];C=E;S=E+M;B.start=[H+Q*Math.sin(this._toRadian(C)),F-Q*Math.cos(this._toRadian(C))];B.end=[H+O*Math.sin(this._toRadian(S-C)),F-O*Math.cos(this._toRadian(S-C))];A.start=[H-Q*Math.sin(this._toRadian(C)),F+Q*Math.cos(this._toRadian(C))];A.end=[H-O*Math.sin(this._toRadian(S-C)),F+O*Math.cos(this._toRadian(S-C))];V=1;T=D/N;J.add({fn:function(){var aa,Z,ac,ab;aa={pageX:B.start[0],pageY:B.start[1],clientX:B.start[0],clientY:B.start[1]};Z={pageX:A.start[0],pageY:A.start[1],clientX:A.start[0],clientY:A.start[1]};ab=this._createTouchList([d.merge({identifier:L++},aa),d.merge({identifier:L++},Z)]);ac={pageX:(B.start[0]+A.start[0])/2,pageY:(B.start[0]+A.start[1])/2,clientX:(B.start[0]+A.start[0])/2,clientY:(B.start[0]+A.start[1])/2};this._simulateEvent(this.target,i,d.merge({touches:ab,targetTouches:ab,changedTouches:ab,scale:V,rotation:C},ac));if(d.UA.ios>=2){this._simulateEvent(this.target,v,d.merge({scale:V,rotation:C},ac));}},timeout:0,context:this});R=Math.floor(z/U);W=(O-Q)/R;Y=(T-V)/R;y=(S-C)/R;G=this._toRadian(S-C)/R;for(var P=0;P<R;P++){J.add({fn:function(ac){var ag=Q+(W)*ac,ae=H+ag*Math.sin(C+G*ac),aa=F-ag*Math.cos(C+G*ac),ab=H-ag*Math.sin(C+G*ac),Z=F+ag*Math.cos(C+G*ac),ak=(ae+ab)/2,aj=(aa+Z)/2,ai,ah,af,ad;ai={pageX:ae,pageY:aa,clientX:ae,clientY:aa};ah={pageX:ab,pageY:Z,clientX:ab,clientY:Z};ad=this._createTouchList([d.merge({identifier:L++},ai),d.merge({identifier:L++},ah)]);af={pageX:ak,pageY:aj,clientX:ak,clientY:aj};this._simulateEvent(this.target,r,d.merge({touches:ad,targetTouches:ad,changedTouches:ad,scale:V+Y*ac,rotation:C+y*ac},af));if(d.UA.ios>=2){this._simulateEvent(this.target,f,d.merge({scale:V+Y*ac,rotation:C+y*ac},af));}},args:[P],context:this});}J.add({fn:function(){var ac=this._getEmptyTouchList(),aa,Z,ad,ab;aa={pageX:B.end[0],pageY:B.end[1],clientX:B.end[0],clientY:B.end[1]};Z={pageX:A.end[0],pageY:A.end[1],clientX:A.end[0],clientY:A.end[1]};ab=this._createTouchList([d.merge({identifier:L++},aa),d.merge({identifier:L++},Z)]);ad={pageX:(B.end[0]+A.end[0])/2,pageY:(B.end[0]+A.end[1])/2,clientX:(B.end[0]+A.end[0])/2,clientY:(B.end[0]+A.end[1])/2};if(d.UA.ios>=2){this._simulateEvent(this.target,a,d.merge({scale:T,rotation:S},ad));}this._simulateEvent(this.target,s,d.merge({touches:ac,targetTouches:ac,changedTouches:ab,scale:T,rotation:S},ad));},context:this});if(K&&d.Lang.isFunction(K)){J.add({fn:K,context:this.node});}J.run();},tap:function(A,F,y,z,C){var H=new d.AsyncQueue(),G=this._getEmptyTouchList(),D,E,B;F=this._calculateDefaultPoint(F);if(!d.Lang.isNumber(y)||y<1){y=1;}if(!d.Lang.isNumber(z)){z=b.HOLD_TAP;}if(!d.Lang.isNumber(C)){C=b.DELAY_TAP;}E={pageX:F[0],pageY:F[1],clientX:F[0],clientY:F[1]};D=this._createTouchList([d.merge({identifier:0},E)]);for(B=0;B<y;B++){H.add({fn:function(){this._simulateEvent(this.target,i,d.merge({touches:D,targetTouches:D,changedTouches:D},E));},context:this,timeout:(B===0)?0:C});H.add({fn:function(){this._simulateEvent(this.target,s,d.merge({touches:G,targetTouches:G,changedTouches:D},E));},context:this,timeout:z});}if(y>1&&!((d.config.win&&("ontouchstart" in d.config.win))&&!(d.UA.chrome&&d.UA.chrome<6))){H.add({fn:function(){this._simulateEvent(this.target,c,E);},context:this});}if(A&&d.Lang.isFunction(A)){H.add({fn:A,context:this.node});}H.run();},flick:function(z,y,A,D,C){var B;y=this._calculateDefaultPoint(y);if(!d.Lang.isString(A)){A=q;}else{A=A.toLowerCase();if(A!==q&&A!==u){d.error(j+"(flick): Only x or y axis allowed");}}if(!d.Lang.isNumber(D)){D=b.DISTANCE_FLICK;}if(!d.Lang.isNumber(C)){C=b.DURATION_FLICK;}else{if(C>b.MAX_DURATION_FLICK){C=b.MAX_DURATION_FLICK;}}if(Math.abs(D)/C<b.MIN_VELOCITY_FLICK){C=Math.abs(D)/b.MIN_VELOCITY_FLICK;}B={start:d.clone(y),end:[(A===q)?y[0]+D:y[0],(A===u)?y[1]+D:y[1]]};this._move(z,B,C);},move:function(y,A,z){var B;if(!d.Lang.isObject(A)){A={point:this._calculateDefaultPoint([]),xdist:b.DISTANCE_MOVE,ydist:0};}else{if(!d.Lang.isArray(A.point)){A.point=this._calculateDefaultPoint([]);}else{A.point=this._calculateDefaultPoint(A.point);}if(!d.Lang.isNumber(A.xdist)){A.xdist=b.DISTANCE_MOVE;}if(!d.Lang.isNumber(A.ydist)){A.ydist=0;
+}}if(!d.Lang.isNumber(z)){z=b.DURATION_MOVE;}else{if(z>b.MAX_DURATION_MOVE){z=b.MAX_DURATION_MOVE;}}B={start:d.clone(A.point),end:[A.point[0]+A.xdist,A.point[1]+A.ydist]};this._move(y,B,z);},_move:function(A,G,B){var H,z=g,D,F,E,y=0;if(!d.Lang.isNumber(B)){B=b.DURATION_MOVE;}else{if(B>b.MAX_DURATION_MOVE){B=b.MAX_DURATION_MOVE;}}if(!d.Lang.isObject(G)){G={start:[l,k],end:[l+b.DISTANCE_MOVE,k]};}else{if(!d.Lang.isArray(G.start)){G.start=[l,k];}if(!d.Lang.isArray(G.end)){G.end=[l+b.DISTANCE_MOVE,k];}}d.AsyncQueue.defaults.timeout=z;H=new d.AsyncQueue();H.add({fn:function(){var J={pageX:G.start[0],pageY:G.start[1],clientX:G.start[0],clientY:G.start[1]},I=this._createTouchList([d.merge({identifier:y++},J)]);this._simulateEvent(this.target,i,d.merge({touches:I,targetTouches:I,changedTouches:I},J));},timeout:0,context:this});D=Math.floor(B/z);F=(G.end[0]-G.start[0])/D;E=(G.end[1]-G.start[1])/D;for(var C=0;C<D;C++){H.add({fn:function(K){var J=G.start[0]+(F*K),I=G.start[1]+(E*K),M={pageX:J,pageY:I,clientX:J,clientY:I},L=this._createTouchList([d.merge({identifier:y++},M)]);this._simulateEvent(this.target,r,d.merge({touches:L,targetTouches:L,changedTouches:L},M));},args:[C],context:this});}H.add({fn:function(){var J={pageX:G.end[0],pageY:G.end[1],clientX:G.end[0],clientY:G.end[1]},I=this._createTouchList([d.merge({identifier:y},J)]);this._simulateEvent(this.target,r,d.merge({touches:I,targetTouches:I,changedTouches:I},J));},timeout:0,context:this});H.add({fn:function(){var K={pageX:G.end[0],pageY:G.end[1],clientX:G.end[0],clientY:G.end[1]},J=this._getEmptyTouchList(),I=this._createTouchList([d.merge({identifier:y},K)]);this._simulateEvent(this.target,s,d.merge({touches:J,targetTouches:J,changedTouches:I},K));},context:this});if(A&&d.Lang.isFunction(A)){H.add({fn:A,context:this.node});}H.run();},_getEmptyTouchList:function(){if(!n){n=this._createTouchList([]);}return n;},_createTouchList:function(A){var B=[],z,y=this;if(!!A&&d.Lang.isArray(A)){if(d.UA.android&&d.UA.android>=4||d.UA.ios&&d.UA.ios>=2){d.each(A,function(C){if(!C.identifier){C.identifier=0;}if(!C.pageX){C.pageX=0;}if(!C.pageY){C.pageY=0;}if(!C.screenX){C.screenX=0;}if(!C.screenY){C.screenY=0;}B.push(p.createTouch(d.config.win,y.target,C.identifier,C.pageX,C.pageY,C.screenX,C.screenY));});z=p.createTouchList.apply(p,B);}else{if(d.UA.ios&&d.UA.ios<2){d.error(j+": No touch event simulation framework present.");}else{z=[];d.each(A,function(C){if(!C.identifier){C.identifier=0;}if(!C.clientX){C.clientX=0;}if(!C.clientY){C.clientY=0;}if(!C.pageX){C.pageX=0;}if(!C.pageY){C.pageY=0;}if(!C.screenX){C.screenX=0;}if(!C.screenY){C.screenY=0;}z.push({target:y.target,identifier:C.identifier,clientX:C.clientX,clientY:C.clientY,pageX:C.pageX,pageY:C.pageY,screenX:C.screenX,screenY:C.screenY});});z.item=function(C){return z[C];};}}}else{d.error(j+": Invalid touchPoints passed");}return z;},_simulateEvent:function(B,z,y){var A;if(e[z]){if((d.config.win&&("ontouchstart" in d.config.win))&&!(d.UA.chrome&&d.UA.chrome<6)){d.Event.simulate(B,z,y);}else{if(this._isSingleTouch(y.touches,y.targetTouches,y.changedTouches)){z={touchstart:t,touchmove:x,touchend:w}[z];y.button=0;y.relatedTarget=null;A=(z===w)?y.changedTouches:y.touches;y=d.mix(y,{screenX:A.item(0).screenX,screenY:A.item(0).screenY,clientX:A.item(0).clientX,clientY:A.item(0).clientY},true);d.Event.simulate(B,z,y);if(z==w){d.Event.simulate(B,o,y);}}else{d.error("_simulateEvent(): Event '"+z+"' has multi touch objects that can't be simulated in your platform.");}}}else{d.Event.simulate(B,z,y);}},_isSingleTouch:function(A,z,y){return(A&&(A.length<=1))&&(z&&(z.length<=1))&&(y&&(y.length<=1));}};d.GestureSimulation=m;d.GestureSimulation.defaults=b;d.GestureSimulation.GESTURES=h;d.Event.simulateGesture=function(C,B,A,y){C=d.one(C);var z=new d.GestureSimulation(C);B=B.toLowerCase();if(!y&&d.Lang.isFunction(A)){y=A;A={};}A=A||{};if(h[B]){switch(B){case"tap":z.tap(y,A.point,A.times,A.hold,A.delay);break;case"doubletap":z.tap(y,A.point,2);break;case"press":if(!d.Lang.isNumber(A.hold)){A.hold=b.HOLD_PRESS;}else{if(A.hold<b.MIN_HOLD_PRESS){A.hold=b.MIN_HOLD_PRESS;}else{if(A.hold>b.MAX_HOLD_PRESS){A.hold=b.MAX_HOLD_PRESS;}}}z.tap(y,A.point,1,A.hold);break;case"move":z.move(y,A.path,A.duration);break;case"flick":z.flick(y,A.point,A.axis,A.distance,A.duration);break;case"pinch":z.pinch(y,A.center,A.r1,A.r2,A.duration,A.start,A.rotation);break;case"rotate":z.rotate(y,A.center,A.r1,A.r2,A.duration,A.start,A.rotation);break;}}else{d.error(j+": Not a supported gesture simulation: "+B);}};},"@VERSION@",{requires:["event-simulate","async-queue","node-screen"]});
View
17 build/gesture-simulate/gesture-simulate.js
@@ -1,6 +1,5 @@
YUI.add('gesture-simulate', function(Y) {
-(function() {
/**
* Simulate high-level user gestures by generating a set of native DOM events.
*
@@ -8,7 +7,9 @@ YUI.add('gesture-simulate', function(Y) {
* @requires event-simulate, async-queue, node-screen
*/
-var gestureNames = {
+var NAME = "gesture-simulate",
+
+ gestureNames = {
tap: 1,
doubletap: 1,
press: 1,
@@ -1055,19 +1056,17 @@ Y.GestureSimulation.GESTURES = gestureNames;
* @static
*/
Y.Event.simulateGesture = function(node, name, options, cb) {
-
- if(node instanceof HTMLElement) {
- node = Y.Node.one(node);
- }
+
+ node = Y.one(node);
var sim = new Y.GestureSimulation(node);
name = name.toLowerCase();
-
+
if(!cb && Y.Lang.isFunction(options)) {
cb = options;
options = {};
}
-
+
options = options || {};
if (gestureNames[name]) {
@@ -1114,7 +1113,5 @@ Y.Event.simulateGesture = function(node, name, options, cb) {
}
};
-})();
-
}, '@VERSION@' ,{requires:['event-simulate', 'async-queue', 'node-screen']});
View
19 src/gesture-simulate/js/gesture-simulate.js
@@ -1,4 +1,3 @@
-(function() {
/**
* Simulate high-level user gestures by generating a set of native DOM events.
*
@@ -6,7 +5,9 @@
* @requires event-simulate, async-queue, node-screen
*/
-var gestureNames = {
+var NAME = "gesture-simulate",
+
+ gestureNames = {
tap: 1,
doubletap: 1,
press: 1,
@@ -1053,19 +1054,17 @@ Y.GestureSimulation.GESTURES = gestureNames;
* @static
*/
Y.Event.simulateGesture = function(node, name, options, cb) {
-
- if(node instanceof HTMLElement) {
- node = Y.Node.one(node);
- }
+
+ node = Y.one(node);
var sim = new Y.GestureSimulation(node);
name = name.toLowerCase();
-
+
if(!cb && Y.Lang.isFunction(options)) {
cb = options;
options = {};
}
-
+
options = options || {};
if (gestureNames[name]) {
@@ -1110,6 +1109,4 @@ Y.Event.simulateGesture = function(node, name, options, cb) {
} else {
Y.error(NAME+': Not a supported gesture simulation: '+name);
}
-};
-
-})();
+};
View
10 src/gesture-simulate/tests/gesture-simulate.html
@@ -55,7 +55,7 @@
//reset the result
this.result = [];
- events.forEach(Y.bind(function(one) {
+ Y.each(events, Y.bind(function(one) {
// Y.one("#touchable").on(one, function(e) {});
document.getElementById("touchable")['on'+one]= Y.bind(function(e) {
e.preventDefault();
@@ -71,7 +71,7 @@
* Removes event handlers that were used during the test.
*/
tearDown : function() /*:Void*/{
- events.forEach(function(one) {
+ Y.each(events, function(one) {
document.getElementById("touchable")['on'+one]= null;
});
}
@@ -127,9 +127,10 @@
Assert.areSame(that.result[last-1].type, "mouseup");
Assert.areSame(that.result[last].type, "click");
- that.result.forEach(function(one) {
+ Y.each(that.result, function(one) {
Assert.areSame(that.result[0].clientY, one.clientY);
});
+
Assert.areSame(that.result[0].clientX+distance, that.result[last].clientX);
}
}, 5000);
@@ -292,9 +293,10 @@
Assert.areSame(that.result[last-1].type, "mouseup");
Assert.areSame(that.result[last].type, "click");
- that.result.forEach(function(one) {
+ Y.each(that.result, function(one) {
Assert.areSame(that.result[0].clientY, one.clientY);
});
+
Assert.areSame(that.result[0].clientX+distance, that.result[last].clientX);
}
}, 5000);

0 comments on commit 4567e1f

Please sign in to comment.
Something went wrong with that request. Please try again.