/** * Resizable unit for RightJS * http://rightjs.org/ui/resizable * * Copyright (C) 2010 Nikolay Nemshilov */ var Resizable=RightJS.Resizable=function(r,c){var k=c.$,l=c.$w,m=c.$E,t=c.Wrapper,s=c.Element,g=new (function(a,b){if(!b){b=a;a="DIV"}var f=new c.Wrapper(c.Element.Wrappers[a]||c.Element,{initialize:function(h,d){this.key=h;var e=[{"class":"rui-"+h}];this instanceof c.Input||this instanceof c.Form||e.unshift(a);this.$super.apply(this,e);if(c.isString(d))d=c.$(d);if(d instanceof c.Element){this._=d._;if("$listeners"in d)d.$listeners=d.$listeners;d={}}this.setOptions(d,this);return this},setOptions:function(h, d){d=d||this;c.Options.setOptions.call(this,c.Object.merge(h,eval("("+(d.get("data-"+this.key)||"{}")+")")));return this}});f=new c.Wrapper(f,b);c.Observer.createShortcuts(f.prototype,f.EVENTS||[]);return f})({extend:{version:"2.0.0",EVENTS:l("resize start release"),Options:{direction:null,minWidth:null,maxWidth:null,minHeight:null,maxHeight:null}},initialize:function(a,b){this.$super("resizable",this.old_inst=k(a)).setOptions(b);this.options.direction?this.addClass("rui-resizable-"+this.options.direction): this.addClass("rui-resizable");this.content=this.first(".rui-resizable-content")||m("div",{"class":"rui-resizable-content"}).insert(this._.childNodes).insertTo(this);this.handle=this.first(".rui-resizable-handle")||m("div",{"class":"rui-resizable-handle"}).insertTo(this)},destroy:function(){this.removeClass("rui-resizable").removeClass("rui-resizable-top").removeClass("rui-resizable-left").removeClass("rui-resizable-right").removeClass("rui-resizable-bottom").insert(this.content._.childNodes);this.content.remove(); this.handle.remove();if(this.old_inst)t.Cache[$uid(this._)]=this.old_inst;return this},setOptions:function(a,b){a=a||{};l("top left right bottom").each(function(f){if(this.hasClass("rui-resizable-"+f))a.direction=f},this);return this.$super(a,b)},start:function(a){this.prevSizes=this.size();this.prevEvPos=a.position();this.contXDiff=this.size().x-this.content.size().x;this.contYDiff=this.size().y-this.content.size().y;l("minWidth maxWidth minHeight maxHeight").each(function(b){this[b]=this.findDim(b)}, this);return this.fire("start",a)},track:function(a){var b=a.position(),f=this.prevEvPos,h=this.handle.dimensions(),d=this.prevSizes,e=d.x,i=d.y,u=f.y-b.y,n=this.minWidth,o=this.maxWidth,p=this.minHeight,q=this.maxHeight,j=this.options.direction;e+=(j==="left"?1:-1)*(f.x-b.x);i+=(j==="top"?1:-1)*u;if(eo)e=o;if(iq)i=q;d.x!==e&&j!=="top"&&j!=="bottom"&&this.setWidth(e);d.y!==i&&j!=="left"&&j!=="right"&&this.setHeight(i);if(e==n||e==o)b.x=h.left+h.width/2;if(i==p||i==q)b.y=h.top+ h.height/2;this.prevEvPos=b;this.prevSizes=this.size();this.fire("resize",a)},setWidth:function(a){this.content.setWidth(a-this.contXDiff);return this.$super(a)},setHeight:function(a){this.content.setHeight(a-this.contYDiff);return this.$super(a)},release:function(a){return this.fire("release",a)},fire:function(a,b){return this.$super(a,this,b)},findDim:function(a){var b=this.options[a]||this.getStyle(a);if(b&&/\d+/.test(b)&&parseFloat(b)>0){a=c(a).include("Width")?"width":"height";b=(this._dummy|| (this._dummy=m("div",{style:"visibility:hidden;z-index:-1"}))).setStyle(a,b).insertTo(this,"before");a=b._["offset"+c(a).capitalize()];b.remove();return a}}});k(r).on({mousedown:function(a){var b=a.find(".rui-resizable-handle");if(b){b=b.parent();if(b instanceof s)b=new g(b);g.current=b.start(a.stop())}},mousemove:function(a){var b=g.current;b&&b.track(a)},mouseup:function(a){var b=g.current;if(b){b.release(a);g.current=null}}});k(window).onBlur(function(a){var b=g.current;if(b){b.release(a);g.current= null}});s.include({makeResizable:function(a){new g(this,a);return this},undoResizable:function(){this instanceof g&&this.destroy();return this}});r.write(''); return g}(document,RightJS);