text: YUI.add("aui-image-cropper",function(e,t){var n=e.Lang,r=n.isBoolean,i=n.isNumber,s=n.toInt,o=e.getClassName("image-cropper","crop"),u=e.getClassName("image-cropper","crop","outline"),a=e.getClassName("image-cropper","overlay"),f=e.getClassName("image-cropper","crop","hover"),l=e.Component.create({NAME:"image-cropper",ATTRS:{cropHeight:{value:100,validator:i},cropWidth:{value:100,validator:i},minWidth:{value:undefined},minHeight:{value:undefined},movable:{value:!0,validator:r},preserveRatio:{value:!1,validator:r},region:{getter:"_getCropRegion",value:{}},resizable:{value:!0,validator:r},x:{value:0,setter:Math.round,validator:i},y:{value:0,setter:Math.round,validator:i}},UI_ATTRS:["cropHeight","cropWidth","minWidth","minHeight","movable","resizable","x","y"],prototype:{renderUI:function(){var t=this,n=t.get("boundingBox"),r=t.get("srcNode");t.cropNode=e.Node.create('<div class="'+o+'"></div>'),t.cropNode.append(e.Node.create('<div class="'+u+'"></div>')),t.overlay=e.Node.create('<div class="'+a+'"></div>'),e.all([t.cropNode,t.overlay]).appendTo(n),t._boundingBox=n,t._renderDrag(),t._renderResize()},bindUI:function(){var t=this;t._fireCropEventTask=e.debounce(t._fireCropEvent,10,t),t.publish("crop",{defaultFn:t._defCropFn}),t.on(["drag:start","resize:start"],e.debounce(t._syncRegion,25)),t.after(["drag:drag","resize:resize"],t._fireCropEvent,t),t.after(["xChange","yChange","cropWidthChange","cropHeightChange"],function(e){t._fireCropEventTask(e),t._syncCropNodeUI()}),t._createHover()},syncUI:function(){var e=this;e._uiSetPreserveRatio(e.get("preserveRatio")),e.syncImageUI(),e._syncCropNodeUI()},destructor:function(){var e=this;e._destroyDrag(),e._destroyResize()},syncImageUI:function(){var e=this,t=e.get("srcNode"),n=e.overlay;e.cropNode.setStyle("backgroundImage","url("+t.attr("src")+")"),e._constrainValues(),e._syncXY();var r=e._getConstraintRegion(),i=e.drag,s=e.resize;i&&i.con.set("constrain",r),s&&s.con.set("constrain",r)},_constrainValues:function(){var e=this,t=e.get("srcNode"),n=e.get("cropHeight"),r=e.get("cropWidth"),i=e.get("x"),s=e.get("y"),o=t.width(),u=t.height();s=Math.max(s,0),s+n>u&&(s=Math.max(u-n,0)),e.set("y",s),s+n>u&&(n=Math.max(u-s,0)),e.set("cropHeight",n),i=Math.max(i,0),i+r>o&&(i=Math.max(o-r,0)),e.set("x",i),i+r>o&&(r=Math.max(o-i,0)),e.set("cropWidth",r)},_createHover:function(){var e=this;e._destroyHover(),e._hoverHandles=e.cropNode.on("hover",e._hoverOverlay,e._unHoverOverlay,e)},_defCropFn:function(e){var t=this,n=e.cropType;n=="drag:drag"?t._syncXY():n=="resize:resize"&&t._syncCropSize()},_destroyDrag:function(e){var t=this;t.drag&&(t.drag.destroy(),delete t.drag)},_destroyHover:function(){var e=this;e._hoverHandles&&(e._hoverHandles.detach(),e._hoverHandles=null)},_destroyResize:function(e){var t=this;t.resize&&(t.resize.destroy(),delete t.resize)},_fireCropEvent:function(e){var t=this;t.fire("crop",{cropType:e.type})},_getConstraintRegion:function(e){var t=this,n=e?null:t._origRegion;if(!n){var r=t.get("srcNode"),i=t.cropNode,s=r.getXY(),o=s[0],u=s[1];n={bottom:u+r.height()+i.getBorderWidth("b"),left:o-i.getBorderWidth("l"),right:o+r.width()+i.getBorderWidth("r"),top:u-i.getBorderWidth("t")},t._origRegion||(t._origRegion=n)}return n},_getCropRegion:function(){var e=this;return{height:e.get("cropHeight"),width:e.get("cropWidth"),x:e.get("x"),y:e.get("y")}},_hoverOverlay:function(){var e=this;!e._isDragging()&&!e._isResizing()&&e._boundingBox.addClass(f)},_isDragging:function(){var e=this,t=e.drag;return t&&t.get("dragging")},_isResizing:function(){var e=this,t=e.resize;return t&&t.get("resizing")},_renderDrag:function(){var t=this,n=(new e.DD.Drag({node:t.cropNode})).plug(e.Plugin.DDConstrained,{constrain:t._getConstraintRegion()});n.addTarget(t),t.drag=n},_renderResize:function(){var t=this,n=(new e.Resize({node:t.cropNode})).plug(e.Plugin.ResizeConstrained,{constrain:t._getConstraintRegion(),preserveRatio:t.get("preserveRatio"),minHeight:t.get("minHeight"),minWidth:t.get("minWidth")});n.addTarget(t),t.resize=n},_syncCropNodeUI:function(){var e=this;e.cropNode.setStyle("backgroundPosition",-e.get("x")+"px "+ -e.get("y")+"px")},_syncCropSize:function(e){var t=this,n=t.cropNode;t.set("cropHeight",n.height()),t.set("cropWidth",n.width())},_syncRegion:function(e){var t=this,n=t._getConstraintRegion(!0),r=t._origRegion;if(n.bottom!=r.bottom||n.left!=r.left||n.right!=r.right||n.top!=r.top){var i=t.drag,s=t.resize;i&&i.con.set("constrain",n),s&&s.con.set("constrain",n),t._origRegion=n}},_syncXY:function(e){var t=this,n=t.cropNode;t.set("x",s(n.getStyle("left"))+n.getBorderWidth("l")),t.set("y",s(n.getStyle("top"))+n.getBorderWidth("t"))},_uiSetCropHeight:function(e){var t=this;t.cropNode.height(e)},_uiSetCropWidth:function(e){var t=this;t.cropNode.width(e)},_uiSetDisabled:function(e){var t=this;l.superclass._uiSetDisabled.apply(t,arguments);var n=!e;t.cropNode.toggle(n),n?t._createHover():t._destroyHover()},_uiSetMinHeight:function(e){var t=this,n=t.resize;n&&n.con.set("minHeight",e)},_uiSetMinWidth:function(e){var t=this,n=t.resize;n&&n.con.set("minWidth",e)},_uiSetMovable:function(e){var t=this;t.drag.set("lock",!e)},_uiSetPreserveRatio:function(e){var t=this,n=t.resize;n&&n.con.set("preserveRatio",e)},_uiSetResizable:function(e){var t=this;e?t._stopResizeHandle&&t._stopResizeHandle.detach():t._stopResizeHandle||(t._stopResizeHandle=t.resize.on("resize:resize",function(e){e.halt()}))},_uiSetX:function(e){var t=this,n=t.get("srcNode"),r=t.cropNode;r.setStyle("left",e-r.getBorderWidth("l"))},_uiSetY:function(e){var t=this,n=t.get("srcNode"),r=t.cropNode;r.setStyle("top",e-r.getBorderWidth("t"))},_unHoverOverlay:function(){var e=this;!e._isDragging()&&!e._isResizing()&&e._boundingBox.removeClass(f)}}});e.ImageCropper=l},"2.5.0",{requires:["resize-base","resize-constrain","dd-constrain","aui-node-base","aui-component"],skinnable:!0});
  