/** * Inline editor feature for RightJS * http://rightjs.org/ui/in-edit * * Copyright (C) 2009-2010 Nikolay Nemshilov */ var InEdit=RightJS.InEdit=function(g,b){var h=b.$,m=b.$w,n=b.Xhr,o=b.Object,j=b.Element,k=b.Input,p=new b.Class(b.Element,{initialize:function(a){this.$super("div",{"class":"rui-spinner"});this.dots=[];for(var d=0;d<(a||4);d++)this.dots.push(new b.Element("div"));this.dots[0].addClass("glowing");this.insert(this.dots);b(this.shift).bind(this).periodical(300)},shift:function(){if(this.visible()){var a=this.dots.pop();this.dots.unshift(a);this.insert(a,"top")}}}),e=new (function(a,d){if(!d){d=a;a="DIV"}var f= new b.Class(b.Element.Wrappers[a]||b.Element,{initialize:function(i,c){this.key=i;var l=[{"class":"rui-"+i}];this instanceof b.Input||this instanceof b.Form||l.unshift(a);this.$super.apply(this,l);if(b.isString(c))c=b.$(c);if(c instanceof b.Element){this._=c._;if("$listeners"in c)c.$listeners=c.$listeners;c={}}this.setOptions(c,this);return b.Wrapper.Cache[b.$uid(this._)]=this},setOptions:function(i,c){c=c||this;b.Options.setOptions.call(this,b.Object.merge(i,eval("("+(c.get("data-"+this.key)||"{}")+ ")")));return this}});f=new b.Class(f,d);b.Observer.createShortcuts(f.prototype,f.EVENTS||[]);return f})("FORM",{extend:{version:"2.2.0",EVENTS:m("show hide send update"),Options:{url:null,name:"text",method:"put",type:"text",toggle:null,update:true,Xhr:{}},i18n:{Save:"Save",Cancel:"Cancel"},current:null},initialize:function(a,d){this.element=h(a);this.$super("in-edit",d).set("action",this.options.url).insert([this.field=new k({type:this.options.type,name:this.options.name,"class":"field"}),this.spinner= new p(4),this.submit=new k({type:"submit","class":"submit",value:e.i18n.Save}),this.cancel=new j("a",{"class":"cancel",href:"#",html:e.i18n.Cancel})]).onClick(this.clicked).onSubmit(this.send)},show:function(){if(e.current!==this){e.current&&e.current.hide();this.oldContent=this.element.html();b(["file","password"]).include(this.options.type)||this.field.setValue(this.oldContent);this.element.update(this);this.spinner.hide();this.submit.show();this.options.toggle&&h(this.options.toggle).hide()}this.options.type!== "file"&&this.field.focus();e.current=this;return this.fire("show")},hide:function(){this.element._.innerHTML=this.oldContent;this.xhr&&this.xhr.cancel();return this.finish()},send:function(a){a&&a.stop();this.spinner.show().resize(this.submit.size());this.submit.hide();this.xhr=(new n(this.options.url,o.merge(this.options.Xhr,{method:this.options.method,spinner:this.spinner,onComplete:b(this.receive).bind(this)}))).send(this);return this.fire("send")},finish:function(){this.options.toggle&&h(this.options.toggle).show(); e.current=null;return this.fire("hide")},receive:function(){if(this.options.update){this.element.update(this.xhr.text);this.fire("update")}this.xhr=null;this.finish()},clicked:function(a){if(a.target===this.cancel){a.stop();this.hide()}}});h(g).onKeydown(function(a){a.keyCode===27&&e.current&&e.current.hide()});j.include({inEdit:function(a){return(new e(this,a)).show()}});(function(){var a=g.createElement("style"),d=g.createTextNode("div.rui-spinner,div.rui-spinner div{margin:0;padding:0;border:none;background:none;list-style:none;font-weight:normal;float:none;display:inline-block; *display:inline; *zoom:1;border-radius:.12em;-moz-border-radius:.12em;-webkit-border-radius:.12em}div.rui-spinner{text-align:center;white-space:nowrap;background:#EEE;border:1px solid #DDD;height:1.2em;padding:0 .2em}div.rui-spinner div{width:.4em;height:70%;background:#BBB;margin-left:1px}div.rui-spinner div:first-child{margin-left:0}div.rui-spinner div.glowing{background:#777}form.rui-in-edit,form.rui-in-edit .cancel{margin:0;padding:0;float:none;position:static}form.rui-in-edit{display:inline-block; *display:inline; *zoom:1;border:none;background:none}form.rui-in-edit div.rui-spinner{margin-right:.2em}form.rui-in-edit div.rui-spinner div{margin-top:.2em}form.rui-in-edit textarea.field{width:100%;margin-bottom:.5em}form.rui-in-edit .field,form.rui-in-edit .submit{margin-right:.2em}form.rui-in-edit,form.rui-in-edit .field,form.rui-in-edit .submit,form.rui-in-edit div.rui-spinner,form.rui-in-edit .cancel{vertical-align:middle}"); a.type="text/css";if(a.styleSheet)a.styleSheet.cssText=d.nodeValue;else a.appendChild(d);g.getElementsByTagName("head")[0].appendChild(a)})();return e}(document,RightJS);