/* places the results of an ajax call either in the innerHTML of a target dom object or * call a user defined function optionally passing parameters. * */ function ajaxCallback() { var serverData=arguments[0]; var status= arguments[1]; // these two are a given var obj=null; var parameters=null; if(arguments.length>2)obj=arguments[2]; // either a proc or an object if(arguments.length>3) parameters =arguments[3]; // if we were passed a callback function then use it if (Object.prototype.toString.call(obj) == "[object Function]") { if(parameters){ obj(serverData, parameters); }else{ obj(serverData); }; }else{ //console.log('Object.prototype.toString.call(obj):'+Object.prototype.toString.call(obj) ); // put the results in a div if(Object.prototype.toString.call(obj)=='[object String]'){ document.getElementById(obj).innerHTML=serverData; }else{ obj.innerHTML=serverData; } }; } /* can be called with a variable number of params. * * either: * ajaxPage(url,userSpecifiedCallbackfuntion | domObject{as an object or the string representing the id}) - the domObjects innerHTML will be set to the result of an ajax call * * or * ajaxPage(url,userSpoecifiedCallbackfuntion,parameterObject) - as above exept the parameter object is passed to the callbackFunction * * */ function ajaxPage(){ /* * for (var i = 0; i < arguments.length; i++) { alert(arguments[i]); } */ var page=arguments[0]; var targetId=arguments[1]; var params=null; if(arguments.length==3)params=arguments[2]; var AJAX = Xhr(); if (AJAX==null) { alert("Your browser doesn't support AJAX."); return false; } AJAX.onreadystatechange = function() { if (AJAX.readyState==4 || AJAX.readyState=="complete") { if(!params){ ajaxCallback(AJAX.responseText, AJAX.status,targetId); }else if(params){ // deal with an extra parameter to the function passed as target // id ajaxCallback(AJAX.responseText, AJAX.status,targetId,params); } } } //console.log(page); //AJAX.open("POST","/",true); //AJAX.setRequestHeader("Content-type","application/x-www-form-urlencoded"); //AJAX.send(page); AJAX.open("GET", page, true); AJAX.send(null); } //function used by the quick reply inline editor to update the db function quickReplyCallBack(serverData,id){ document.getElementById('QRE'+id).innerHTML=serverData; /*document.getElementById('QREX'+id).onkeyup = function(evt) { evt = evt || window.event; while($(this).outerHeight() < this.scrollHeight + parseFloat($(this).css("borderTopWidth")) + parseFloat($(this).css("borderBottomWidth"))) { $(this).height($(this).height()+1); }; };*/ } //function used by the quick reply inline editor to update the db function quickReply(itemNumber,forumid,threadid,postid){ if(document.getElementById('QRED'+itemNumber)){ document.getElementById('QRED'+itemNumber).innerHTML=''; } var newDiv=document.getElementById('QRE'+itemNumber); if(newDiv){ newDiv.parentNode.removeChild(newDiv); return; } newDiv=document.createElement('div'); newDiv.id='QRE'+itemNumber; addClass(newDiv,'quickReply'); insertAfter(newDiv,document.getElementById('QR'+itemNumber)); newDiv=$('QRE'+itemNumber); ajaxPage("/?page=mz.edit.quick2&fi="+forumid+'&ti='+threadid+'&pi='+postid+'&id='+ itemNumber, quickReplyCallBack ,itemNumber); } function addClass(element, classToAdd) { var currentClassValue = element.className; if (currentClassValue.indexOf(classToAdd) == -1) { if ((currentClassValue == null) || (currentClassValue === "")) { element.className = classToAdd; } else { element.className += " " + classToAdd; }; }; } function insertAfter(newElement,targetElement) { //target is what you want it to go after. Look for this elements parent. var parent = targetElement.parentNode; //if the parents lastchild is the targetElement... if(parent.lastchild == targetElement) { //add the newElement after the target element. parent.appendChild(newElement); } else { // else the target has siblings, insert the new element between the target and it's next sibling. parent.insertBefore(newElement, targetElement.nextSibling); }; } function Xhr(){ /* returns cross-browser XMLHttpRequest, or null if unable */ try { return new XMLHttpRequest(); }catch(e){} try { return new ActiveXObject("Msxml3.XMLHTTP"); }catch(e){} try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); }catch(e){} try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); }catch(e){} try { return new ActiveXObject("Msxml2.XMLHTTP"); }catch(e){} try { return new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){} return null; }