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

📄 global.lib.js

📁 asp的bbs程序
💻 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,会对后续产生不良影响
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 + -