/* [supesite] (c) 2007-2009 comsenz inc. $id: ajax.js 13359 2009-09-22 09:06:19z zhaofei $ */ var ajaxs = new array(); var ajaxstacks = new array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0); var ajaxposthandle = 0; var evalscripts = new array(); var ajaxpostresult = 0; function ajax(recvtype, waitid) { for(var stackid = 0; stackid < ajaxstacks.length && ajaxstacks[stackid] != 0; stackid++); ajaxstacks[stackid] = 1; var aj = new object(); aj.loading = 'loading...';//public aj.recvtype = recvtype ? recvtype : 'xml';//public aj.waitid = waitid ? $(waitid) : null;//public aj.resulthandle = null;//private aj.sendstring = '';//private aj.targeturl = '';//private aj.stackid = 0; aj.stackid = stackid; aj.setloading = function(loading) { if(typeof loading !== 'undefined' && loading !== null) aj.loading = loading; } aj.setrecvtype = function(recvtype) { aj.recvtype = recvtype; } aj.setwaitid = function(waitid) { aj.waitid = typeof waitid == 'object' ? waitid : $(waitid); } aj.createxmlhttprequest = function() { var request = false; if(window.xmlhttprequest) { request = new xmlhttprequest(); if(request.overridemimetype) { request.overridemimetype('text/xml'); } } else if(window.activexobject) { var versions = ['microsoft.xmlhttp', 'msxml.xmlhttp', 'microsoft.xmlhttp', 'msxml2.xmlhttp.7.0', 'msxml2.xmlhttp.6.0', 'msxml2.xmlhttp.5.0', 'msxml2.xmlhttp.4.0', 'msxml2.xmlhttp.3.0', 'msxml2.xmlhttp']; for(var i=0; i'; } } aj.processhandle = function() { if(aj.xmlhttprequest.readystate == 4 && aj.xmlhttprequest.status == 200) { for(k in ajaxs) { if(ajaxs[k] == aj.targeturl) { ajaxs[k] = null; } } if(aj.waitid) changedisplay(aj.waitid, 'none'); if(aj.recvtype == 'html') { aj.resulthandle(aj.xmlhttprequest.responsetext, aj); } else if(aj.recvtype == 'xml') { try { aj.resulthandle(aj.xmlhttprequest.responsexml.lastchild.firstchild.nodevalue, aj); } catch(e) { aj.resulthandle('', aj); } } ajaxstacks[aj.stackid] = 0; } } aj.get = function(targeturl, resulthandle) { if(targeturl.indexof('?') != -1) { targeturl = targeturl + '&inajax=1'; } else { targeturl = targeturl + '?inajax=1'; } settimeout(function(){aj.showloading()}, 500); if(in_array(targeturl, ajaxs)) { return false; } else { ajaxs.push(targeturl); } aj.targeturl = targeturl; aj.xmlhttprequest.onreadystatechange = aj.processhandle; aj.resulthandle = resulthandle; var delay = 100; if(window.xmlhttprequest) { settimeout(function(){ aj.xmlhttprequest.open('get', aj.targeturl); aj.xmlhttprequest.send(null);}, delay); } else { settimeout(function(){ aj.xmlhttprequest.open("get", targeturl, true); aj.xmlhttprequest.send();}, delay); } } aj.post = function(targeturl, sendstring, resulthandle) { if(targeturl.indexof('?') != -1) { targeturl = targeturl + '&inajax=1'; } else { targeturl = targeturl + '?inajax=1'; } settimeout(function(){aj.showloading()}, 500); if(in_array(targeturl, ajaxs)) { return false; } else { ajaxs.push(targeturl); } aj.targeturl = targeturl; aj.sendstring = sendstring; aj.xmlhttprequest.onreadystatechange = aj.processhandle; aj.resulthandle = resulthandle; aj.xmlhttprequest.open('post', targeturl); aj.xmlhttprequest.setrequestheader('content-type', 'application/x-www-form-urlencoded'); aj.xmlhttprequest.send(aj.sendstring); } return aj; } function newfunction(func){ var args = new array(); for(var i=1; i]*?>([^\x00]*?)<\/script>/ig; var arr = new array(); while(arr = p.exec(s)) { var p1 = /]*?src=\"([^\>]*?)\"[^\>]*?(reload=\"1\")?(?:charset=\"([\w\-]+?)\")?><\/script>/i; var arr1 = new array(); arr1 = p1.exec(arr[0]); if(arr1) { appendscript(arr1[1], '', arr1[2], arr1[3]); } else { p1 = /([^\x00]+?)<\/script>/i; arr1 = p1.exec(arr[0]); //获取字符集 var re = /charset=\"([\w\-]+?)\"/i; var charsetarr = re.exec(arr1[1]); //appendscript('', arr1[2], arr1[1].indexof('reload=') != -1, charsetarr[1]); } } return s; } function appendscript(src, text, reload, charset) { var id = hash(src + text); if(!reload && in_array(id, evalscripts)) return; if(reload && $(id)) { $(id).parentnode.removechild($(id)); } evalscripts.push(id); var scriptnode = document.createelement("script"); scriptnode.type = "text/javascript"; scriptnode.id = id; scriptnode.charset = charset; try { if(src) { scriptnode.src = src; } else if(text){ scriptnode.text = text; } $('append_parent').appendchild(scriptnode); } catch(e) {} } function stripscript(s) { return s.replace(/.*?<\/script>/ig, ''); } function ajaxupdateevents(obj, tagname) { tagname = tagname ? tagname : 'a'; var objs = obj.getelementsbytagname(tagname); for(k in objs) { var o = objs[k]; ajaxupdateevent(o); } } function ajaxupdateevent(o) { if(typeof o == 'object' && o.getattribute) { if(o.getattribute('ajaxtarget')) { if(!o.id) o.id = math.random(); var ajaxevent = o.getattribute('ajaxevent') ? o.getattribute('ajaxevent') : 'click'; var ajaxurl = o.getattribute('ajaxurl') ? o.getattribute('ajaxurl') : o.href; _attachevent(o, ajaxevent, newfunction('ajaxget', ajaxurl, o.getattribute('ajaxtarget'), o.getattribute('ajaxwaitid'), o.getattribute('ajaxloading'), o.getattribute('ajaxdisplay'))); if(o.getattribute('ajaxfunc')) { o.getattribute('ajaxfunc').match(/(\w+)\((.+?)\)/); _attachevent(o, ajaxevent, newfunction(regexp.$1, regexp.$2)); } } } } function ajaxget(url, showid, waitid, loading, display, recall) { waitid = typeof waitid == 'undefined' || waitid === null ? showid : waitid; var x = new ajax(); x.setloading(loading); x.setwaitid(waitid); x.display = typeof display == 'undefined' || display == null ? '' : display; x.showid = $(showid); if(x.showid) x.showid.orgdisplay = typeof x.showid.orgdisplay === 'undefined' ? x.showid.style.display : x.showid.orgdisplay; if(url.substr(strlen(url) - 1) == '#') { url = url.substr(0, strlen(url) - 1); x.autogoto = 1; } var url = url + '&inajax=1&ajaxtarget=' + showid; x.get(url, function(s, x) { evaled = false; if(s.indexof('ajaxerror') != -1) { evalscript(s); evaled = true; } if(!evaled && (typeof ajaxerror == 'undefined' || !ajaxerror)) { if(x.showid) { changedisplay(x.showid, x.showid.orgdisplay); changedisplay(x.showid, x.display); x.showid.orgdisplay = x.showid.style.display; ajaxinnerhtml(x.showid, s); ajaxupdateevents(x.showid); if(x.autogoto) scroll(0, x.showid.offsettop); } } if(!evaled)evalscript(s); ajaxerror = null; if(recall) {eval(recall);} }); } function ajaxpost(formid, func, parameter) { showloading(); if(ajaxposthandle != 0) { return false; } var ajaxframeid = 'ajaxframe'; var ajaxframe = $(ajaxframeid); if(ajaxframe == null) { if (is_ie && !is_opera) { ajaxframe = document.createelement(""); } else { ajaxframe = document.createelement("iframe"); ajaxframe.name = ajaxframeid; ajaxframe.id = ajaxframeid; } ajaxframe.style.display = 'none'; $('append_parent').appendchild(ajaxframe); } $(formid).target = ajaxframeid; $(formid).action = $(formid).action + '&inajax=1'; //ajaxposthandle = [showid, ajaxframeid, formid, ajaxframeid, func]; ajaxposthandle = [formid, func, parameter]; if(ajaxframe.attachevent) { ajaxframe.detachevent ('onload', ajaxpost_load); ajaxframe.attachevent('onload', ajaxpost_load); } else { document.removeeventlistener('load', ajaxpost_load, true); ajaxframe.addeventlistener('load', ajaxpost_load, false); } $(formid).submit(); return false; } function ajaxpost_load() { var formstatus = '__' + ajaxposthandle[0]; showloading('none'); if(is_ie) { var s = $('ajaxframe').contentwindow.document.xmldocument.text; } else { var s = $('ajaxframe').contentwindow.document.documentelement.firstchild.nodevalue; } evaled = false; if(s.indexof('ajaxerror') != -1) { evalscript(s); evaled = true; } if(s.indexof('ajaxok') != -1) { ajaxpostresult = 1; } else { ajaxpostresult = 0; } //function if(ajaxposthandle[1]) { settimeout(ajaxposthandle[1] + '(\'' + ajaxposthandle[2] + '\',' + ajaxpostresult + ')', 10); } if(!evaled && (typeof ajaxerror == 'undefined' || !ajaxerror) && $(formstatus)) { $(formstatus).style.display = ''; ajaxinnerhtml($(formstatus), '
' + s + '
'); evalscript(s); if($(formstatus).ctrlid) setmenuposition($(formstatus).ctrlid, 0); if($(formstatus).ctrlid) jsmenu['timer'][$(formstatus).ctrlid] = settimeout("hidemenu()", 2000); } ajaxerror = null; if($(ajaxposthandle[0])) { $(ajaxposthandle[0]).target = 'ajaxframe'; } ajaxposthandle = 0; } function hidestatus(showid) { showid = '__' + showid; if($(showid)) { $(showid).style.display = "none"; } } function ajaxmenu(e, ctrlid, timeout, func, offset) { var box = 0; showloading(); if(jsmenu['active'][0] && jsmenu['active'][0].ctrlkey == ctrlid) { hidemenu(); doane(e); return; } else if(is_ie && is_ie < 7 && document.readystate.tolowercase() != 'complete') { return; } cache = 0; divclass = 'popupmenu_popup'; optionclass = 'popupmenu_option'; if(isundefined(timeout)) timeout = 3000; if(isundefined(func)) func = ''; if(isundefined(offset)) offset = 0; duration = timeout > 10000 ? 3 : 0; executetime = duration ? 2000: timeout; if(offset == -1) { divclass = 'popupmenu_centerbox'; box = 1; } var div = $(ctrlid + '_menu'); if(cache && div) { showmenu(ctrlid, e.type == 'click', offset, duration, timeout, 0, ctrlid, 500, 1); if(func) settimeout(func + '(' + ctrlid + ')', executetime); doane(e); } else { if(!div) { div = document.createelement('div'); div.ctrlid = ctrlid; div.id = ctrlid + '_menu'; div.style.display = 'none'; div.classname = divclass; $('append_parent').appendchild(div); } var x = new ajax(); var href = !isundefined($(ctrlid).href) ? $(ctrlid).href : $(ctrlid).attributes['href'].value; x.div = div; x.etype = e.type; x.optionclass = optionclass; x.duration = duration; x.timeout = timeout; x.executetime = executetime; x.get(href + '&ajaxmenuid='+ctrlid+'_menu&popupmenu_box='+box, function(s) { evaled = false; if(s.indexof('ajaxerror') != -1) { evalscript(s); evaled = true; if(!cache && duration != 3 && x.div.id) settimeout('$("append_parent").removechild($(\'' + x.div.id + '\'))', timeout); } if(!evaled && (typeof ajaxerror == 'undefined' || !ajaxerror)) { if(x.div) x.div.innerhtml = '
' + s + '
'; showmenu(ctrlid, x.etype == 'click', offset, x.duration, x.timeout, 0, ctrlid, 500, 1); if(func) settimeout(func + '("' + ctrlid + '")', x.executetime); } if(!evaled) evalscript(s); ajaxerror = null; showloading('none'); }); doane(e); } showloading('none'); doane(e); } //得到一个定长的hash值,依赖于 stringxor() function hash(string, length) { var length = length ? length : 32; var start = 0; var i = 0; var result = ''; filllen = length - string.length % length; for(i = 0; i < filllen; i++){ string += "0"; } while(start < string.length) { result = stringxor(result, string.substr(start, length)); start += length; } return result; } function stringxor(s1, s2) { var s = ''; var hash = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'; var max = math.max(s1.length, s2.length); for(var i=0; i'+s+''; $('append_parent').appendchild(div1); var trs = div1.getelementsbytagname('tr'); var l = trs.length; for(var i=0; i