WordPress/wp-includes/js/imgareaselect/jquery.imgareaselect.min.js

1 line
9.5 KiB
JavaScript
Raw Normal View History

!function(xe){var we=Math.abs,Se=Math.max,ze=Math.min,ke=Math.round;function Ce(){return xe("<div/>")}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).unbind(xe.imgAreaSelect.keyPress,xe.imgAreaSelect.onKeyPress),n.keys&&xe(document)[xe.imgAreaSelect.keyPress](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<S||-1))),z=ke(Se(c,ze(c+a,w+we(S-x)/v*(w<z||-1)))),S=ke(S)):(z=Se(c,ze(c+a,w+we(S-x)/v*(w<z||-1)