﻿(function(D){D.widget("ui.resizable",D.extend({},D.ui.mouse,{_init:function(){var K=this,M=this.options;this.element.addClass("ui-resizable");D.extend(this,{_aspectRatio:!!(M.aspectRatio),aspectRatio:M.aspectRatio,originalElement:this.element,_proportionallyResizeElements:[],_helper:M.helper||M.ghost||M.animate?M.helper||"ui-resizable-helper":null});if(this.element[0].nodeName.match(/canvas|textarea|input|select|button|img/i)){if(/relative/.test(this.element.css("position"))&&D.browser.opera){this.element.css({position:"relative",top:"auto",left:"auto"})}this.element.wrap(D('<div class="ui-wrapper" style="overflow: hidden;"></div>').css({position:this.element.css("position"),width:this.element.outerWidth(),height:this.element.outerHeight(),top:this.element.css("top"),left:this.element.css("left")}));this.element=this.element.parent().data("resizable",this.element.data("resizable"));this.elementIsWrapper=true;this.element.css({marginLeft:this.originalElement.css("marginLeft"),marginTop:this.originalElement.css("marginTop"),marginRight:this.originalElement.css("marginRight"),marginBottom:this.originalElement.css("marginBottom")});this.originalElement.css({marginLeft:0,marginTop:0,marginRight:0,marginBottom:0});this.originalResizeStyle=this.originalElement.css("resize");this.originalElement.css("resize","none");this._proportionallyResizeElements.push(this.originalElement.css({position:"static",zoom:1,display:"block"}));this.originalElement.css({margin:this.originalElement.css("margin")});this._proportionallyResize()}this.handles=M.handles||(!D(".ui-resizable-handle",this.element).length?"e,s,se":{n:".ui-resizable-n",e:".ui-resizable-e",s:".ui-resizable-s",w:".ui-resizable-w",se:".ui-resizable-se",sw:".ui-resizable-sw",ne:".ui-resizable-ne",nw:".ui-resizable-nw"});if(this.handles.constructor==String){if(this.handles=="all"){this.handles="n,e,s,w,se,sw,ne,nw"}var L=this.handles.split(",");this.handles={};for(var N=0;N<L.length;N++){var C=D.trim(L[N]),A="ui-resizable-"+C;var B=D('<div class="ui-resizable-handle '+A+'"></div>');if(/sw|se|ne|nw/.test(C)){B.css({zIndex:++M.zIndex})}if("se"==C){B.addClass("ui-icon ui-icon-gripsmall-diagonal-se")}this.handles[C]=".ui-resizable-"+C;this.element.append(B)}}this._renderAxis=function(H){H=H||this.element;for(var I in this.handles){if(this.handles[I].constructor==String){this.handles[I]=D(this.handles[I],this.element).show()}if(this.elementIsWrapper&&this.originalElement[0].nodeName.match(/textarea|input|select|button/i)){var J=D(this.handles[I],this.element),P=0;P=/sw|ne|nw|se|n|s/.test(I)?J.outerHeight():J.outerWidth();var G=["padding",/ne|nw|n/.test(I)?"Top":/se|sw|s/.test(I)?"Bottom":/^e$/.test(I)?"Right":"Left"].join("");H.css(G,P);this._proportionallyResize()}if(!D(this.handles[I]).length){continue}}};this._renderAxis(this.element);this._handles=D(".ui-resizable-handle",this.element).disableSelection();this._handles.mouseover(function(){if(!K.resizing){if(this.className){var G=this.className.match(/ui-resizable-(se|sw|ne|nw|n|e|s|w)/i)}K.axis=G&&G[1]?G[1]:"se"}});if(M.autoHide){this._handles.hide();D(this.element).addClass("ui-resizable-autohide").hover(function(){D(this).removeClass("ui-resizable-autohide");K._handles.show()},function(){if(!K.resizing){D(this).addClass("ui-resizable-autohide");K._handles.hide()}})}this._mouseInit()},destroy:function(){this._mouseDestroy();var A=function(C){D(C).removeClass("ui-resizable ui-resizable-disabled ui-resizable-resizing").removeData("resizable").unbind(".resizable").find(".ui-resizable-handle").remove()};if(this.elementIsWrapper){A(this.element);var B=this.element;B.parent().append(this.originalElement.css({position:B.css("position"),width:B.outerWidth(),height:B.outerHeight(),top:B.css("top"),left:B.css("left")})).end().remove()}this.originalElement.css("resize",this.originalResizeStyle);A(this.originalElement)},_mouseCapture:function(A){var C=false;for(var B in this.handles){if(D(this.handles[B])[0]==A.target){C=true}}return this.options.disabled||!!C},_mouseStart:function(K){var M=this.options,C=this.element.position(),N=this.element;this.resizing=true;this.documentScroll={top:D(document).scrollTop(),left:D(document).scrollLeft()};if(N.is(".ui-draggable")||(/absolute/).test(N.css("position"))){N.css({position:"absolute",top:C.top,left:C.left})}if(D.browser.opera&&(/relative/).test(N.css("position"))){N.css({position:"relative",top:"auto",left:"auto"})}this._renderProxy();var L=F(this.helper.css("left")),A=F(this.helper.css("top"));if(M.containment){L+=D(M.containment).scrollLeft()||0;A+=D(M.containment).scrollTop()||0}this.offset=this.helper.offset();this.position={left:L,top:A};this.size=this._helper?{width:N.outerWidth(),height:N.outerHeight()}:{width:N.width(),height:N.height()};this.originalSize=this._helper?{width:N.outerWidth(),height:N.outerHeight()}:{width:N.width(),height:N.height()};this.originalPosition={left:L,top:A};this.sizeDiff={width:N.outerWidth()-N.width(),height:N.outerHeight()-N.height()};this.originalMousePosition={left:K.pageX,top:K.pageY};this.aspectRatio=(typeof M.aspectRatio=="number")?M.aspectRatio:((this.originalSize.width/this.originalSize.height)||1);var B=D(".ui-resizable-"+this.axis).css("cursor");D("body").css("cursor",B=="auto"?this.axis+"-resize":B);N.addClass("ui-resizable-resizing");this._propagate("start",K);return true},_mouseDrag:function(Q){var T=this.helper,C=this.options,B={},Y=this,Z=this.originalMousePosition,R=this.axis;var W=(Q.pageX-Z.left)||0,X=(Q.pageY-Z.top)||0;var A=this._change[R];if(!A){return false}var S=A.apply(this,[Q,W,X]),V=D.browser.msie&&D.browser.version<7,U=this.sizeDiff;if(this._aspectRatio||Q.shiftKey){S=this._updateRatio(S,Q)}S=this._respectSize(S,Q);this._propagate("resize",Q);T.css({top:this.position.top+"px",left:this.position.left+"px",width:this.size.width+"px",height:this.size.height+"px"});if(!this._helper&&this._proportionallyResizeElements.length){this._proportionallyResize()}this._updateCache(S);this._trigger("resize",Q,this.ui());return false},_mouseStop:function(O){this.resizing=false;var N=this.options,T=this;if(this._helper){var R=this._proportionallyResizeElements,P=R.length&&(/textarea/i).test(R[0].nodeName),B=P&&D.ui.hasScroll(R[0],"left")?0:T.sizeDiff.height,Q=P?0:T.sizeDiff.width;var S={width:(T.size.width-Q),height:(T.size.height-B)},C=(parseInt(T.element.css("left"),10)+(T.position.left-T.originalPosition.left))||null,A=(parseInt(T.element.css("top"),10)+(T.position.top-T.originalPosition.top))||null;if(!N.animate){this.element.css(D.extend(S,{top:A,left:C}))}T.helper.height(T.size.height);T.helper.width(T.size.width);if(this._helper&&!N.animate){this._proportionallyResize()}}D("body").css("cursor","auto");this.element.removeClass("ui-resizable-resizing");this._propagate("stop",O);if(this._helper){this.helper.remove()}return false},_updateCache:function(B){var A=this.options;this.offset=this.helper.offset();if(E(B.left)){this.position.left=B.left}if(E(B.top)){this.position.top=B.top}if(E(B.height)){this.size.height=B.height}if(E(B.width)){this.size.width=B.width}},_updateRatio:function(J,A){var K=this.options,C=this.position,B=this.size,L=this.axis;if(J.height){J.width=(B.height*this.aspectRatio)}else{if(J.width){J.height=(B.width/this.aspectRatio)}}if(L=="sw"){J.left=C.left+(B.width-J.width);J.top=null}if(L=="nw"){J.top=C.top+(B.height-J.height);J.left=C.left+(B.width-J.width)}return J},_respectSize:function(S,B){var V=this.helper,A=this.options,b=this._aspectRatio||B.shiftKey,C=this.axis,T=E(S.width)&&A.maxWidth&&(A.maxWidth<S.width),a=E(S.height)&&A.maxHeight&&(A.maxHeight<S.height),W=E(S.width)&&A.minWidth&&(A.minWidth>S.width),Z=E(S.height)&&A.minHeight&&(A.minHeight>S.height);if(W){S.width=A.minWidth}if(Z){S.height=A.minHeight}if(T){S.width=A.maxWidth}if(a){S.height=A.maxHeight}var X=this.originalPosition.left+this.originalSize.width,c=this.position.top+this.size.height;var Y=/sw|nw|w/.test(C),U=/nw|ne|n/.test(C);if(W&&Y){S.left=X-A.minWidth}if(T&&Y){S.left=X-A.maxWidth}if(Z&&U){S.top=c-A.minHeight}if(a&&U){S.top=c-A.maxHeight}var d=!S.width&&!S.height;if(d&&!S.left&&S.top){S.top=null}else{if(d&&!S.top&&S.left){S.left=null}}return S},_proportionallyResize:function(){var K=this.options;if(!this._proportionallyResizeElements.length){return}var C=this.helper||this.element;for(var L=0;L<this._proportionallyResizeElements.length;L++){var J=this._proportionallyResizeElements[L];if(!this.borderDif){var A=[J.css("borderTopWidth"),J.css("borderRightWidth"),J.css("borderBottomWidth"),J.css("borderLeftWidth")],B=[J.css("paddingTop"),J.css("paddingRight"),J.css("paddingBottom"),J.css("paddingLeft")];this.borderDif=D.map(A,function(N,H){var G=parseInt(N,10)||0,I=parseInt(B[H],10)||0;return G+I})}if(D.browser.msie&&!(!(D(C).is(":hidden")||D(C).parents(":hidden").length))){continue}J.css({height:(C.height()-this.borderDif[0]-this.borderDif[2])||0,width:(C.width()-this.borderDif[1]-this.borderDif[3])||0})}},_renderProxy:function(){var J=this.element,I=this.options;this.elementOffset=J.offset();if(this._helper){this.helper=this.helper||D('<div style="overflow:hidden;"></div>');var B=D.browser.msie&&D.browser.version<7,C=(B?1:0),A=(B?2:-1);this.helper.addClass(this._helper).css({width:this.element.outerWidth()+A,height:this.element.outerHeight()+A,position:"absolute",left:this.elementOffset.left-C+"px",top:this.elementOffset.top-C+"px",zIndex:++I.zIndex});this.helper.appendTo("body").disableSelection()}else{this.helper=this.element}},_change:{e:function(A,C,B){return{width:this.originalSize.width+C}},w:function(L,J,A){var K=this.options,C=this.originalSize,B=this.originalPosition;return{left:B.left+J,width:C.width-J}},n:function(L,J,A){var K=this.options,C=this.originalSize,B=this.originalPosition;return{top:B.top+A,height:C.height-A}},s:function(A,C,B){return{height:this.originalSize.height+B}},se:function(A,C,B){return D.extend(this._change.s.apply(this,arguments),this._change.e.apply(this,[A,C,B]))},sw:function(A,C,B){return D.extend(this._change.s.apply(this,arguments),this._change.w.apply(this,[A,C,B]))},ne:function(A,C,B){return D.extend(this._change.n.apply(this,arguments),this._change.e.apply(this,[A,C,B]))},nw:function(A,C,B){return D.extend(this._change.n.apply(this,arguments),this._change.w.apply(this,[A,C,B]))}},_propagate:function(A,B){D.ui.plugin.call(this,A,[B,this.ui()]);(A!="resize"&&this._trigger(A,B,this.ui()))},plugins:{},ui:function(){return{originalElement:this.originalElement,element:this.element,helper:this.helper,position:this.position,size:this.size,originalSize:this.originalSize,originalPosition:this.originalPosition}}}));D.extend(D.ui.resizable,{version:"1.7.1",eventPrefix:"resize",defaults:{alsoResize:false,animate:false,animateDuration:"slow",animateEasing:"swing",aspectRatio:false,autoHide:false,cancel:":input,option",containment:false,delay:0,distance:1,ghost:false,grid:false,handles:"e,s,se",helper:false,maxHeight:null,maxWidth:null,minHeight:10,minWidth:10,zIndex:1000}});D.ui.plugin.add("resizable","alsoResize",{start:function(H,C){var A=D(this).data("resizable"),B=A.options;_store=function(G){D(G).each(function(){D(this).data("resizable-alsoresize",{width:parseInt(D(this).width(),10),height:parseInt(D(this).height(),10),left:parseInt(D(this).css("left"),10),top:parseInt(D(this).css("top"),10)})})};if(typeof(B.alsoResize)=="object"&&!B.alsoResize.parentNode){if(B.alsoResize.length){B.alsoResize=B.alsoResize[0];_store(B.alsoResize)}else{D.each(B.alsoResize,function(G,J){_store(G)})}}else{_store(B.alsoResize)}},resize:function(C,N){var P=D(this).data("resizable"),B=P.options,O=P.originalSize,M=P.originalPosition;var A={height:(P.size.height-O.height)||0,width:(P.size.width-O.width)||0,top:(P.position.top-M.top)||0,left:(P.position.left-M.left)||0},L=function(G,H){D(G).each(function(){var K=D(this),R=D(this).data("resizable-alsoresize"),I={},J=H&&H.length?H:["width","height","top","left"];D.each(J||["width","height","top","left"],function(Q,V){var U=(R[V]||0)+(A[V]||0);if(U&&U>=0){I[V]=U||null}});if(/relative/.test(K.css("position"))&&D.browser.opera){P._revertToRelativePosition=true;K.css({position:"absolute",top:"auto",left:"auto"})}K.css(I)})};if(typeof(B.alsoResize)=="object"&&!B.alsoResize.nodeType){D.each(B.alsoResize,function(G,H){L(G,H)})}else{L(B.alsoResize)}},stop:function(B,A){var C=D(this).data("resizable");if(C._revertToRelativePosition&&D.browser.opera){C._revertToRelativePosition=false;el.css({position:"relative"})}D(this).removeData("resizable-alsoresize-start")}});D.ui.plugin.add("resizable","animate",{stop:function(P,S){var V=D(this).data("resizable"),O=V.options;var T=V._proportionallyResizeElements,Q=T.length&&(/textarea/i).test(T[0].nodeName),B=Q&&D.ui.hasScroll(T[0],"left")?0:V.sizeDiff.height,R=Q?0:V.sizeDiff.width;var U={width:(V.size.width-R),height:(V.size.height-B)},C=(parseInt(V.element.css("left"),10)+(V.position.left-V.originalPosition.left))||null,A=(parseInt(V.element.css("top"),10)+(V.position.top-V.originalPosition.top))||null;V.element.animate(D.extend(U,A&&C?{top:A,left:C}:{}),{duration:O.animateDuration,easing:O.animateEasing,step:function(){var G={width:parseInt(V.element.css("width"),10),height:parseInt(V.element.css("height"),10),top:parseInt(V.element.css("top"),10),left:parseInt(V.element.css("left"),10)};if(T&&T.length){D(T[0]).css({width:G.width,height:G.height})}V._updateCache(G);V._propagate("resize",P)}})}});D.ui.plugin.add("resizable","containment",{start:function(b,X){var S=D(this).data("resizable"),C=S.options,U=S.element;var R=C.containment,a=(R instanceof D)?R.get(0):(/parent/.test(R))?U.parent().get(0):R;if(!a){return}S.containerElement=D(a);if(/document/.test(R)||R==document){S.containerOffset={left:0,top:0};S.containerPosition={left:0,top:0};S.parentData={element:D(document),left:0,top:0,width:D(document).width(),height:D(document).height()||document.body.parentNode.scrollHeight}}else{var B=D(a),Y=[];D(["Top","Right","Left","Bottom"]).each(function(H,G){Y[H]=F(B.css("padding"+G))});S.containerOffset=B.offset();S.containerPosition=B.position();S.containerSize={height:(B.innerHeight()-Y[3]),width:(B.innerWidth()-Y[1])};var W=S.containerOffset,Z=S.containerSize.height,T=S.containerSize.width,A=(D.ui.hasScroll(a,"left")?a.scrollWidth:T),V=(D.ui.hasScroll(a)?a.scrollHeight:Z);S.parentData={element:a,left:W.left,top:W.top,width:A,height:V}}},resize:function(V,Z){var T=D(this).data("resizable"),d=T.options,A=T.containerSize,Y=T.containerOffset,S=T.size,a=T.position,c=T._aspectRatio||V.shiftKey,U={top:0,left:0},C=T.containerElement;if(C[0]!=document&&(/static/).test(C.css("position"))){U=Y}if(a.left<(T._helper?Y.left:0)){T.size.width=T.size.width+(T._helper?(T.position.left-Y.left):(T.position.left-U.left));if(c){T.size.height=T.size.width/d.aspectRatio}T.position.left=d.helper?Y.left:0}if(a.top<(T._helper?Y.top:0)){T.size.height=T.size.height+(T._helper?(T.position.top-Y.top):T.position.top);if(c){T.size.width=T.size.height*d.aspectRatio}T.position.top=T._helper?Y.top:0}T.offset.left=T.parentData.left+T.position.left;T.offset.top=T.parentData.top+T.position.top;var X=Math.abs((T._helper?T.offset.left-U.left:(T.offset.left-U.left))+T.sizeDiff.width),B=Math.abs((T._helper?T.offset.top-U.top:(T.offset.top-Y.top))+T.sizeDiff.height);var b=T.containerElement.get(0)==T.element.parent().get(0),W=/relative|absolute/.test(T.containerElement.css("position"));if(b&&W){X-=T.parentData.left}if(X+T.size.width>=T.parentData.width){T.size.width=T.parentData.width-X;if(c){T.size.height=T.size.width/T.aspectRatio}}if(B+T.size.height>=T.parentData.height){T.size.height=T.parentData.height-B;if(c){T.size.width=T.size.height*T.aspectRatio}}},stop:function(Q,S){var V=D(this).data("resizable"),P=V.options,T=V.position,R=V.containerOffset,U=V.containerPosition,C=V.containerElement;var B=D(V.helper),A=B.offset(),W=B.outerWidth()-V.sizeDiff.width,X=B.outerHeight()-V.sizeDiff.height;if(V._helper&&!P.animate&&(/relative/).test(C.css("position"))){D(this).css({left:A.left-U.left-R.left,width:W,height:X})}if(V._helper&&!P.animate&&(/static/).test(C.css("position"))){D(this).css({left:A.left-U.left-R.left,width:W,height:X})}}});D.ui.plugin.add("resizable","ghost",{start:function(J,I){var A=D(this).data("resizable"),C=A.options,B=A.size;A.ghost=A.originalElement.clone();A.ghost.css({opacity:0.25,display:"block",position:"relative",height:B.height,width:B.width,margin:0,left:0,top:0}).addClass("ui-resizable-ghost").addClass(typeof C.ghost=="string"?C.ghost:"");A.ghost.appendTo(A.helper)},resize:function(H,C){var A=D(this).data("resizable"),B=A.options;if(A.ghost){A.ghost.css({position:"relative",height:A.size.height,width:A.size.width})}},stop:function(H,C){var A=D(this).data("resizable"),B=A.options;if(A.ghost&&A.helper){A.helper.get(0).removeChild(A.ghost.get(0))}}});D.ui.plugin.add("resizable","grid",{resize:function(C,Q){var V=D(this).data("resizable"),B=V.options,U=V.size,S=V.originalSize,P=V.originalPosition,O=V.axis,R=B._aspectRatio||C.shiftKey;B.grid=typeof B.grid=="number"?[B.grid,B.grid]:B.grid;var A=Math.round((U.width-S.width)/(B.grid[0]||1))*(B.grid[0]||1),T=Math.round((U.height-S.height)/(B.grid[1]||1))*(B.grid[1]||1);if(/^(se|s|e)$/.test(O)){V.size.width=S.width+A;V.size.height=S.height+T}else{if(/^(ne)$/.test(O)){V.size.width=S.width+A;V.size.height=S.height+T;V.position.top=P.top-T}else{if(/^(sw)$/.test(O)){V.size.width=S.width+A;V.size.height=S.height+T;V.position.left=P.left-A}else{V.size.width=S.width+A;V.size.height=S.height+T;V.position.top=P.top-T;V.position.left=P.left-A}}}}});var F=function(A){return parseInt(A,10)||0};var E=function(A){return !isNaN(parseInt(A,10))}})(jQuery);