(function(){YAHOO.widget.EditableElement=function(){var Dom=YAHOO.util.Dom,YU=YAHOO.util;this.config={class_name:"editable",trigger:"click",input_type:"text",save_on_enter:true,clear_on_escape:true,linebreak:false,save_button:true,cancel_button:true,textarea_rows:6,textarea_cols:50};this.clicked=undefined;this.contents=undefined;this.input=undefined;this.init=function(){_items=Dom.getElementsByClassName(this.config.class_name);if(_items.length>0){for(i=0;i<_items.length;i++){this.elID=YU.Dom.generateId(_items[i]);YU.Event.addListener(_items[i],this.config.trigger,this.triggered,this,true);if(this.config.save_on_enter||this.config.clear_on_escape){var status=YU.Event.addListener(_items[i],"keyup",this.onKeyUp,this,true)}}}};this._max=function(x,y){if(x>y){return x}return y};this.step_up=function(el){if(el){var tmpEl=el;while(tmpEl.className!=this.config.class_name){tmpEl=tmpEl.parentNode}if(tmpEl){el=tmpEl}}return el};this.triggered=function(ev){if(!this.check()){return }this.clicked=YU.Event.getTarget(ev);this.clicked=this.step_up(this.clicked);this.contents=this.clicked.innerHTML;this.create_input_field()};this.onKeyUp=function(p_oEvent){var keyCode=YU.Event.getCharCode(p_oEvent);switch(keyCode){case 13:if(this.config.save_on_enter){this.check(p_oEvent)}break;case 27:if(this.config.save_on_enter){this.reset_input_field()}break;default:break}};this.create_input_field=function(){this.input=YU.Dom.generateId();if(this.config.input_type=="text"){new_input=document.createElement("input");min_size=this._max(this.contents.length,this.config.min_size);with(new_input){setAttribute("type","text");setAttribute("id",this.input);value=this.contents;setAttribute("size",min_size);className="editable_input"}}else{if(this.config.input_type=="textarea"){new_input=document.createElement("textarea");with(new_input){setAttribute("id",this.input);value=this.contents;className="editable_input";setAttribute("rows",this.config.textarea_rows);setAttribute("cols",this.config.textarea_cols)}}}this.clicked.innerHTML="";this.clicked.appendChild(new_input);if(this.config.linebreak){newline=document.createElement("br");this.clicked.appendChild(newline)}if(this.config.save_button){this.create_save_button()}if(this.config.cancel_button){this.create_cancel_button()}new_input.select()};this.create_save_button=function(){this.save_input=YU.Dom.generateId();new_save_input=document.createElement("input");with(new_save_input){setAttribute("type","button");setAttribute("id",this.save_input);value="Save";className="editable_input"}this.clicked.appendChild(new_save_input);YU.Event.addListener(new_save_input,"click",this.check,this,true)};this.create_cancel_button=function(){this.cancel_input=YU.Dom.generateId();new_cancel_input=document.createElement("input");with(new_cancel_input){setAttribute("type","button");setAttribute("id",this.cancel_input);value="Cancel";className="editable_input"}this.clicked.appendChild(new_cancel_input);YU.Event.addListener(new_cancel_input,"click",this.reset_input_field,this,true)};this.reset_input_field=function(){this.clicked.innerHTML=this.contents;this.clicked=undefined;this.contents=undefined;this.input=undefined};this.clear_input=function(){if(this.input){var input_value=YU.Dom.get(this.input).value;if(input_value.length>0){this.clean_input();this.contents_new=input_value}else{this.contents_new="[removed]"}this.clicked.innerHTML=this.contents_new;if(this.contents_new!=this.contents){var el=this.step_up(this.clicked);this.callback(el)}}this.clicked=undefined;this.contents=undefined;this.input=undefined};this.clean_input=function(){checkText=new String(YU.Dom.get(this.input).value);regEx1=/\"/g;checkText=String(checkText.replace(regEx1,""));YU.Dom.get(this.input).value=checkText};this.check=function(ev){if(!ev){if(this.clicked==undefined){return true}return false}if(this.clicked){clicked=YU.Event.getTarget(ev);this.clear_input();return true}};this.callback=function(){alert("default callback() called")}}})();