⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 common.js

📁 asp的bbs程序
💻 JS
📖 第 1 页 / 共 4 页
字号:
/*
  common
*/
// 我的帐号
//function userAccount () {
//    BindPopup('user_account', 'user_account_menu', -75);
//}

// 短消息
function userMsg () {
    var user_msg = $('user_msg');
    if (!user_msg) return;
    var tip = user_msg.tip;
    if (!tip) {
        if (!$('user_message') || !$('user_msg_close')) return;
        $('user_message')._html = $('user_message').innerHTML;
        $('user_message').innerHTML = '';
        var content = $('user_message')._html;

        tip = user_msg.tip = PopUp.Panel(content);
        PopUp.AddPopUp(tip, false, document.forms[0]);
        PopUp.AddMask(tip);
        //CSS.SetAlpha(tip, 90);

        function user_msg_resize () {
            var l = Global.GetOffsetLeft(user_msg) - 287 + 75;
            var t = Global.GetOffsetTop(user_msg) + 15;
            PopUp.SetXY(tip, l, t);
        }
        user_msg_resize();
        Events.AttachEvent(window, 'resize', user_msg_resize);

        // remove
        var close = userMsg.close = function (e) {
            Events.RemoveEvent(window, 'resize', user_msg_resize);
            Events.RemoveEvent($('user_msg_close'), 'click', close);
            PopUp.RemovePopUp(tip, tip.parentNode);
            e && Events.CancelAll(e);
        }
        //Events.AttachEvent($('user_msg_close'), 'click', close);
    }
}
function userMsgReply (th, messageId) {
    var p = th.parentNode.parentNode; // <ul>
    var reply = $('user_message_reply');
    oNode.RemoveNode(reply, reply.parentNode);
    if (th.parentNode.parentNode.nextSibling) {
        oNode.InsertBefore(reply, th.parentNode.parentNode.nextSibling);
    }
    else {
        oNode.AddNode(reply, p.parentNode);
    }
    reply.style.display = '';
    $('topHiddenMessageID').value= messageId;
}

BindPopup.currentMenu = null;
BindPopup.back = null;
function BindPopup(binderId, popupId, align, offsetX, offsetY, delay) {
    var binder = $(binderId);
    if (!binder) return;
    var popup = $(popupId);
    if (!popup) return;
    //popup = resetPopup(popup);
    popup.style.position = 'absolute';
    popup.style.visibility = 'visible';
    popup.style.zIndex = 10;

    if (!offsetX) offsetX = 0;
    if (!offsetY) offsetY = 0;

    var back = BindPopup.back;
    if (Browser.IsIE56 && !back) {
        back = BindPopup.back = oNode.CreateNode('iframe');
        oNode.InsertBefore(back, popup);
        back.style.position = 'absolute';
        back.style.left = '-1000px';
        back.style.top = '-1000px';
        CSS.SetAlpha(back, 0);
    }

    var interval;
    Events.AttachEvent(binder, 'mouseover', function () {
		if (delay)
			binder.interval = setTimeout(show, 500);
		else 
			show();
    });
    Events.AttachEvent(binder, 'mouseout', function () {
		if (delay) {
			clearTimeout(binder.interval);
			hide();
		}
		else 
			hide();
    });
    Events.AttachEvent(popup, 'mouseover', function () {
        clearTimeout(interval);
    });
    Events.AttachEvent(popup, 'mouseout', function () {
        hide();
    });
    // 导致其他功能无法正常使用
    //Events.AttachEvent(popup, 'click', function () {
    //    _hide();
    //});
    // 此功能已无必要
    //Events.AttachEvent(window, 'resize', move);

	function show () {
        if (interval) clearTimeout(interval);
        if (BindPopup.currentMenu && BindPopup.currentMenu != popup)
            BindPopup.currentMenu.hide();
        popup.style.zIndex = 10;
        popup.style.display = '';
        move();

        BindPopup.currentMenu = popup;
	}

    function move () {
        popup.style.top = Global.GetOffsetTop(binder) + binder.offsetHeight + 'px';

        var left = Global.GetOffsetLeft(binder);
        align = align || 'left';
        switch (align.toString().toLowerCase()) {
            case 'left':
                break;
            case 'center':
                left += (binder.offsetWidth - popup.offsetWidth) / 2;
                break;
            case 'right':
                left += binder.offsetWidth - popup.offsetWidth;
                break;
        }
        popup.style.left = left + offsetX + 'px';

        if (back) {
            back.style.left = popup.style.left;
            back.style.top = popup.style.top;
            back.style.width = popup.offsetWidth + 'px';
            back.style.height = popup.offsetHeight + 'px';
        }
    }
    function hide () {
        interval = setTimeout(_hide, 500);
    }
    function _hide () {
        popup.style.display = 'none';
        popup.style.zIndex = 1;
        if (back) {
            back.style.left = '-1000px';
            back.style.top = '-1000px';
        }
        Events.RemoveEvent(window, 'resize', move);
    }
    popup.hide = _hide;
}
function resetPopup (el) {
    if (el.tagName.toLowerCase() == 'div')
        return el;
    var c = document.createElement('div');
    c.innerHTML = el.innerHTML;
    oNode.RemoveNode(el);
    oNode.AddNode(c);
    c.style.display = 'none';
    return c;
}

/* blank out
// 关闭侧边栏
function CloseSide () {
    var cookie_name = 'closesidebar';
    var but = $('action_closesidebar');
    if (!but) return;
    var c = $('content');
    var open = true;
    function d (e) {
        if (open) {
            but.innerHTML = '开启侧栏';
            CSS.ReplaceClass(c, 'hassidebar', 'nosidebar');
            Cookie.Set(cookie_name, '0');
        }
        else {
            but.innerHTML = '关闭侧栏';
            CSS.ReplaceClass(c, 'nosidebar', 'hassidebar');
            Cookie.Set(cookie_name, '1');
        }
        open = !open
        e && Events.CancelAll(e);
    }
    Events.AttachEvent(but, 'click', d);

    var is_close = Cookie.cookies[cookie_name];
    if (is_close == '0') open = true;d();
}
*/

// 切换
function Switch (num, tag) {
    for (var x = 1; x < num; x++) {
        var list = [];
        var heads = $('head_' + x).getElementsByTagName('a');
        var bodys = $('body_' + x).getElementsByTagName(tag ? tag[x - 1] : 'ul');
        for (var i = 0, len = heads.length; i < len; i++) {
            list[i] = [heads[i], bodys[i]];
        }
        Effects.Switch(list, 'current', '');
    }
}

//// 板块菜单显示
//function blockMenu () {
//    var nav_menu = $('navigation_menu');
//    if (!nav_menu) return;
//    nav_menu._html = nav_menu.innerHTML;
//    nav_menu.innerHTML = '';
//    var content = nav_menu._html;

//    var _menu;
//    var interval;
//    var display = false;

//    var nav = $('navigation1');
//    if (nav) {
//        nav = nav.getElementsByTagName('a')[0];
//        Events.AttachEvent(nav, 'mouseover', function (e) {
//            show(e, this);
//        });
//        Events.AttachEvent(nav, 'mouseout', function () {
//            interval = setTimeout(hide, 300);
//        });
//    }

//    var nav2 = $('navigation2');
//    if (nav2) {
//        nav2 = nav2.getElementsByTagName('a')[0];
//        Events.AttachEvent(nav2, 'mouseover', function (e) {
//            show(e, this);
//        });
//        Events.AttachEvent(nav2, 'mouseout', function () {
//            interval = setTimeout(hide, 300);
//        });
//    }

//    function show (e, th) {
//        clearTimeout(interval);
//        if (display) return;
//        display = true;
//        menu = _menu;
//        if (!menu) {
//            menu = _menu = PopUp.Panel(content);
//            PopUp.AddPopUp(menu, false);
//            CSS.AddClass(menu, nav_menu.className);
//            PopUp.AddMask(menu);

//            Events.AttachEvent(menu, 'mouseover', function () {
//                clearTimeout(interval);
//            });
//            Events.AttachEvent(menu, 'mouseout', function () {
//                interval = setTimeout(hide, 300);
//            });
///*
//            Events.AttachEvent(document, 'mousedown', function (e, th) {
//                var obj = $EO(e);
//                while (obj) {
//                    if (obj == menu) return;
//                    obj = obj.parentNode;
//                }
//                nav.display = false;
//                PopUp.RemovePopUp(menu);
//                nav.menu = null;
//            });
//*/
//            Events.CancelAll(e);
//        }

//        // 调整位置
//        var SH = Global.GetScrollTop();
//        var OH = Global.GetOffsetTop(th);
//        var CH = Global.GetClientHeight();
//        var tH = OH - SH;
//        var bH = CH - tH;
//        var h = menu.offsetHeight;
//        // 正常
//        if (h + 20 < bH) {
//            menu.style.top = OH + 20 + 'px';
//        }
//        // 显示于顶部
//        else if (h + 20 < tH) {
//            menu.style.top = SH + tH - h + 'px';
//        }
//        // 顶部较高
//        else if (tH > bH) {
//            menu.style.top = SH + 'px';
//            menu.style.height = tH + 'px';
//            menu.style.overflow = 'auto';
//        }
//        // 底部较高,超出范围
//        else {
//            menu.style.top = OH + 20 + 'px';
//            menu.style.height = bH - 20 + 'px';
//            menu.style.overflow = 'auto';
//        }
//        menu.style.left = Global.GetOffsetLeft(th) - 26 + 'px';
//    }
//    function hide () {
//        display = false;
//        _menu && PopUp.RemovePopUp(_menu);
//        _menu = null;
//    }
//}

// 表单提交并禁用提交按钮
// 调用方式:onclick="return FormSubmit(this)"
function FormSubmit (th) {
    setTimeout(function () {th.disabled = true}, 100);
    return true;
}

// 复选框选取,当前条目为选择状态
function itemClick (th) {
    try {
        var p = th.parentNode.parentNode;
        th.checked ? CSS.AddClass(p, 'current') : CSS.RemoveClass(p, 'current');
    }
    catch (e) {}
}

function itemMouseOver (th) {
    CSS.AddClass(th, 'hover');
    th.onmouseout ||
    (th.onmouseout = function () {
        CSS.RemoveClass(th, 'hover');
    });
}

// 自动缩放图片
function imageScale (th, dw /* 显示的宽度 */, dh /* 显示的宽度 */, nonMargin) {
    var ow = th.offsetWidth, oh = th.offsetHeight;
    th.ow = ow;
    th.oh = oh;

    if (ow / oh > dw / dh) {
        if (ow > dw) {
            th.style.width = dw + 'px';
            th.style.height = dw / ow * oh + 'px';
            nonMargin || (th.style.marginTop = (dh - dw / ow * oh) / 2 + 'px');
        }
        else {
            nonMargin || (th.style.marginTop = (dh - oh) / 2 + 'px');
        }
    }
    else {
        if (oh > dh) {
            th.style.height = dh + 'px';
            th.style.width = dh / oh * ow + 'px';
        }
        else {
            nonMargin || (th.style.marginTop = (dh - oh) / 2 + 'px');
        }
    }
}

// 图片浮动预览
function imageTip (pCss) {
    var tip = new Tip();
    tip.Condition = function (e) {
        var obj = $EO(e);
        while (obj) {
            if (obj.className && obj.className.indexOf(pCss) > -1) break;
            obj = obj.parentNode;
        }
        if (obj) obj = $EO(e);
        if (!obj || obj.tagName.toLowerCase() != 'img') {
            this.display = false;
        }
        else {
            if (imageTip.src != obj.src) {
                imageTip.src = obj.src;
                this.text = '<img src="' + obj.src + '" />';
            }
            this.display = true;
        }
        return true;
    };
    tip.Change = function (e, flow) {
        var imgs = flow.getElementsByTagName('img');
        if (imgs && imgs[0]) {
            var ow = imgs[0].width, oh = imgs[0].height;
            var w = 300;//Global.GetClientWidth() - e.clientX;
            if (w < ow) {
                imgs[0].width = w - 20;
                imgs[0].height = (w - 20) / ow * oh;
            }
        }
    };
    tip.Create();
    tip.css.tip = 'image-tip';
    /*
    Events.AttachEvent(document, 'mousemove', function (e) {
        var obj = $EO(e);
        while (obj) {
            if (obj.className == pCss) break;
            obj = obj.parentNode;
        }
        if (obj) obj = $EO(e);
        if (!obj || obj.tagName.toLowerCase() != 'img') {
            tip.SetVisible(false);
            return;
        }
        if (imageTip.src != obj.src) {
            imageTip.src = obj.src;
            tip.SetText('<img src="' + obj.src + '" />');
        }
        tip.SetVisible(true);
    });
    */
}

// 清理编辑的内容
function clearEditorContent (str) {
    str = str.replace(/(<img[^>]+?)onload="[^"]+?"([^>]*?>)/gi, '$1$2');
    str = str.replace(/(<img[^>]+?)onerror="[^"]+?"([^>]*?>)/gi, '$1$2');
    return str;
}

// 提交后,清除验证码
// ('验证码容器id', '验证码文本框', '提示信息容器id')
function validateClear (validate_id, input_name, panel_id) {
    // 重设验证码
    validateReset(validate_id);
    // 清空文本域
    input_name = document.getElementsByName(input_name);
    input_name.length > 0 && (input_name[0].value = '');
    // 清空提示
    AjaxRequest.Clear('ap_checkvcode');
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -