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