diff --git a/src/js/_enqueues/vendor/imgareaselect/jquery.imgareaselect.js b/src/js/_enqueues/vendor/imgareaselect/jquery.imgareaselect.js index c0b573934f..d825b9cddf 100644 --- a/src/js/_enqueues/vendor/imgareaselect/jquery.imgareaselect.js +++ b/src/js/_enqueues/vendor/imgareaselect/jquery.imgareaselect.js @@ -1,6 +1,6 @@ /* * imgAreaSelect jQuery plugin - * version 0.9.10-wp + * version 0.9.10-wp2 * * Copyright (c) 2008-2013 Michal Wojciechowski (odyniec.net) * @@ -20,7 +20,7 @@ var abs = Math.abs, max = Math.max, min = Math.min, - round = Math.round; + floor = Math.floor; /** * Create a new HTML div element @@ -230,12 +230,12 @@ $.imgAreaSelect = function (img, options) { function getSelection(noScale) { var sx = noScale || scaleX, sy = noScale || scaleY; - return { x1: round(selection.x1 * sx), - y1: round(selection.y1 * sy), - x2: round(selection.x2 * sx), - y2: round(selection.y2 * sy), - width: round(selection.x2 * sx) - round(selection.x1 * sx), - height: round(selection.y2 * sy) - round(selection.y1 * sy) }; + return { x1: floor(selection.x1 * sx), + y1: floor(selection.y1 * sy), + x2: floor(selection.x2 * sx), + y2: floor(selection.y2 * sy), + width: floor(selection.x2 * sx) - floor(selection.x1 * sx), + height: floor(selection.y2 * sy) - floor(selection.y1 * sy) }; } /** @@ -257,10 +257,10 @@ $.imgAreaSelect = function (img, options) { var sx = noScale || scaleX, sy = noScale || scaleY; selection = { - x1: round(x1 / sx || 0), - y1: round(y1 / sy || 0), - x2: round(x2 / sx || 0), - y2: round(y2 / sy || 0) + x1: floor(x1 / sx || 0), + y1: floor(y1 / sy || 0), + x2: floor(x2 / sx || 0), + y2: floor(y2 / sy || 0) }; selection.width = selection.x2 - selection.x1; @@ -283,7 +283,7 @@ $.imgAreaSelect = function (img, options) { * Get image offset. The .offset() method returns float values, so they * need to be rounded. */ - imgOfs = { left: round($img.offset().left), top: round($img.offset().top) }; + imgOfs = { left: floor($img.offset().left), top: floor($img.offset().top) }; /* Get image dimensions */ imgWidth = $img.innerWidth(); @@ -293,10 +293,10 @@ $.imgAreaSelect = function (img, options) { imgOfs.left += ($img.outerWidth() - imgWidth) >> 1; /* Set minimum and maximum selection area dimensions */ - minWidth = round(options.minWidth / scaleX) || 0; - minHeight = round(options.minHeight / scaleY) || 0; - maxWidth = round(min(options.maxWidth / scaleX || 1<<24, imgWidth)); - maxHeight = round(min(options.maxHeight / scaleY || 1<<24, imgHeight)); + minWidth = floor(options.minWidth / scaleX) || 0; + minHeight = floor(options.minHeight / scaleY) || 0; + maxWidth = floor(min(options.maxWidth / scaleX || 1<<24, imgWidth)); + maxHeight = floor(min(options.maxHeight / scaleY || 1<<24, imgHeight)); /* * Workaround for jQuery 1.3.2 incorrect offset calculation, originally @@ -311,8 +311,8 @@ $.imgAreaSelect = function (img, options) { /* Determine parent element offset */ parOfs = /absolute|relative/.test($parent.css('position')) ? - { left: round($parent.offset().left) - $parent.scrollLeft(), - top: round($parent.offset().top) - $parent.scrollTop() } : + { left: floor($parent.offset().left) - $parent.scrollLeft(), + top: floor($parent.offset().top) - $parent.scrollTop() } : position == 'fixed' ? { left: $(document).scrollLeft(), top: $(document).scrollTop() } : { left: 0, top: 0 }; @@ -430,6 +430,13 @@ $.imgAreaSelect = function (img, options) { function doUpdate(resetKeyPress) { adjust(); update(resetKeyPress); + updateSelectionRelativeToParentElement(); + } + + /** + * Set the correct values of x1, y1, x2, and y2. + */ + function updateSelectionRelativeToParentElement() { x1 = viewX(selection.x1); y1 = viewY(selection.y1); x2 = viewX(selection.x2); y2 = viewY(selection.y2); } @@ -571,16 +578,16 @@ $.imgAreaSelect = function (img, options) { if (xFirst) { x2 = max(left, min(left + imgWidth, x1 + abs(y2 - y1) * aspectRatio * (x2 > x1 || -1))); - y2 = round(max(top, min(top + imgHeight, + y2 = floor(max(top, min(top + imgHeight, y1 + abs(x2 - x1) / aspectRatio * (y2 > y1 || -1)))); - x2 = round(x2); + x2 = floor(x2); } else { y2 = max(top, min(top + imgHeight, y1 + abs(x2 - x1) / aspectRatio * (y2 > y1 || -1))); - x2 = round(max(left, min(left + imgWidth, + x2 = floor(max(left, min(left + imgWidth, x1 + abs(y2 - y1) * aspectRatio * (x2 > x1 || -1)))); - y2 = round(y2); + y2 = floor(y2); } } @@ -589,6 +596,14 @@ $.imgAreaSelect = function (img, options) { * aspect ratio */ function doResize() { + /* + * Make sure x1, x2, y1, y2 are initialized to avoid the following calculation + * getting incorrect results. + */ + if ( x1 == null || x2 == null || y1 == null || y2 == null ) { + updateSelectionRelativeToParentElement(); + } + /* * Make sure the top left corner of the selection area stays within * image boundaries (it might not if the image source was dynamically diff --git a/src/js/_enqueues/vendor/imgareaselect/jquery.imgareaselect.min.js b/src/js/_enqueues/vendor/imgareaselect/jquery.imgareaselect.min.js index f2b1c8b4a6..22cb54f75e 100644 --- a/src/js/_enqueues/vendor/imgareaselect/jquery.imgareaselect.min.js +++ b/src/js/_enqueues/vendor/imgareaselect/jquery.imgareaselect.min.js @@ -1 +1 @@ -!function(xe){var we=Math.abs,Se=Math.max,ze=Math.min,ke=Math.round;function Ce(){return xe("
")}xe.imgAreaSelect=function(o,n){var t,i,r,c,d,a,s,u,l,h,f,m,e,p,y,g,v,b,x,w,S,z,k,C,A,W,I,K=xe(o),P=Ce(),N=Ce(),H=Ce().add(Ce()).add(Ce()).add(Ce()),M=Ce().add(Ce()).add(Ce()).add(Ce()),E=xe([]),O={left:0,top:0},T={left:0,top:0},L=0,j="absolute",D={x1:0,y1:0,x2:0,y2:0,width:0,height:0},R=document.documentElement,X=navigator.userAgent;function Y(e){return e+O.left-T.left}function $(e){return e+O.top-T.top}function q(e){return e-O.left+T.left}function B(e){return e-O.top+T.top}function Q(e){return Se(e.pageX||0,G(e).x)-T.left}function F(e){return Se(e.pageY||0,G(e).y)-T.top}function G(e){e=e.originalEvent||{};return e.touches&&e.touches.length?{x:e.touches[0].pageX,y:e.touches[0].pageY}:{x:0,y:0}}function J(e){var t=e||h,e=e||f;return{x1:ke(D.x1*t),y1:ke(D.y1*e),x2:ke(D.x2*t),y2:ke(D.y2*e),width:ke(D.x2*t)-ke(D.x1*t),height:ke(D.y2*e)-ke(D.y1*e)}}function U(e,t,o,i,s){var n=s||h,s=s||f;(D={x1:ke(e/n||0),y1:ke(t/s||0),x2:ke(o/n||0),y2:ke(i/s||0)}).width=D.x2-D.x1,D.height=D.y2-D.y1}function V(){t&&K.width()&&(O={left:ke(K.offset().left),top:ke(K.offset().top)},d=K.innerWidth(),a=K.innerHeight(),O.top+=K.outerHeight()-a>>1,O.left+=K.outerWidth()-d>>1,e=ke(n.minWidth/h)||0,p=ke(n.minHeight/f)||0,y=ke(ze(n.maxWidth/h||1<<24,d)),g=ke(ze(n.maxHeight/f||1<<24,a)),"1.3.2"!=xe().jquery||"fixed"!=j||R.getBoundingClientRect||(O.top+=Se(document.body.scrollTop,R.scrollTop),O.left+=Se(document.body.scrollLeft,R.scrollLeft)),T=/absolute|relative/.test(s.css("position"))?{left:ke(s.offset().left)-s.scrollLeft(),top:ke(s.offset().top)-s.scrollTop()}:"fixed"==j?{left:xe(document).scrollLeft(),top:xe(document).scrollTop()}:{left:0,top:0},r=Y(0),c=$(0),(D.x2>d||D.y2>a)&&ne())}function Z(e){if(b){switch(P.css({left:Y(D.x1),top:$(D.y1)}).add(N).width(A=D.width).height(W=D.height),N.add(H).add(E).css({left:0,top:0}),H.width(Se(A-H.outerWidth()+H.innerWidth(),0)).height(Se(W-H.outerHeight()+H.innerHeight(),0)),xe(M[0]).css({left:r,top:c,width:D.x1,height:a}),xe(M[1]).css({left:r+D.x1,top:c,width:A,height:D.y1}),xe(M[2]).css({left:r+D.x2,top:c,width:d-D.x2,height:a}),xe(M[3]).css({left:r+D.x1,top:c+D.y2,width:A,height:a-D.y2}),A-=E.outerWidth(),W-=E.outerHeight(),E.length){case 8:xe(E[4]).css({left:A>>1}),xe(E[5]).css({left:A,top:W>>1}),xe(E[6]).css({left:A>>1,top:W}),xe(E[7]).css({top:W>>1});case 4:E.slice(1,3).css({left:A}),E.slice(2,4).css({top:W})}!1!==e&&(xe.imgAreaSelect.onKeyPress!=me&&xe(document).off(xe.imgAreaSelect.keyPress,xe.imgAreaSelect.onKeyPress),n.keys&&xe(document).on(xe.imgAreaSelect.keyPress,function(){xe.imgAreaSelect.onKeyPress=me})),ge&&H.outerWidth()-H.innerWidth()==2&&(H.css("margin",0),setTimeout(function(){H.css("margin","auto")},0))}}function _(e){V(),Z(e),x=Y(D.x1),w=$(D.y1),S=Y(D.x2),z=$(D.y2)}function ee(e,t){n.fadeSpeed?e.fadeOut(n.fadeSpeed,t):e.hide()}function te(e){var t=q(Q(e))-D.x1,e=B(F(e))-D.y1;I||(V(),I=!0,P.one("mouseout",function(){I=!1})),m="",n.resizable&&(e<=n.resizeMargin?m="n":e>=D.height-n.resizeMargin&&(m="s"),t<=n.resizeMargin?m+="w":t>=D.width-n.resizeMargin&&(m+="e")),P.css("cursor",m?m+"-resize":n.movable?"move":""),i&&i.toggle()}function oe(e){xe("body").css("cursor",""),!n.autoHide&&D.width*D.height!=0||ee(P.add(M),function(){xe(this).hide()}),xe(document).off("mousemove touchmove",re),P.on("mousemove touchmove",te),n.onSelectEnd(o,J())}function ie(e){return"mousedown"==e.type&&1!=e.which||(te(e),V(),m?(xe("body").css("cursor",m+"-resize"),x=Y(D[/w/.test(m)?"x2":"x1"]),w=$(D[/n/.test(m)?"y2":"y1"]),xe(document).on("mousemove touchmove",re).one("mouseup touchend",oe),P.off("mousemove touchmove",te)):n.movable?(u=r+D.x1-Q(e),l=c+D.y1-F(e),P.off("mousemove touchmove",te),xe(document).on("mousemove touchmove",de).one("mouseup touchend",function(){n.onSelectEnd(o,J()),xe(document).off("mousemove touchmove",de),P.on("mousemove touchmove",te)})):K.mousedown(e)),!1}function se(e){v&&(e?(S=Se(r,ze(r+d,x+we(z-w)*v*(x