cropper.js 16 KB

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