// X-Mode AJAX Core "Yume" 2.0 // Compatible with X-Mode 3 "Yotsuba" and any other external apps. // Originally developed by Dave Crane, Eric Pascarello and Darren James // Developed by Juti Noppornpitak var net = new Object(); net.READY_STATE_UNINITIALIZED = 0; net.READY_STATE_LOADING = 1; net.READY_STATE_LOADED = 2; net.READY_STATE_INTERACTIVE = 3; net.READY_STATE_COMPLETE = 4; net.CONNECTION_TERMINATION = "Terminating the connection..."; net.core = function(url, console, onload, loading, onerror, method, data, contentType) { this.url = url; this.currurl = url; this.req = null; this.console = console; this.data = (data) ? data : null; this.contentType = (contentType) ? contentType : null; this.method = (method) ? method : "GET"; this.onload = (onload) ? onload : this.defaultLoad; this.loading = (loading) ? loading : this.defaultLoading; this.onerror = (onerror) ? onerror : this.defaultError; // Require the user to manually start the connection. // this.connect(url); } net.core.prototype = { defaultConnect:function() { this.connect(this.url); }, connect:function(url, method, data, contentType) { // Create the requester if(window.XMLHttpRequest) { // for Mozilla/Safari this.req = new XMLHttpRequest(); } else if(window.ActiveXObject) { // for MSIE this.req = new ActiveXObject("Microsoft.XMLHTTP"); } if(!contentType && method == "POST") { contentType="application/x-www-form-urlencoded"; } this.currurl = url; if(this.req) { try { var loader = this; this.req.onreadystatechange = function() { loader.process.call(loader); } if(!method) { method = "GET"; } if(!data) { data = null; } this.req.open(method, this.currurl, true); if(contentType) { this.req.setRequestHeader("Content-Type", contentType); } this.req.send(data); } catch(err) { this.onerror.call(this); } } }, process:function() { var req = this.req; var status = req.readyState; if(status == net.READY_STATE_COMPLETE) { var httpstatus = req.status; if(httpstatus == 200 || httpstatus == 0) { this.onload.call(this); } else { this.onerror.call(this); } } else { // handling loading/connecting this.loading.call(this); } }, defaultLoad:function() { xcie__setElement(this.console, this.req.responseText); }, defaultError:function() { alert("Error while connecting to: " + this.currurl); }, defaultLoading:function() { xcie__setElement(this.console, "Loading"); } } function xcie__element(id) { return document.getElementById(id); } function xcie__getElement(id) { if(!xcie__element(id)) return; return xcie__element(id).innerHTML; } function xcie__getElementValue(id) { if(!xcie__element(id)) return; return xcie__element(id).value; } function xcie__setElementValue(id, value) { if(!xcie__element(id)) return; xcie__element(id).value = value; } function xcie__setElement(id, value) { if(!xcie__element(id)) return; xcie__element(id).innerHTML = value; } function xcie__setWindowTitle(value) { document.title = value; } function xcie__setClass(id, nc) { xcie__element(id).className = nc; } function xcie__img(src, align, other) { return ""; } function xcie__a(label, value, ajax, other, command) { return "" + label + ""; } function xcie__in(type, name, value, other, cmd) { return ""; } function addslashes(str) { // SRC: Stephen Chapman of About.com str=str.replace(/\\/g,'\\\\'); str=str.replace(/\'/g,'\\\''); str=str.replace(/\"/g,'\\"'); return str; } function stripslashes(str) { // SRC: Stephen Chapman of About.com str=str.replace(/\\'/g,'\''); str=str.replace(/\\"/g,'"'); str=str.replace(/\\\\/g,'\\'); return str; }