?? widget.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 + -