function saveTextBoxChanges(e,inputObj) { if(!inputObj && this)inputObj = this; // alert("Save" + (e.toSource()) + (inputObj.toSource())); if(document.all)e = event; if(e.keyCode && e.keyCode==27){ cancelRename(e,inputObj); return; } inputObj.style.display='none'; inputObj.nextSibling.style.display='inline'; // empty class of element - it signalised that this element already // edited(and don't need to highlight it with red color) inputObj.nextSibling.setAttribute("class", ""); if(inputObj.value.length>0){ inputObj.nextSibling.innerHTML = inputObj.value; } } function cancelRename(e,inputObj) { if(!inputObj && this)inputObj = this; inputObj.style.display = 'none'; inputObj.nextSibling.style.display = 'inline'; } function renameCheckKeyCode(e) { if(document.all)e = event; if(e.keyCode==13){ // Enter pressed saveTextBoxChanges(false,this); } if(e.keyCode==27){ // ESC pressed cancelRename(false,this); } } function stripHtml(s) { return s.replace(/[\s]+$/g,'').replace(/^[\s]+/g,'').replace(/( )+/g,''); } function createTextBox(obj) { var textBox = document.createElement('INPUT'); textBox.className = 'tableTextBox'; textBox.style.width="100%"; textBox.value = stripHtml(obj.innerHTML); obj.parentNode.insertBefore(textBox,obj); textBox.id = 'textBox' + obj.parentNode.id.replace(/[^0-9]/gi,''); textBox.onblur = saveTextBoxChanges; textBox.onkeydown = renameCheckKeyCode; renameEnableTextBox(obj); } function renameEnableTextBox(obj) { obj.style.display = 'none'; obj.previousSibling.value = stripHtml(obj.innerHTML); obj.previousSibling.style.display = 'inline'; obj.previousSibling.select(); obj.previousSibling.focus(); } function renameItem(obj2) { if(!obj2.previousSibling || obj2.previousSibling.tagName.toLowerCase()!='input'){ createTextBox(obj2); }else{ renameEnableTextBox(obj2); } }