📄 common.js
字号:
function hostconvert(url) {
if(!url.match(/^https?:\/\//)) url = SITEURL + url;
var url_host = getHost(url);
var cur_host = getHost().toLowerCase();
if(url_host && cur_host != url_host) {
url = url.replace(url_host, cur_host);
}
return url;
}
function newfunction(func) {
var args = [];
for(var i=1; i<arguments.length; i++) args.push(arguments[i]);
return function(event) {
doane(event);
window[func].apply(window, args);
return false;
}
}
function evalscript(s) {
if(s.indexOf('<script') == -1) return s;
var p = /<script[^\>]*?>([^\x00]*?)<\/script>/ig;
var arr = [];
while(arr = p.exec(s)) {
var p1 = /<script[^\>]*?src=\"([^\>]*?)\"[^\>]*?(reload=\"1\")?(?:charset=\"([\w\-]+?)\")?><\/script>/i;
var arr1 = [];
arr1 = p1.exec(arr[0]);
if(arr1) {
appendscript(arr1[1], '', arr1[2], arr1[3]);
} else {
p1 = /<script(.*?)>([^\x00]+?)<\/script>/i;
arr1 = p1.exec(arr[0]);
appendscript('', arr1[2], arr1[1].indexOf('reload=') != -1);
}
}
return s;
}
var safescripts = {}, evalscripts = [];
function safescript(id, call, seconds, times, timeoutcall, endcall, index) {
seconds = seconds || 1000;
times = times || 0;
var checked = true;
try {
if(typeof call == 'function') {
call();
} else {
eval(call);
}
} catch(e) {
checked = false;
}
if(!checked) {
if(!safescripts[id] || !index) {
safescripts[id] = safescripts[id] || [];
safescripts[id].push({
'times':0,
'si':setInterval(function () {
safescript(id, call, seconds, times, timeoutcall, endcall, safescripts[id].length);
}, seconds)
});
} else {
index = (index || 1) - 1;
safescripts[id][index]['times']++;
if(safescripts[id][index]['times'] >= times) {
clearInterval(safescripts[id][index]['si']);
if(typeof timeoutcall == 'function') {
timeoutcall();
} else {
eval(timeoutcall);
}
}
}
} else {
try {
index = (index || 1) - 1;
if(safescripts[id][index]['si']) {
clearInterval(safescripts[id][index]['si']);
}
if(typeof endcall == 'function') {
endcall();
} else {
eval(endcall);
}
} catch(e) {}
}
}
function $F(func, args, script) {
var run = function () {
var argc = args.length, s = '';
for(i = 0;i < argc;i++) {
s += ',args[' + i + ']';
}
eval('var check = typeof ' + func + ' == \'function\'');
if(check) {
eval(func + '(' + s.substr(1) + ')');
} else {
setTimeout(function () { checkrun(); }, 50);
}
};
var checkrun = function () {
if(JSLOADED[src]) {
run();
} else {
setTimeout(function () { checkrun(); }, 50);
}
};
script = script || 'common_extra';
src = JSPATH + script + '.js?' + VERHASH;
if(!JSLOADED[src]) {
appendscript(src);
}
checkrun();
}
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 ? charset : (BROWSER.firefox ? document.characterSet : document.charset);
try {
if(src) {
scriptNode.src = src;
scriptNode.onloadDone = false;
scriptNode.onload = function () {
scriptNode.onloadDone = true;
JSLOADED[src] = 1;
};
scriptNode.onreadystatechange = function () {
if((scriptNode.readyState == 'loaded' || scriptNode.readyState == 'complete') && !scriptNode.onloadDone) {
scriptNode.onloadDone = true;
JSLOADED[src] = 1;
}
};
} else if(text){
scriptNode.text = text;
}
document.getElementsByTagName('head')[0].appendChild(scriptNode);
} catch(e) {}
}
function stripscript(s) {
return s.replace(/<script.*?>.*?<\/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(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) {
var evaled = false;
if(s.indexOf('ajaxerror') != -1) {
evalscript(s);
evaled = true;
}
if(!evaled && (typeof ajaxerror == 'undefined' || !ajaxerror)) {
if(x.showId) {
x.showId.style.display = x.display;
ajaxinnerhtml(x.showId, s);
ajaxupdateevents(x.showId);
if(x.autogoto) scroll(0, x.showId.offsetTop);
}
}
ajaxerror = null;
if(recall && typeof recall == 'function') {
recall();
} else if(recall) {
eval(recall);
}
if(!evaled) evalscript(s);
});
}
function ajaxpost(formid, showid, waitid, showidclass, submitbtn, recall) {
var waitid = typeof waitid == 'undefined' || waitid === null ? showid : (waitid !== '' ? waitid : '');
var showidclass = !showidclass ? '' : showidclass;
var ajaxframeid = 'ajaxframe';
var ajaxframe = $(ajaxframeid);
var formtarget = $(formid).target;
var handleResult = function() {
var s = '';
var evaled = false;
showloading('none');
try {
s = $(ajaxframeid).contentWindow.document.XMLDocument.text;
} catch(e) {
try {
s = $(ajaxframeid).contentWindow.document.documentElement.firstChild.wholeText;
} catch(e) {
try {
s = $(ajaxframeid).contentWindow.document.documentElement.firstChild.nodeValue;
} catch(e) {
s = '内部错误,无法显示此内容';
}
}
}
if(s != '' && s.indexOf('ajaxerror') != -1) {
evalscript(s);
evaled = true;
}
if(showidclass) {
if(showidclass != 'onerror') {
$(showid).className = showidclass;
} else {
showError(s);
ajaxerror = true;
}
}
if(submitbtn) {
submitbtn.disabled = false;
}
if(!evaled && (typeof ajaxerror == 'undefined' || !ajaxerror)) {
ajaxinnerhtml($(showid), s);
}
ajaxerror = null;
if($(formid)) $(formid).target = formtarget;
if(typeof recall == 'function') {
recall();
} else {
eval(recall);
}
if(!evaled) evalscript(s);
ajaxframe.loading = 0;
$('append_parent').removeChild(ajaxframe.parentNode);
};
if(!ajaxframe) {
var div = document.createElement('div');
div.style.display = 'none';
div.innerHTML = '<iframe name="' + ajaxframeid + '" id="' + ajaxframeid + '" loading="1"></iframe>';
$('append_parent').appendChild(div);
ajaxframe = $(ajaxframeid);
} else if(ajaxframe.loading) {
return false;
}
_attachEvent(ajaxframe, 'load', handleResult);
showloading();
$(formid).target = ajaxframeid;
var action = $(formid).getAttribute('action');
action = hostconvert(action);
$(formid).action = action.replace(/\&inajax\=1/g, '')+'&inajax=1';
$(formid).submit();
if(submitbtn) {
submitbtn.disabled = true;
}
doane();
return false;
}
function ajaxmenu(ctrlObj, timeout, cache, duration, pos, recall, idclass, contentclass) {
if(!ctrlObj.getAttribute('mid')) {
var ctrlid = ctrlObj.id;
if(!ctrlid) {
ctrlObj.id = 'ajaxid_' + Math.random();
}
} else {
var ctrlid = ctrlObj.getAttribute('mid');
if(!ctrlObj.id) {
ctrlObj.id = 'ajaxid_' + Math.random();
}
}
var menuid = ctrlid + '_menu';
var menu = $(menuid);
if(isUndefined(timeout)) timeout = 3000;
if(isUndefined(cache)) cache = 1;
if(isUndefined(pos)) pos = '43';
if(isUndefined(duration)) duration = timeout > 0 ? 0 : 3;
if(isUndefined(idclass)) idclass = 'p_pop';
if(isUndefined(contentclass)) contentclass = 'p_opt';
var func = function() {
showMenu({'ctrlid':ctrlObj.id,'menuid':menuid,'duration':duration,'timeout':timeout,'pos':pos,'cache':cache,'layer':2});
if(typeof recall == 'function') {
recall();
} else {
eval(recall);
}
};
if(menu) {
if(menu.style.display == '') {
hideMenu(menuid);
} else {
func();
}
} else {
menu = document.createElement('div');
menu.id = menuid;
menu.style.display = 'none';
menu.className = idclass;
menu.innerHTML = '<div class="' + contentclass + '" id="' + menuid + '_content"></div>';
$('append_parent').appendChild(menu);
var url = (!isUndefined(ctrlObj.href) ? ctrlObj.href : ctrlObj.attributes['href'].value);
url += (url.indexOf('?') != -1 ? '&' :'?') + 'ajaxmenu=1';
ajaxget(url, menuid + '_content', 'ajaxwaitid', '', '', func);
}
doane();
}
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<max; i++) {
var k = s1.charCodeAt(i) ^ s2.charCodeAt(i);
s += hash.charAt(k % 52);
}
return s;
}
function showPreview(val, id) {
var showObj = $(id);
if(showObj) {
showObj.innerHTML = val.replace(/\n/ig, "<bupdateseccoder />");
}
}
function showloading(display, waiting) {
var display = display ? display : 'block';
var waiting = waiting ? waiting : '请稍候...';
$('ajaxwaitid').innerHTML = waiting;
$('ajaxwaitid').style.display = display;
}
function ajaxinnerhtml(showid, s) {
if(showid.tagName != 'TBODY') {
showid.innerHTML = s;
} else {
while(showid.firstChild) {
showid.firstChild.parentNode.removeChild(showid.firstChild);
}
var div1 = document.createElement('DIV');
div1.id = showid.id+'_div';
div1.innerHTML = '<table><tbody id="'+showid.id+'_tbody">'+s+'</tbody></table>';
$('append_parent').appendChild(div1);
var trs = div1.getElementsByTagName('TR');
var l = trs.length;
for(var i=0; i<l; i++) {
showid.appendChild(trs[0]);
}
var inputs = div1.getElementsByTagName('INPUT');
var l = inputs.length;
for(var i=0; i<l; i++) {
showid.appendChild(inputs[0]);
}
div1.parentNode.removeChild(div1);
}
}
function doane(event, preventDefault, stopPropagation) {
var preventDefault = isUndefined(preventDefault) ? 1 : preventDefault;
var stopPropagation = isUndefined(stopPropagation) ? 1 : stopPropagation;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -