SoFunction
Updated on 2025-04-13

JavaScript function analysis used in discuz Original


function ajaxupdateevents(obj, tagName) {
    tagName = tagName ? tagName : 'A';
    var objs = (tagName);
    for(k in objs) {
        var o = objs[k];
        ajaxupdateevent(o);
    }
}

function ajaxupdateevent(o) {
    if(typeof o == 'object' && ) {
        if(('ajaxtarget')) {
            if(!)  = ();
            var ajaxevent = ('ajaxevent') ? ('ajaxevent') : 'click';
            var ajaxurl = ('ajaxurl') ? ('ajaxurl') : ;
            _attachEvent(o, ajaxevent, newfunction('ajaxget', ajaxurl, ('ajaxtarget'), ('ajaxwaitid'), ('ajaxloading'), ('ajaxdisplay')));
            if(('ajaxfunc')) {
                ('ajaxfunc').match(/(\w+)\((.+?)\)/);
                _attachEvent(o, ajaxevent, newfunction(RegExp.$1, RegExp.$2));
            }
        }
    }
}

/*
*@ url: url requested
*@ id: Displayed id
*@ waitid: The waiting id is the default to the displayed id. If waitid is an empty string, loading... will not be displayed. If null, it will be displayed in the showid area.
*@ linkid:  Which link is contacted by the ajax request? The attributes of the object (such as ajaxdisplay) save some data required by the ajax request process.
*/
function ajaxget(url, showid, waitid, loading, display, recall) {
    waitid = typeof waitid == 'undefined' || waitid === null ? showid : waitid;
    var x = new Ajax();
    (loading);
    (waitid);
     = typeof display == 'undefined' || display == null ? '' : display;
     = $(showid);
    if()  = typeof  === 'undefined' ?  : ;

    if((strlen(url) - 1) == '#') {
        url = (0, strlen(url) - 1);
         = 1;
    }

    var url = url + '&inajax=1&ajaxtarget=' + showid;
    (url, function(s, x) {
        evaled = false;
        if(('ajaxerror') != -1) {
            evalscript(s);
            evaled = true;
        }
        if(!evaled && (typeof ajaxerror == 'undefined' || !ajaxerror)) {
            if() {
                changedisplay(, );
                changedisplay(, );
                 = ;
                ajaxinnerhtml(, s);
                ajaxupdateevents();
                if() scroll(0, );
            }
        }
        if(!evaled)evalscript(s);
        ajaxerror = null;
        if(recall) {eval(recall);}
    });
}

var ajaxpostHandle = 0;
function ajaxpost(formid, showid, waitid) {
    showloading();
    var waitid = typeof waitid == 'undefined' || waitid === null ? showid : (waitid !== '' ? waitid : '');

    if(ajaxpostHandle != 0) {
        return false;
    }
    var ajaxframeid = 'ajaxframe';
    var ajaxframe = $(ajaxframeid);
    if(ajaxframe == null) {
        if (is_ie && !is_opera) {
            ajaxframe = ("<iframe name='" + ajaxframeid + "' id='" + ajaxframeid + "'></iframe>");
        } else {
            ajaxframe = ("iframe");
             = ajaxframeid;
             = ajaxframeid;
        }
        // = ajaxframeid;
         = 'none';
        $('append_parent').appendChild(ajaxframe);

    }
    $(formid).target = ajaxframeid;
    ajaxpostHandle = [showid, ajaxframeid, formid, $(formid).target];
    if() {
         ('onload', ajaxpost_load);
        ('onload', ajaxpost_load);
    } else {
        ('load', ajaxpost_load, true);
        ('load', ajaxpost_load, false);
    }
    $(formid).submit();
    return false;
    //$(waitid).innerHTML = 'Loading...';
}

function ajaxpost_load() {
    showloading('none');
    if(is_ie) {
        var s = $(ajaxpostHandle[1]).;
    } else {
        var s = $(ajaxpostHandle[1]).;
    }
    evaled = false;
    if(('ajaxerror') != -1) {
        evalscript(s);
        evaled = true;
    }
    if(!evaled && (typeof ajaxerror == 'undefined' || !ajaxerror)) {
        ajaxinnerhtml($(ajaxpostHandle[0]), s);
        if(!evaled)evalscript(s);
        setMenuPosition($(ajaxpostHandle[0]).ctrlid, 0);
        setTimeout("hideMenu()", 3000);
    }
    ajaxerror = null;
    if($(ajaxpostHandle[2])) {
        $(ajaxpostHandle[2]).target = ajaxpostHandle[3];
        //$(ajaxpostHandle[2]).removeChild($(ajaxpostHandle[1]));
    }
    ajaxpostHandle = 0;
}

function ajaxmenu(e, ctrlid, timeout, func, cache, duration, ismenu, divclass, optionclass) {
    showloading();
    if(jsmenu['active'][0] && jsmenu['active'][0].ctrlkey == ctrlid) {
        hideMenu();
        doane(e);
        return;
    } else if(is_ie && is_ie < 7 && () != 'complete') {
        return;
    }
    if(isUndefined(timeout)) timeout = 3000;
    if(isUndefined(func)) func = '';
    if(isUndefined(cache)) cache = 1;
    if(isUndefined(divclass)) divclass = 'popupmenu_popup';
    if(isUndefined(optionclass)) optionclass = 'popupmenu_option';
    if(isUndefined(ismenu)) ismenu = 1;
    if(isUndefined(duration)) duration = timeout > 0 ? 0 : 3;
    var div = $(ctrlid + '_menu');
    if(cache && div) {
        showMenu(ctrlid,  == 'click', 0, duration, timeout, 0, ctrlid, 400, 1);
        if(func) setTimeout(func + '(' + ctrlid + ')', timeout);
        doane(e);
    } else {
        if(!div) {
            div = ('div');
             = ctrlid;
             = ctrlid + '_menu';
             = 'none';
             = divclass;
            $('append_parent').appendChild(div);
        }

        var x = new Ajax();
        var href = !isUndefined($(ctrlid).href) ? $(ctrlid).href : $(ctrlid).attributes['href'].value;
         = div;
         = ;
         = optionclass;
         = duration;
         = timeout;
        (href + '&inajax=1&ajaxmenuid='+ctrlid+'_menu', function(s) {
            evaled = false;
            if(('ajaxerror') != -1) {
                evalscript(s);
                evaled = true;
                if(!cache && duration != 3 && ) setTimeout('$("append_parent").removeChild($(\'' +  + '\'))', timeout);
            }
            if(!evaled && (typeof ajaxerror == 'undefined' || !ajaxerror)) {
                if()  = '<div class="' +  + '">' + s + '</div>';
                showMenu(ctrlid,  == 'click', 0, , , 0, ctrlid, 400, 1);
                if(func) setTimeout(func + '("' + ctrlid + '")', );
                //if(!cache && duration != 3 && ) setTimeout('($(\'' +  + '\'))', timeout);
            }
            if(!evaled) evalscript(s);
            ajaxerror = null;
            showloading('none');
        });
        doane(e);
    }
}

//Get a fixed length hash value, depending on stringxor()
function hash(string, length) {
    var length = length ? length : 32;
    var start = 0;
    var i = 0;
    var result = '';
    filllen = length -  % length;
    for(i = 0; i < filllen; i++){
        string += "0";
    }
    while(start < ) {
        result = stringxor(result, (start, length));
        start += length;
    }
    return result;
}

function stringxor(s1, s2) {
    var s = '';
    var hash = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    var max = (, );
    for(var i=0; i<max; i++) {
        var k = (i) ^ (i);
        s += (k % 52);
    }
    return s;
}

function showloading(display, waiting) {
    var display = display ? display : 'block';
    var waiting = waiting ? waiting : 'Loading...';
    $('ajaxwaitid').innerHTML = waiting;
    $('ajaxwaitid'). = display;
}

function ajaxinnerhtml(showid, s) {
    if( != 'TBODY') {
         = s;
    } else {
        while() {
            ();
        }
        var div1 = ('DIV');
         = +'_div';
         = '<table><tbody >'+s+'</tbody></table>';
        $('append_parent').appendChild(div1);
        var trs = ('TR');
        var l = ;
        for(var i=0; i<l; i++) {
            (trs[0]);
        }
        var inputs = ('INPUT');
        var l = ;
        for(var i=0; i<l; i++) {
            (inputs[0]);
        }
        (div1);
    }
}

var hiddenobj = new Array();
var pmwinposition = new Array();
function pmwin(action, param) {
    var objs = ("OBJECT");
    if(action == 'open') {
        for(i = 0;i < ; i ++) {
            if(objs[i]. != 'hidden') {
                objs[i].setAttribute("oldvisibility", objs[i].);
                objs[i]. = 'hidden';
            }
        }
        var clientWidth = ;
        var clientHeight =  ?  : ;
        var scrollTop =  ?  : ;
        var pmwidth = 800;
        var pmheight = clientHeight * 0.9;
        if(!$('pmlayer')) {
            div = ('div'); = 'pmlayer';
             = pmwidth + 'px';
             = pmheight + 'px';
             = ((clientWidth - pmwidth) / 2) + 'px';
             = 'absolute';
             = '999';
            $('append_parent').appendChild(div);
            $('pmlayer').innerHTML = '<div style="width: 800px; background: #666666; margin: 5px auto; text-align: left">' +
                '<div style="width: 800px; height: ' + pmheight + 'px; padding: 1px; background: #FFFFFF; border: 1px solid #7597B8; position: relative; left: -6px; top: -3px">' +
                '<div onmouseover="pmwindrag(this)" style="cursor: move; position: relative; left: 0px; top: 0px; width: 800px; height: 30px; margin-bottom: -30px;"></div>' +
'<a href="###" onclick="pmwin(\'close\')"><img style="position: absolute; right: 20px; top: 15px" src="' + IMGDIR +'/" title="Close" /</a>' +
                '<div  style="margin-top: 30px; position: absolute; width: 100%; height: 100%; display: none"></div><iframe  name="pmframe" style="width:' + pmwidth + 'px;height:100%" allowTransparency="true" frameborder="0"></iframe></div></div>';
        }
        $('pmlayer'). = '';
        $('pmlayer'). = ((clientHeight - pmheight) / 2 + scrollTop) + 'px';
        if(!param) {
             = '';
        } else {
             = '?' + param;
        }
    } else if(action == 'close') {
        for(i = 0;i < ; i ++) {
            if(objs[i].attributes['oldvisibility']) {
                objs[i]. = objs[i].attributes['oldvisibility'].nodeValue;
                objs[i].removeAttribute('oldvisibility');
            }
        }
        hiddenobj = new Array();
        $('pmlayer'). = 'none';
    }
}

var pmwindragstart = new Array();
function pmwindrag(obj) {
     = function(e) {
        if(is_ie) {
             = function() {
                return false;
            }
        }
        pmwindragstart = is_ie ? [, ] : [, ];
        pmwindragstart[2] = parseInt($('pmlayer').);
        pmwindragstart[3] = parseInt($('pmlayer').);
        $('pmwinmask'). = '';
        doane(e);
    }
    _attachEvent(, 'mousemove', function(e) {
        if(pmwindragstart[0]) {
            var pmwindragnow = is_ie ? [, ] : [, ];
            with($('pmlayer')) {
                 = (pmwindragstart[2] + pmwindragnow[0] - pmwindragstart[0]) + 'px';
                 = (pmwindragstart[3] + pmwindragnow[1] - pmwindragstart[1]) + 'px';
            }
            doane(e);
        }
    });
     = function(e) {
        if(is_ie) {
             = function() {
                return true;
            }
        }
        pmwindragstart = [];
        $('pmwinmask'). = 'none';
        doane(e);
    }
     = null;
}

function pmchecknew() {
    ajaxget('?checknewpm=' + (), 'pmnotice', 'ajaxwaitid');
}

var discuz_uid = isUndefined(discuz_uid) ? 0 : discuz_uid;
if(discuz_uid && !getcookie('checkpm') && typeof IN_ADMINCP == 'undefined') {
    if() {
        ('onload', pmchecknew);
    } else {
        ('load', pmchecknew, false);
    }
}