?? global.lib.js
字號:
?/*
By Hangring
#2007.12.24#
*/
$Defined('Global');
var Global = {PATH:'/'};
Global.GetObject = function ($_) {
var d = document;
return (d.all && d.all($_)) || (d.getElementById && d.getElementById($_)) || null;
}
// 文檔尺寸
Global.GetDocWidth = function (d) {
d = d || document;
return Math.max(this.GetClientWidth(d), d.body.offsetWidth);
};
Global.GetDocHeight = function (d) {
d = d || document;
return Math.max(this.GetClientHeight(d), d.body.offsetHeight);
};
// 已滾動尺寸
Global.GetScrollLeft = function (d) {
d = d || document;
return (d.documentElement ? d.documentElement.scrollLeft : d.body.scrollLeft);
};
Global.GetScrollTop = function (d) {
d = d || document;
return (d.documentElement ? d.documentElement.scrollTop : d.body.scrollTop);
};
// 可視尺寸
// ie5.5獲取的值為0,通過Global.GetDocWidth()/Global.GetDocHeight()可獲取
Global.GetClientWidth = function (d) {
d = d || document;
return (window.innerWidth || d.documentElement && d.documentElement.clientWidth || d.body.clientWidth);
};
Global.GetClientHeight = function (d) {
d = d || document;
return (window.innerHeight || d.documentElement && d.documentElement.clientHeight || d.body.clientHeight);
};
// 相對尺寸
Global.GetOffsetTop = function (el, p) {
el = $(el);
var _t = el.offsetTop;
while (el = el.offsetParent) {
if (el == p) break;
_t += el.offsetTop;
}
return _t;
};
Global.GetOffsetLeft = function (el, p) {
el = $(el);
var _l = el.offsetLeft;
while (el = el.offsetParent) {
if (el == p) break;
_l += el.offsetLeft;
}
return _l;
};
// 唯一值
Global.Random = function () {
return (new Date().getTime() + '_' + Math.floor(Math.random() * 10000000));
};
Global.FlashEnabled = function (startVersion, endVersion) {
var enabled = false;
var start = 6;
var end = 11;
if (typeof startVersion == 'number') {
start = startVersion;
end = endVersion ? (endVersion + 1) : (startVersion + 1);
}
try {
if (window.ActiveXObject) {
for (var i = start; i < end; i++) {
if (new ActiveXObject('ShockwaveFlash.ShockwaveFlash.' + i))
break;
}
if (i < end) enabled = true;
}
else {
var description = navigator.plugins['Shockwave Flash'].description;
// Shockwave Flash 9.0 r124
var arr = /^Shockwave\s+Flash\s+([0-9]+)/i.exec(description);
if (arr && arr.length > 1 && arr[1] >= start && arr[1] < end) {
enabled = true;
}
}
}
catch (e) {
enabled = false;
}
return (!!enabled);
};
Global.LoadScript = function (src) {
document.write('<script type="text/javascript" src="' + src + '"><' + '/' + 'script>');
};
/*
// 是否為本地運行
Global.IsLocal = function () {
return location.href.indexOf('file:///') == 0;
};
*/
// ie5不支持Array.push()
Array.prototype.push || (Array.prototype.push = function (arg) {this[this.length] = arg;});
// Object to Array
function ToArray (obj, index) {
return Array.prototype.slice.apply(obj).slice(index || 0);
}
// typeof
function TypeOf (obj) {
if (typeof obj == 'undefined') return 'undefined';
var type = obj.constructor.name;
if (obj.constructor && typeof(type) == 'undefined') {
if (obj.constructor === Object)
return 'object';
if (obj.constructor === Function)
return 'function';
}
return (type ? type.toLowerCase() : 'string');
};
///
// object or list
// arguments is 'id' or ('id1', 'id2', ..., 'idn')
// ie中, 對于不同的HTMLElement擁有相同值的name與id,會對后續(xù)產生不良影響
function $ () {
var $_ = arguments;
if ($_.length == 1) {
$_ = typeof $_[0] == 'string' ? Global.GetObject($_[0]) : $_[0];
}
else if ($_.length > 1) {
for (var i = 0; i < $_.length; i++) {
$_[i] = typeof $_[i] == 'string' ? Global.GetObject($_[i]) : $_[i];
}
}
else {
$_ = null;
}
return $_;
}
// event
function $E (e, win) {
win = win || window;
return win.event || e || null;
}
// event target object
function $EO (e, win) {
//e = $E(e, win) || null;
return e && (e.target || e.srcElement) || null;
}
///
function $Defined (cls) {
if (typeof eval(cls) != 'undefined')
alert('變量' + cls + ' 重定義。');
}
window.onerror = function () {/*return true;*/};
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -