/* * * Script by http://www.yvoschaap.com * http://www.yvoschaap.com/instantedit/ * */ /* request channel */ function xhr() {}; xhr.prototype.init = function() { try { this._xh = new XMLHttpRequest(); } catch (e) { var _ie = new Array( 'MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP' ); var success = false; for (var i=0;i < _ie.length && !success; i++) { try { this._xh = new ActiveXObject(_ie[i]); success = true; } catch (e) { } } if ( !success ) { return false; } return true; } } xhr.prototype.wait = function() { state = this._xh.readyState; return (state && (state < 4)); } xhr.prototype.process = function() { if (this._xh.readyState == 4 && this._xh.status == 200) { this.processed = true; } } xhr.prototype.send = function(urlget,data) { if (!this._xh) { this.init(); } if (!this.wait()) { this._xh.open("GET",urlget,false); try { this._xh.send(data) } catch (e) { alert(e); } if (this._xh.readyState == 4 && this._xh.status == 200) { return this._xh.responseText; } else { // fail } } return data; } // var urlBase = "/update.php"; var formVars = ""; var changing = false; function fieldEnter(campo,evt,idfld) { evt = (evt) ? evt : window.event; if (evt.keyCode == 13 && campo.value!="") { elem = document.getElementById( idfld ); remote = new xhr; //nt = remote.send(urlBase + "?fieldname=" +encodeURIComponent(elem.id)+ "&content="+encodeURIComponent(campo.value)+"&"+formVars,""); var fieldName = elem.id; fieldName = fieldName.replace(/\//g, "^^^"); var fieldValue = campo.value; fieldValue = fieldValue.replace(/\//g, "^^^"); nt = remote.send(urlBase+"/"+formVars+"/"+encodeURIComponent(fieldName)+"/"+encodeURIComponent(fieldValue), encodeURIComponent(fieldValue)); //remove glow noLight(elem); elem.innerHTML = nt; changing = false; return false; } else { return true; } } function fieldBlur(campo,idfld) { if (campo.value!="") { elem = document.getElementById( idfld ); remote = new xhr; var fieldName = elem.id; fieldName = fieldName.replace(/\//g, "^^^"); var fieldValue = campo.value; fieldValue = fieldValue.replace(/\//g, "^^^"); //nt = remote.send(urlBase + "?fieldname=" +encodeURIComponent(elem.id)+ "&content="+encodeURIComponent(campo.value)+"&"+formVars,""); nt = remote.send(urlBase+"/"+formVars+"/"+encodeURIComponent(fieldName)+"/"+encodeURIComponent(fieldValue), encodeURIComponent(fieldValue)); elem.innerHTML = nt; changing = false; return false; } } //edit field created function editBox(actual) { //alert(actual.nodeName+' '+changing); if(!changing){ width = widthEl(actual.id) + 20; height =heightEl(actual.id) + 2; if(height < 40){ if(width < 100) width = 150; actual.innerHTML = ""; }else{ if(width < 70) width = 90; if(height < 50) height = 50; actual.innerHTML = ""; } changing = true; } actual.firstChild.focus(); } //find all span tags with class editText and id as fieldname parsed to update script. add onclick function function editbox_init(){ if (!document.getElementsByTagName){ return; } var spans = document.getElementsByTagName("span"); // loop through all span tags for (var i=0; i