Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes Chrome problem and deals with pull #66 and issue #35.

  • Loading branch information...
commit 1b253ea4e71ac1e12377b087aeadcce38ded7db6 1 parent f927734
@sadfuzzy sadfuzzy authored committed
Showing with 11 additions and 9 deletions.
  1. +7 −5 js/jquery.Jcrop.js
  2. +4 −4 js/jquery.Jcrop.min.js
View
12 js/jquery.Jcrop.js
@@ -1158,11 +1158,13 @@
function trackMove(e) //{{{
{
//init 4 ios...
- var i;
- i = e.originalEvent.changedTouches[0].clientX;
- i = e.originalEvent.changedTouches[0].clientY;
- i = e.originalEvent.changedTouches[0].pageX;
- i = e.originalEvent.changedTouches[0].pageY;
+ if (e.originalEvent && e.originalEvent.changedTouches) {
+ var i;
+ i = e.originalEvent.changedTouches[0].clientX;
+ i = e.originalEvent.changedTouches[0].clientY;
+ i = e.originalEvent.changedTouches[0].pageX;
+ i = e.originalEvent.changedTouches[0].pageY;
+ }
onMove(mouseAbs(e));
return false;
View
8 js/jquery.Jcrop.min.js
@@ -16,7 +16,7 @@ T&&(e=f>0?b+R/T:b-R/T),Q/S&&Math.abs(d)<Q/S&&(c=d>0?a+Q/S:a-Q/S),a<0&&(c-=a,a-=a
(a,b){bp(p(),a,b)}function m(){b&&(c.remove(),G.show(),b=!1,ba.isAwake()?ba.setBgOpacity(d.bgOpacity,1,1):(ba.setBgOpacity(1,1,1),ba.disableHandles()),bp(F,0,1))}function n(a,e){b&&(d.bgFade&&!e?c.animate({opacity:1-a},{queue:!1,duration:d.fadeTime}):c.css({opacity:1-a}))}function o(){d.shade?k():m(),ba.isAwake()&&n(d.bgOpacity)}function p(){return c.children()}var b=!1,c=a("<div />").css({position:"absolute",zIndex:240,opacity:0}),e={top:j(),left:j().height(E),right:j().height(E),bottom:j()};return{update:g,updateRaw:i,getShades:p,setBgColor:l,enable:k,disable:m,resize:f,refresh:o,opacity:n}}(),ba=function(){function k(b){var c=a("<div />").css({position:"absolute",opacity:d.borderOpacity}).addClass(i(b));return H.append(c),c}function l(b,c){var d=a("<div />").mousedown(r(b)).css({cursor:b+"-resize",position:"absolute",zIndex:c}).addClass("ord-"+b);return Y.support&&d.bind("touchstart.jcrop",Y.createDragger(b)),I.append(d),d}function m(a){var b=d.handleSize;return l(a,c++).css({opacity:d.handleOpacity}).width
(b).height(b).addClass(i("handle"))}function n(a){return l(a,c++).addClass("jcrop-dragbar")}function o(a){var b;for(b=0;b<a.length;b++)g[a[b]]=n(a[b])}function p(a){var b,c;for(c=0;c<a.length;c++){switch(a[c]){case"n":b="hline";break;case"s":b="hline bottom";break;case"e":b="vline right";break;case"w":b="vline"}e[a[c]]=k(b)}}function q(a){var b;for(b=0;b<a.length;b++)f[a[b]]=m(a[b])}function s(a,b){d.shade||G.css({top:h(-b),left:h(-a)}),J.css({top:h(b),left:h(a)})}function u(a,b){J.width(Math.round(a)).height(Math.round(b))}function v(){var a=Z.getFixed();Z.setPressed([a.x,a.y]),Z.setCurrent([a.x2,a.y2]),w()}function w(a){if(b)return y(a)}function y(a){var c=Z.getFixed();u(c.w,c.h),s(c.x,c.y),d.shade&&_.updateRaw(c),b||A(),a?d.onSelect.call(br,t(c)):d.onChange.call(br,t(c))}function z(a,c,e){if(!b&&!c)return;d.bgFade&&!e?C.animate({opacity:a},{queue:!1,duration:d.fadeTime}):C.css("opacity",a)}function A(){J.show(),d.shade?_.opacity(N):z(N,!0),b=!0}function B(){F(),J.hide(),d.shade?_.opacity(1):z(1),b=!1,d.onRelease
.call(br)}function D(){j&&I.show()}function E(){j=!0;if(d.allowResize)return I.show(),!0}function F(){j=!1,I.hide()}function K(a){a?(W=!0,F()):(W=!1,E())}function L(){K(!1),v()}var b,c=370,e={},f={},g={},j=!1;d.dragEdges&&a.isArray(d.createDragbars)&&o(d.createDragbars),a.isArray(d.createHandles)&&q(d.createHandles),d.drawBorders&&a.isArray(d.createBorders)&&p(d.createBorders),a(document).bind("touchstart.jcrop-ios",function(b){a(b.currentTarget).hasClass("jcrop-tracker")&&b.stopPropagation()});var M=x().mousedown(r("move")).css({cursor:"move",position:"absolute",zIndex:360});return Y.support&&M.bind("touchstart.jcrop",Y.createDragger("move")),H.append(M),F(),{updateVisible:w,update:y,release:B,refresh:v,isAwake:function(){return b},setCursor:function(a){M.css("cursor",a)},enableHandles:E,enableOnly:function(){j=!0},showHandles:D,disableHandles:F,animMode:K,setBgOpacity:z,done:L}}(),bb=function(){function f(){L.css({zIndex:450}),Y.support&&a(document).bind("touchmove.jcrop",k).bind("touchend.jcrop",m),e&&a(document
-).bind("mousemove.jcrop",h).bind("mouseup.jcrop",i)}function g(){L.css({zIndex:290}),a(document).unbind(".jcrop")}function h(a){var c;return c=a.originalEvent.changedTouches[0].clientX,c=a.originalEvent.changedTouches[0].clientY,c=a.originalEvent.changedTouches[0].pageX,c=a.originalEvent.changedTouches[0].pageY,b(l(a)),!1}function i(a){return a.preventDefault(),a.stopPropagation(),V&&(V=!1,c(l(a)),ba.isAwake()&&d.onSelect.call(br,t(Z.getFixed())),g(),b=function(){},c=function(){}),!1}function j(a,d){return V=!0,b=a,c=d,f(),!1}function k(a){return a.pageX=a.originalEvent.changedTouches[0].pageX,a.pageY=a.originalEvent.changedTouches[0].pageY,h(a)}function m(a){return a.pageX=a.originalEvent.changedTouches[0].pageX,a.pageY=a.originalEvent.changedTouches[0].pageY,i(a)}function n(a){L.css("cursor",a)}var b=function(){},c=function(){},e=d.trackDocument;return e||L.mousemove(h).mouseup(i).mouseout(i),C.before(L),{activateHandlers:j,setCursor:n}}(),bc=function(){function e(){d.keySupport&&(b.show(),b.focus())}function f
-(a){b.hide()}function h(a,b,c){d.allowMove&&(Z.moveOffset([b,c]),ba.updateVisible(!0)),a.preventDefault(),a.stopPropagation()}function i(a){if(a.ctrlKey||a.metaKey)return!0;X=a.shiftKey?!0:!1;var b=X?10:1;switch(a.keyCode){case 37:h(a,-b,0);break;case 39:h(a,b,0);break;case 38:h(a,0,-b);break;case 40:h(a,0,b);break;case 27:d.allowSelect&&ba.release();break;case 9:return!0}return!1}var b=a('<input type="radio" />').css({position:"fixed",left:"-120px",width:"12px"}).addClass("jcrop-keymgr"),c=a("<div />").css({position:"absolute",overflow:"hidden"}).append(b);return d.keySupport&&(b.keydown(i).blur(f),g||!d.fixedSupport?(b.css({position:"absolute",left:"-20px"}),c.append(b).insertBefore(C)):b.insertBefore(C)),{watchKeys:e}}();Y.support&&L.bind("touchstart.jcrop",Y.newSelection),I.hide(),bq(!0);var br={setImage:bo,animateTo:be,setSelect:bf,setOptions:bj,tellSelect:bh,tellScaled:bi,setClass:bd,disable:bk,enable:bl,cancel:bm,release:ba.release,destroy:bn,focus:bc.watchKeys,getBounds:function(){return[D*S,E*T]},getWidgetSize
-:function(){return[D,E]},getScaleFactor:function(){return[S,T]},getOptions:function(){return d},ui:{holder:F,selection:J}};return a.browser.msie&&F.bind("selectstart",function(){return!1}),z.data("Jcrop",br),br},a.fn.Jcrop=function(b,c){var d;return this.each(function(){if(a(this).data("Jcrop")){if(b==="api")return a(this).data("Jcrop");a(this).data("Jcrop").setOptions(b)}else this.tagName=="IMG"?a.Jcrop.Loader(this,function(){a(this).css({display:"block",visibility:"hidden"}),d=a.Jcrop(this,b),a.isFunction(c)&&c.call(d)}):(a(this).css({display:"block",visibility:"hidden"}),d=a.Jcrop(this,b),a.isFunction(c)&&c.call(d))}),this},a.Jcrop.Loader=function(b,c,d){function g(){f.complete?(e.unbind(".jcloader"),a.isFunction(c)&&c.call(f)):window.setTimeout(g,50)}var e=a(b),f=e[0];e.bind("load.jcloader",g).bind("error.jcloader",function(b){e.unbind(".jcloader"),a.isFunction(d)&&d.call(f)}),f.complete&&a.isFunction(c)&&(e.unbind(".jcloader"),c.call(f))},a.Jcrop.defaults={allowSelect:!0,allowMove:!0,allowResize:!0,trackDocument
-:!0,baseClass:"jcrop",addClass:null,bgColor:"black",bgOpacity:.6,bgFade:!1,borderOpacity:.4,handleOpacity:.5,handleSize:7,aspectRatio:0,keySupport:!0,createHandles:["n","s","e","w","nw","ne","se","sw"],createDragbars:["n","s","e","w"],createBorders:["n","s","e","w"],drawBorders:!0,dragEdges:!0,fixedSupport:!0,touchSupport:null,shade:null,boxWidth:0,boxHeight:0,boundary:2,fadeTime:400,animationDelay:20,swingSpeed:3,minSelect:[0,0],maxSize:[0,0],minSize:[0,0],onChange:function(){},onSelect:function(){},onDblClick:function(){},onRelease:function(){}}})(jQuery);
+).bind("mousemove.jcrop",h).bind("mouseup.jcrop",i)}function g(){L.css({zIndex:290}),a(document).unbind(".jcrop")}function h(a){if(a.originalEvent&&a.originalEvent.changedTouches){var c;c=a.originalEvent.changedTouches[0].clientX,c=a.originalEvent.changedTouches[0].clientY,c=a.originalEvent.changedTouches[0].pageX,c=a.originalEvent.changedTouches[0].pageY}return b(l(a)),!1}function i(a){return a.preventDefault(),a.stopPropagation(),V&&(V=!1,c(l(a)),ba.isAwake()&&d.onSelect.call(br,t(Z.getFixed())),g(),b=function(){},c=function(){}),!1}function j(a,d){return V=!0,b=a,c=d,f(),!1}function k(a){return a.pageX=a.originalEvent.changedTouches[0].pageX,a.pageY=a.originalEvent.changedTouches[0].pageY,h(a)}function m(a){return a.pageX=a.originalEvent.changedTouches[0].pageX,a.pageY=a.originalEvent.changedTouches[0].pageY,i(a)}function n(a){L.css("cursor",a)}var b=function(){},c=function(){},e=d.trackDocument;return e||L.mousemove(h).mouseup(i).mouseout(i),C.before(L),{activateHandlers:j,setCursor:n}}(),bc=function(){function e
+(){d.keySupport&&(b.show(),b.focus())}function f(a){b.hide()}function h(a,b,c){d.allowMove&&(Z.moveOffset([b,c]),ba.updateVisible(!0)),a.preventDefault(),a.stopPropagation()}function i(a){if(a.ctrlKey||a.metaKey)return!0;X=a.shiftKey?!0:!1;var b=X?10:1;switch(a.keyCode){case 37:h(a,-b,0);break;case 39:h(a,b,0);break;case 38:h(a,0,-b);break;case 40:h(a,0,b);break;case 27:d.allowSelect&&ba.release();break;case 9:return!0}return!1}var b=a('<input type="radio" />').css({position:"fixed",left:"-120px",width:"12px"}).addClass("jcrop-keymgr"),c=a("<div />").css({position:"absolute",overflow:"hidden"}).append(b);return d.keySupport&&(b.keydown(i).blur(f),g||!d.fixedSupport?(b.css({position:"absolute",left:"-20px"}),c.append(b).insertBefore(C)):b.insertBefore(C)),{watchKeys:e}}();Y.support&&L.bind("touchstart.jcrop",Y.newSelection),I.hide(),bq(!0);var br={setImage:bo,animateTo:be,setSelect:bf,setOptions:bj,tellSelect:bh,tellScaled:bi,setClass:bd,disable:bk,enable:bl,cancel:bm,release:ba.release,destroy:bn,focus:bc.watchKeys
+,getBounds:function(){return[D*S,E*T]},getWidgetSize:function(){return[D,E]},getScaleFactor:function(){return[S,T]},getOptions:function(){return d},ui:{holder:F,selection:J}};return a.browser.msie&&F.bind("selectstart",function(){return!1}),z.data("Jcrop",br),br},a.fn.Jcrop=function(b,c){var d;return this.each(function(){if(a(this).data("Jcrop")){if(b==="api")return a(this).data("Jcrop");a(this).data("Jcrop").setOptions(b)}else this.tagName=="IMG"?a.Jcrop.Loader(this,function(){a(this).css({display:"block",visibility:"hidden"}),d=a.Jcrop(this,b),a.isFunction(c)&&c.call(d)}):(a(this).css({display:"block",visibility:"hidden"}),d=a.Jcrop(this,b),a.isFunction(c)&&c.call(d))}),this},a.Jcrop.Loader=function(b,c,d){function g(){f.complete?(e.unbind(".jcloader"),a.isFunction(c)&&c.call(f)):window.setTimeout(g,50)}var e=a(b),f=e[0];e.bind("load.jcloader",g).bind("error.jcloader",function(b){e.unbind(".jcloader"),a.isFunction(d)&&d.call(f)}),f.complete&&a.isFunction(c)&&(e.unbind(".jcloader"),c.call(f))},a.Jcrop.defaults=
+{allowSelect:!0,allowMove:!0,allowResize:!0,trackDocument:!0,baseClass:"jcrop",addClass:null,bgColor:"black",bgOpacity:.6,bgFade:!1,borderOpacity:.4,handleOpacity:.5,handleSize:7,aspectRatio:0,keySupport:!0,createHandles:["n","s","e","w","nw","ne","se","sw"],createDragbars:["n","s","e","w"],createBorders:["n","s","e","w"],drawBorders:!0,dragEdges:!0,fixedSupport:!0,touchSupport:null,shade:null,boxWidth:0,boxHeight:0,boundary:2,fadeTime:400,animationDelay:20,swingSpeed:3,minSelect:[0,0],maxSize:[0,0],minSize:[0,0],onChange:function(){},onSelect:function(){},onDblClick:function(){},onRelease:function(){}}})(jQuery);

2 comments on commit 1b253ea

@Gladhon

Unfortunetly bug #35 come's back with your if-declaration, I changed it to a more specific one, can you test it ?

if (Touch.support){
@tapmodo
Owner

I did some more debugging on this problem and came up with, I think, a comprehensive fix. The problem with the jumping on iOS turned out to be that both "touchmove" and "mousemove" were being called as the touch drag event was happening. Anyway, I sorted it out and pushed the commits just now.

Also, may benefit performance since half the events are happening?

Please test!

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