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

📄 widget.js

📁 asp的bbs程序
💻 JS
字号:
// 弹出框
var Widget = {
    // 警告框
    InfoNum : 0,
    // 是否有关闭按钮
    InfoCloseAble : true,
    Success : function (t, c, callback) {
        var p = this.Info(t, c, callback);
        var p_canel = $('popup_info_canel');
        CSS.RemoveClass(p, 'error', 'alert');
        CSS.AddClass(p, 'valid');
        CSS.SetDisplay(p_canel, false);
    },
    Error : function (t, c, callback) {
        var p = this.Info(t, c, callback);
        var p_canel = $('popup_info_canel');
        CSS.RemoveClass(p, 'valid', 'alert');
        CSS.AddClass(p, 'error');
        CSS.SetDisplay(p_canel, false);
    },
    Alert : function (t, c, callback) {
        var p = this.Info(t, c, callback);
        var p_canel = $('popup_info_canel');
        CSS.RemoveClass(p, 'valid', 'error');
        CSS.AddClass(p, 'alert');
        CSS.SetDisplay(p_canel, false);
    },
    Confirm : function (t, c, func, callback) {
        var p = this.Info(t, c, function () {
            var returnValue = false;
            if (p._returnValue) {
                returnValue = true;
                func();
            }
            callback && callback(returnValue);
        });

        CSS.RemoveClass(p, 'valid', 'error');
        CSS.AddClass(p, 'alert');

        var p_canel = $('popup_info_canel');
        CSS.SetDisplay(p_canel, true);
    },
    Info : function (title, content, callback) {
        var p = $('popup_info');
        var p_bar = $('popup_info_bar');
        var p_title = $('popup_info_title');
        var p_content = $('popup_info_content');
        var p_close = $('popup_info_close');
        var p_confirm = $('popup_info_confirm');
        var p_canel = $('popup_info_canel');
        
        p_close.style.display = '';
        p_confirm.style.display = '';

        // restore
        if (p._display) PopUp.RestorePopUp(p);

        p._returnValue = false;
        // title
        p_title.innerHTML = title;
        // content
        content && (p_content.innerHTML = content);

        // close
        if (this.InfoCloseAble) {
            function _confirm () {
                p._returnValue = true;
                _close();
            }

            var _close = Widget.InfoClose = function (e) {
                p._display = false;
                Widget.InfoNum = 0;
                e && Events.CancelAll(e);
                PopUp.RestorePopUp(p);
                Events.RemoveEvent(p_close, 'click', _close);
                Events.RemoveEvent(p_canel, 'click', _close);
                Events.RemoveEvent(p_confirm, 'click', _confirm);
                Events.RemoveEvent(window, 'scroll', scroll);
                callback && callback();
            };

            Events.AttachEvent(p_close, 'click', _close);
            Events.AttachEvent(p_canel, 'click', _close);
            Events.AttachEvent(p_confirm, 'click', _confirm);
            p_confirm.parentNode.style.display = '';
        }
        else {
            p_close.style.display = 'none';
            p_confirm.parentNode.style.display = 'none';
        }

        // move
        Effects.Move(p_bar, p, {modal:!true});

        // float
        PopUp.Panel(p, 0, 0, true);
        PopUp.AddPopUp(p, true);
        PopUp.AddMask(p);
        p.style.zIndex = 10;
        p._display = true;
        //this.ContentNum && p.focus();
        p.focus();

        function scroll () {
            PopUp.SetXY(p, p.style.left, Global.GetScrollTop() + (Global.GetClientHeight() - p.offsetHeight) / 2);
        }
        Events.AttachEvent(window, 'scroll', scroll);

        this.InfoNum = 1;

        return p;
    },
    InfoClose : function () {},
    // 内容框
    ContentNum : 0,
    // args : (title, content, size : {width:Number, height:Number} | width, callback)
    Content : function (title, content, width, callback) {
        DomEvent.Clear();
        AjaxRequest.SetFormIndex(1);
        this.ContentNum = 1;

        var w = $('popup_win');
		//var w_wrap = $('win_wrap');
        var w_bar = $('popup_win_bar');
        var w_title = $('popup_win_title');
        var w_content = $('popup_win_content');
        var w_close = $('popup_win_close');
        
        /*
        <div class="maxwin maxwin-shadow">\
            <div class="win-shadow" id="winShadow"></div>\
        CSS.AddClass(w, 'maxwin-shadow');
		var w_shadow = $('win_shadow');
		if (!w_shadow) {
			w_shadow = oNode.CreateNode('div');
			w_shadow.id = 'win_shadow';
			CSS.AddClass(w_shadow, 'win-shadow');
			oNode.InsertBefore(w_shadow, w.firstChild);
		}
        */

        if (oNode.IsNode(content)) {
            if (!content._innerHTML) {
                content._innerHTML = content.innerHTML;
                content.innerHTML = '';
            }
            content = content._innerHTML;
        }

        // restore
        if (w._display) PopUp.RestorePopUp(w);

        // title 
        title && (w_title.innerHTML = title);
        // content
        content && (w_content.innerHTML = content);
        
		// size
        w.style.width = (width || 400) + 'px';
		
        // close
        w._close = function (e) {
            DomEvent.Clear(true);
            Widget.ContentNum = 0;
            AjaxRequest.FormIndex = 0;
            //if (callback && !callback()) return;
            callback && callback();

            w.RemoveEvent();
            w._display = false;
            e && Events.CancelAll(e);
            w_content.innerHTML = '';
            PopUp.RestorePopUp(w);
            Events.RemoveEvent(w_close, 'click', w._close);
        };
        this.Close = w._close;
        Events.AttachEvent(w_close, 'click', w._close);

        // float
        w.gradual = !true;
        PopUp.Panel(w, 0, 0, true);
        PopUp.AddPopUp(w, true);
        PopUp.AddMask(w);
        w._display = true;
		
		this.Resize();

        // move
        Effects.Move(w_title, w, {modal:!true});
        
        this.Focus(w);

        return w;
    },
    Focus : function (w) {
        w = w || $('popup_win');
        var inputs = w.getElementsByTagName('input');
        if (inputs && inputs[0] && inputs[0].type == 'text') inputs[0].focus();
    },
	// resize : 是否只改变大小
    Resize : function (resize, nogradual) {
		if (!this.ContentNum) return;
        /*
        if ($('popup_win').offsetHeight > 400) {
            var obj = $('popup_win_content').getElementsByTagName('div')[1];
            obj.style.overflow = 'auto';
            obj.style.height = '300px';
        }
        */
		if (!nogradual) {
            node = $('popup_win_content');
            var alpha = 0;
            var gradual = function () {
                if (alpha > 100) {
                    CSS.SetAlpha(node, 100);
                    return;
                }
                CSS.SetAlpha(node, alpha);
                alpha += 10;
                setTimeout(gradual, 0);
            }
            gradual();
        }
		/*
		if (Browser.IsIE)
			$('win_wrap').style.height
				= $('popup_win_bar').offsetHeight
				+ $('popup_win_content').offsetHeight
				+ 'px';
		$('popup_win_close').style.border = '0';
		$('win_shadow').style.height = $('win_wrap').offsetHeight + 12 + 'px';
		$('win_shadow').style.width =  $('win_wrap').offsetWidth + 12 + 'px';
		$('win_shadow').style.marginBottom = -($('win_wrap').offsetHeight + 6) + 'px';
		*/
        //alert($('popup_win').offsetHeight);
        resize || $('popup_win').$Move();
    },
    // show
    Show : function () {
        PopUp.SetVisible($('popup_win'), true);
    },
    // hide
    Hide : function () {
        PopUp.SetVisible($('popup_win'), false);
    },
    // AjaxRequest回调时调用关闭,或外部执行关闭
    Close : function () {},
    // AjaxRequest回调时调用
    Auto : function (state, content, ButtonName) {
        AjaxRequest.DisableButton(ButtonName, false);
        if (state == 'success') {// || state == 'alert'
            try {
                Widget.Close();
            }
            catch (e) {}
        }
        switch (state) {
            case 'success':
                Widget.Success('操作成功', content);
                break;
            case 'error':
                //Widget.Error('错误', content, function () {AjaxRequest.DisableButton(ButtonName, false)});
                Widget.Error('错误', content);
                break;
            case 'alert':
                Widget.Alert('警告', content);
                break;
        }
    },

    ///
    // 加载浮动窗
    // 显示
    LoadingNum : 0,
    ShowLoading : function (id, p) {
        id = id || 'popup_loading';
        var w = $(id);
        if (!w) return;
        
        this.HideLoading();
        this.LoadingNum++;

        var w_close = $(id + '_close');
        var w_back = $(id + '_back');
        var w_retry = $(id + '_retry');        

        if (w && w_close && w_back && w_retry) {
            PopUp.Panel(w, 0, 0, true);
            PopUp.AddPopUp(w, true);
            PopUp.AddMask(w);
            p && PopUp.SetXY(w, Global.GetOffsetLeft($(p)), Global.GetOffsetTop($(p)));
            var HideLoading = this.HideLoading = function () {
                this.HideLoading1(w);
            };
            Events.AttachEvent(w_close, 'click', HideLoading);
        }
        else {
            w.style.display = '';
            if (p) {
                w.style.left = Global.GetOffsetLeft($(p)) + 'px';
                w.style.top = Global.GetOffsetTop($(p)) + 'px';
            }
            this.HideLoading = function () {
                this.HideLoading2(w);
            };
        }
    },
    // 隐藏
    HideLoading : function () {},
    HideLoading1 : function (w) {
        this.LoadingNum--;
        if (this.LoadingNum > 1 && this.HideLoading == this.HideLoading1) return;
        this.LoadingNum = 0;
        w && PopUp.RestorePopUp(w);
        w = null;
    },
    HideLoading2 : function (w) {
        this.LoadingNum--;
        w.style.display = 'none';
    }
};

⌨️ 快捷键说明

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