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

📄 dom.js

📁 Ajax下日志框架
💻 JS
📖 第 1 页 / 共 3 页
字号:
/***MochiKit.DOM 1.3.1See <http://mochikit.com/> for documentation, downloads, license, etc.(c) 2005 Bob Ippolito.  All rights Reserved.***/if (typeof(dojo) != 'undefined') {    dojo.provide("MochiKit.DOM");    dojo.require("MochiKit.Iter");}if (typeof(JSAN) != 'undefined') {    JSAN.use("MochiKit.Iter", []);}try {    if (typeof(MochiKit.Iter) == 'undefined') {        throw "";    }} catch (e) {    throw "MochiKit.DOM depends on MochiKit.Iter!";}if (typeof(MochiKit.DOM) == 'undefined') {    MochiKit.DOM = {};}MochiKit.DOM.NAME = "MochiKit.DOM";MochiKit.DOM.VERSION = "1.3.1";MochiKit.DOM.__repr__ = function () {    return "[" + this.NAME + " " + this.VERSION + "]";};MochiKit.DOM.toString = function () {    return this.__repr__();};MochiKit.DOM.EXPORT = [    "formContents",    "currentWindow",    "currentDocument",    "withWindow",    "withDocument",    "registerDOMConverter",    "coerceToDOM",    "createDOM",    "createDOMFunc",    "getNodeAttribute",    "setNodeAttribute",    "updateNodeAttributes",    "appendChildNodes",    "replaceChildNodes",    "removeElement",    "swapDOM",    "BUTTON",    "TT",    "PRE",    "H1",    "H2",    "H3",    "BR",    "CANVAS",    "HR",    "LABEL",    "TEXTAREA",    "FORM",    "STRONG",    "SELECT",    "OPTION",    "OPTGROUP",    "LEGEND",    "FIELDSET",    "P",    "UL",    "OL",    "LI",    "TD",    "TR",    "THEAD",    "TBODY",    "TFOOT",    "TABLE",    "TH",    "INPUT",    "SPAN",    "A",    "DIV",    "IMG",    "getElement",    "$",    "computedStyle",    "getElementsByTagAndClassName",    "addToCallStack",    "addLoadEvent",    "focusOnLoad",    "setElementClass",    "toggleElementClass",    "addElementClass",    "removeElementClass",    "swapElementClass",    "hasElementClass",    "escapeHTML",    "toHTML",    "emitHTML",    "setDisplayForElement",    "hideElement",    "showElement",    "scrapeText",    "elementDimensions",    "elementPosition",    "setElementDimensions",    "setElementPosition",    "getViewportDimensions",    "setOpacity"];MochiKit.DOM.EXPORT_OK = [    "domConverters"];MochiKit.DOM.Dimensions = function (w, h) {    this.w = w;    this.h = h;};MochiKit.DOM.Dimensions.prototype.repr = function () {    var repr = MochiKit.Base.repr;    return "{w: "  + repr(this.w) + ", h: " + repr(this.h) + "}";};MochiKit.DOM.Coordinates = function (x, y) {    this.x = x;    this.y = y;};MochiKit.DOM.Coordinates.prototype.repr = function () {    var repr = MochiKit.Base.repr;    return "{x: "  + repr(this.x) + ", y: " + repr(this.y) + "}";};MochiKit.DOM.Coordinates.prototype.toString = function () {    return this.repr();};MochiKit.Base.update(MochiKit.DOM, {    setOpacity: function(elem, o) {        elem = MochiKit.DOM.getElement(elem);        MochiKit.DOM.updateNodeAttributes(elem, {'style': {                'opacity': o,                 '-moz-opacity': o,                '-khtml-opacity': o,                'filter':' alpha(opacity=' + (o * 100) + ')'            }});    },        getViewportDimensions: function() {        var d = new MochiKit.DOM.Dimensions();                var w = MochiKit.DOM._window;        var b = MochiKit.DOM._document.body;                if (w.innerWidth) {            d.w = w.innerWidth;            d.h = w.innerHeight;        } else if (b.parentElement.clientWidth) {            d.w = b.parentElement.clientWidth;            d.h = b.parentElement.clientHeight;        } else if (b && b.clientWidth) {            d.w = b.clientWidth;            d.h = b.clientHeight;        }        return d;    },    elementDimensions: function (elem) {        var self = MochiKit.DOM;        if (typeof(elem.w) == 'number' || typeof(elem.h) == 'number') {            return new self.Dimensions(elem.w || 0, elem.h || 0);        }        elem = self.getElement(elem);        if (!elem) {            return undefined;        }        if (self.computedStyle(elem, 'display') != 'none') {            return new self.Dimensions(elem.offsetWidth || 0,                 elem.offsetHeight || 0);        }        var s = elem.style;        var originalVisibility = s.visibility;        var originalPosition = s.position;        s.visibility = 'hidden';        s.position = 'absolute';        s.display = '';        var originalWidth = elem.offsetWidth;        var originalHeight = elem.offsetHeight;        s.display = 'none';        s.position = originalPosition;        s.visibility = originalVisibility;        return new self.Dimensions(originalWidth, originalHeight);    },    /*         elementPosition is adapted from YAHOO.util.Dom.getXY, version 0.9.0.        Copyright: Copyright (c) 2006, Yahoo! Inc. All rights reserved.        License: BSD, http://developer.yahoo.net/yui/license.txt    */    elementPosition: function (elem, /* optional */relativeTo) {        var self = MochiKit.DOM;                elem = self.getElement(elem);                if (!elem) {             return undefined;        }        var c = new self.Coordinates(0, 0);                if (elem.x && elem.y) {            /* it's just a MochiKit.DOM.Coordinates object */            c.x += elem.x || 0;            c.y += elem.y || 0;            return c;        } else if (elem.parentNode === null || self.computedStyle(elem, 'display') == 'none') {            return undefined;        }                var box = null;        var parent = null;                var d = MochiKit.DOM._document;        var de = d.documentElement;        var b = d.body;                        if (elem.getBoundingClientRect) { // IE shortcut                        /*                            The IE shortcut is off by two:                http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/getboundingclientrect.asp                            */            box = elem.getBoundingClientRect();                                    c.x += box.left +                 (de.scrollLeft || b.scrollLeft) -                 (de.clientLeft || b.clientLeft);                        c.y += box.top +                 (de.scrollTop || b.scrollTop) -                 (de.clientTop || b.clientTop);                    } else if (d.getBoxObjectFor) { // Gecko shortcut            box = d.getBoxObjectFor(elem);            c.x += box.x;            c.y += box.y;        } else if (elem.offsetParent) {            c.x += elem.offsetLeft;            c.y += elem.offsetTop;            parent = elem.offsetParent;                        if (parent != elem) {                while (parent) {                    c.x += parent.offsetLeft;                    c.y += parent.offsetTop;                    parent = parent.offsetParent;                }            }            /*                                Opera < 9 and old Safari (absolute) incorrectly account for                 body offsetTop and offsetLeft.                            */                        var ua = navigator.userAgent.toLowerCase();            if ((typeof(opera) != "undefined" &&                 parseFloat(opera.version()) < 9) ||                 (ua.indexOf('safari') != -1 &&                 self.computedStyle(elem, 'position') == 'absolute')) {                                                c.x -= b.offsetLeft;                c.y -= b.offsetTop;                            }        }                if (typeof(relativeTo) != 'undefined') {            relativeTo = arguments.callee(relativeTo);            if (relativeTo) {                c.x -= (relativeTo.x || 0);                c.y -= (relativeTo.y || 0);            }        }                if (elem.parentNode) {            parent = elem.parentNode;        } else {            parent = null;        }                while (parent && parent.tagName != 'BODY' &&             parent.tagName != 'HTML') {            c.x -= parent.scrollLeft;            c.y -= parent.scrollTop;                    if (parent.parentNode) {                parent = parent.parentNode;            } else {                parent = null;            }        }                return c;    },        setElementDimensions: function (elem, newSize/* optional */, units) {        elem = MochiKit.DOM.getElement(elem);        if (typeof(units) == 'undefined') {            units = 'px';        }        MochiKit.DOM.updateNodeAttributes(elem, {'style': {            'width': newSize.w + units,             'height': newSize.h + units        }});    },        setElementPosition: function (elem, newPos/* optional */, units) {        elem = MochiKit.DOM.getElement(elem);        if (typeof(units) == 'undefined') {            units = 'px';        }        MochiKit.DOM.updateNodeAttributes(elem, {'style': {            'left': newPos.x + units,            'top': newPos.y + units        }});    },        currentWindow: function () {        return MochiKit.DOM._window;    },    currentDocument: function () {        return MochiKit.DOM._document;    },    withWindow: function (win, func) {        var self = MochiKit.DOM;        var oldDoc = self._document;        var oldWin = self._win;        var rval;        try {            self._window = win;            self._document = win.document;            rval = func();        } catch (e) {            self._window = oldWin;            self._document = oldDoc;            throw e;        }        self._window = oldWin;        self._document = oldDoc;        return rval;    },    formContents: function (elem/* = document */) {        var names = [];

⌨️ 快捷键说明

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