//>>built
define("demos/cropper/src/Preview",["dojo","dijit","dojox","dojo/require!dijit/_Widget,dojo/dnd/move,dojox/layout/ResizeHandle"],function(_1,_2,_3){_1.provide("demos.cropper.src.Preview");_1.require("dijit._Widget");_1.require("dojo.dnd.move");_1.require("dojox.layout.ResizeHandle");(function(d,$){var _4=function(_5,_6){var n=d.create(_6);d.place(n,_5,"before");d.place(_5,n,"first");return n;},_7="absolute",_8="position",_9="px",_a=Math.floor;d.declare("image.Preview",_2._Widget,{glassSize:150,scale:2,withMouseMove:false,withDrag:true,moveInterval:50,hoverable:false,resizeable:true,opacity:0.35,postCreate:function(){var gs=this.glassSize,s=this.scale;var mb=d.marginBox(this.domNode);this.currentSize=mb;this.container=_4(this.domNode,"div");d.marginBox(this.container,mb);this.picker=d.create("div",{"class":"imageDragger",style:{opacity:this.hoverable?0:this.opacity,width:gs+_9,height:gs+_9}},this.domNode,"before");this.preview=d.create("div",{style:{position:_7,overflow:"hidden",width:_a(gs*s)+_9,height:_a(gs*s)+_9}},d.body());var n=_4(d.create("img",{style:{position:_7},src:this.altSrc||this.domNode.src},this.preview),"div");d.style(n,_8,"relative");d.style(this.domNode,_8,_7);this.image=d.query("img",this.preview).onload(d.hitch(this,"_adjustImage"))[0];this._positionPicker();this.mover=new d.dnd.move.parentConstrainedMoveable(this.picker,{area:"content",within:true});if(this.resizeable){this._handle=new _3.layout.ResizeHandle({targetContainer:this.picker,fixedAspect:true,intermediateChanges:true,activeResize:true,onResize:d.hitch(this,function(e,f){this._adjustImage(e,f);this._whileMoving();}),constrainMax:true,maxWidth:mb.w,maxHeight:mb.h,minWidth:40,minHeight:40}).placeAt(this.picker);}d.subscribe("/dnd/move/start",this,"_startDnd");d.subscribe("/dnd/move/stop",this,"_stopDnd");d.isIE&&(this.image.src=this.image.src);this.connect(d.global,"onresize","_positionPicker");if(this.hoverable){this.connect(this.container,"onmouseenter","_enter");this.connect(this.container,"onmouseleave","_leave");}setTimeout(_1.hitch(this,"_positionPicker"),125);},_adjustImage:function(e){var tc=this.coords,s=this.scale;if(e&&e.type&&(e.type=="mouseup"||e.type=="mousemove")){var xy=d.coords(this.picker);this.scale=d.coords(this.preview).w/xy.w;}else{if(e&&e.type&&e.type=="load"&&this.imageReady(e)){}}d.style(this.image,{height:_a(tc.h*s)+_9,width:_a(tc.w*s)+_9});},_positionPicker:function(e){var tc=this.coords=d.coords(this.container,true);d.style(this.preview,{left:tc.x+tc.w+10+_9,top:tc.y+_9});},_startDnd:function(n){if(!this._interval&&n&&n.node==this.picker){this._interval=this.connect(d.doc,"onmousemove","_whileMoving");}},_stopDnd:function(){if(this._interval){this.disconnect(this._interval);delete this._interval;if(this.resizeable&&this._lastXY){var tc=this.coords;this._handle.maxSize={h:_a(tc.h-(this._lastXY.t-tc.t)),w:_a(tc.w-(this._lastXY.l-tc.l))};}}},_whileMoving:function(){var xy=this._lastXY=d.coords(this.picker),tc=this.coords,r=this.image.width/tc.w,x=_a((xy.l-tc.l)*r),y=_a((xy.t-tc.t)*r);d.style(this.image,{top:"-"+y+_9,left:"-"+x+_9});},destroy:function(){d.place(this.domNode,this.container,"before");d.forEach(["preview","picker","container","image"],function(n){d.destroy(this[n]);delete this[n];},this);this.inherited(arguments);},imageReady:function(){},_enter:function(e){this._anim&&this._anim.stop();this._anim=d.anim(this.picker,{opacity:this.opacity});},_leave:function(e){if(!this._interval&&!this._handle._isSizing){this._anim&&this._anim.stop();this._anim=d.anim(this.picker,{opacity:0});}}});d.extend(d.NodeList,{preview:function(_b){return this.instantiate(image.Preview,_b);}});})(_1,_1.query);});