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

📄 dom-debug.js

📁 国外的人才求职招聘最新版
💻 JS
📖 第 1 页 / 共 4 页
字号:
         * @method inDocument                  * @param {String | HTMLElement} el The element to search for         * @return {Boolean} Whether or not the element is present in the current document         */        inDocument: function(el) {            var f = function(el) { // safari contains fails for body so crawl up                if (isSafari) {                    while (el = el.parentNode) { // note assignment                        if (el == document.documentElement) {                            return true;                        }                    }                    return false;                }                return this.isAncestor(document.documentElement, el);            };                        return Y.Dom.batch(el, f, Y.Dom, true);        },                /**         * Returns a array of HTMLElements that pass the test applied by supplied boolean method.         * For optimized performance, include a tag and/or root node when possible.         * @method getElementsBy         * @param {Function} method - A boolean method for testing elements which receives the element as its only argument.         * @param {String} tag (optional) The tag name of the elements being collected         * @param {String | HTMLElement} root (optional) The HTMLElement or an ID to use as the starting point          * @param {Function} apply (optional) A function to apply to each element when found          * @return {Array} Array of HTMLElements         */        getElementsBy: function(method, tag, root, apply) {            tag = tag || '*';            root = (root) ? Y.Dom.get(root) : null || document;             if (!root) {                return [];            }            var nodes = [],                elements = root.getElementsByTagName(tag);                        for (var i = 0, len = elements.length; i < len; ++i) {                if ( method(elements[i]) ) {                    nodes[nodes.length] = elements[i];                    if (apply) {                        apply(elements[i]);                    }                }            }            YAHOO.log('getElementsBy returning ' + nodes, 'info', 'Dom');                        return nodes;        },                /**         * Returns an the method(s) return value(s).         * The method is called with the element(s) as the first arg, and the optional param as the second ( method(el, o) ).         * @method batch         * @param {String | HTMLElement | Array} el (optional) An element or array of elements to apply the method to         * @param {Function} method The method to apply to the element(s)         * @param {Any} o (optional) An optional arg that is passed to the supplied method         * @param {Boolean} override (optional) Whether or not to override the scope of "method" with "o"         * @return {Any | Array} The return value(s) from the supplied methods         */        batch: function(el, method, o, override) {            el = (el && el.tagName) ? el : Y.Dom.get(el); // skip get() when possible            if (!el || !method) {                YAHOO.log('batch failed: invalid arguments', 'error', 'Dom');                return false;            }             var scope = (override) ? o : window;                        if (el.tagName || (!el.item && !el.slice)) { // not a collection or array, just run the method                return method.call(scope, el, o);            }             var collection = [];                        for (var i = 0, len = el.length; i < len; ++i) {                collection[collection.length] = method.call(scope, el[i], o);            }                        return collection;        },                /**         * Returns the height of the document.         * @method getDocumentHeight         * @return {Int} The height of the actual document (which includes the body and its margin).         */        getDocumentHeight: function() {            var scrollHeight = (document.compatMode != 'CSS1Compat') ? document.body.scrollHeight : document.documentElement.scrollHeight;            var h = Math.max(scrollHeight, Y.Dom.getViewportHeight());            YAHOO.log('getDocumentHeight returning ' + h, 'info', 'Dom');            return h;        },                /**         * Returns the width of the document.         * @method getDocumentWidth         * @return {Int} The width of the actual document (which includes the body and its margin).         */        getDocumentWidth: function() {            var scrollWidth = (document.compatMode != 'CSS1Compat') ? document.body.scrollWidth : document.documentElement.scrollWidth;            var w = Math.max(scrollWidth, Y.Dom.getViewportWidth());            YAHOO.log('getDocumentWidth returning ' + w, 'info', 'Dom');            return w;        },        /**         * Returns the current height of the viewport.         * @method getViewportHeight         * @return {Int} The height of the viewable area of the page (excludes scrollbars).         */        getViewportHeight: function() {            var height = self.innerHeight; // Safari, Opera            var mode = document.compatMode;                    if ( (mode || isIE) && !isOpera ) { // IE, Gecko                height = (mode == 'CSS1Compat') ?                        document.documentElement.clientHeight : // Standards                        document.body.clientHeight; // Quirks            }                    YAHOO.log('getViewportHeight returning ' + height, 'info', 'Dom');            return height;        },                /**         * Returns the current width of the viewport.         * @method getViewportWidth         * @return {Int} The width of the viewable area of the page (excludes scrollbars).         */                getViewportWidth: function() {            var width = self.innerWidth;  // Safari            var mode = document.compatMode;                        if (mode || isIE) { // IE, Gecko, Opera                width = (mode == 'CSS1Compat') ?                        document.documentElement.clientWidth : // Standards                        document.body.clientWidth; // Quirks            }            YAHOO.log('getViewportWidth returning ' + width, 'info', 'Dom');            return width;        },       /**         * Returns the nearest ancestor that passes the test applied by supplied boolean method.         * For performance reasons, IDs are not accepted and argument validation omitted.         * @method getAncestorBy         * @param {HTMLElement} node The HTMLElement to use as the starting point          * @param {Function} method - A boolean method for testing elements which receives the element as its only argument.         * @return {Object} HTMLElement or null if not found         */        getAncestorBy: function(node, method) {            while (node = node.parentNode) { // NOTE: assignment                if ( testElement(node, method) ) {                    YAHOO.log('getAncestorBy returning ' + node, 'info', 'Dom');                    return node;                }            }             YAHOO.log('getAncestorBy returning null (no ancestor passed test)', 'error', 'Dom');            return null;        },                /**         * Returns the nearest ancestor with the given className.         * @method getAncestorByClassName         * @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point          * @param {String} className         * @return {Object} HTMLElement         */        getAncestorByClassName: function(node, className) {            node = Y.Dom.get(node);            if (!node) {                YAHOO.log('getAncestorByClassName failed: invalid node argument', 'error', 'Dom');                return null;            }            var method = function(el) { return Y.Dom.hasClass(el, className); };            return Y.Dom.getAncestorBy(node, method);        },        /**         * Returns the nearest ancestor with the given tagName.         * @method getAncestorByTagName         * @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point          * @param {String} tagName         * @return {Object} HTMLElement         */        getAncestorByTagName: function(node, tagName) {            node = Y.Dom.get(node);            if (!node) {                YAHOO.log('getAncestorByTagName failed: invalid node argument', 'error', 'Dom');                return null;            }            var method = function(el) {                 return el.tagName && el.tagName.toUpperCase() == tagName.toUpperCase();            };            return Y.Dom.getAncestorBy(node, method);        },        /**         * Returns the previous sibling that is an HTMLElement.          * For performance reasons, IDs are not accepted and argument validation omitted.         * Returns the nearest HTMLElement sibling if no method provided.         * @method getPreviousSiblingBy         * @param {HTMLElement} node The HTMLElement to use as the starting point          * @param {Function} method A boolean function used to test siblings         * that receives the sibling node being tested as its only argument         * @return {Object} HTMLElement or null if not found         */        getPreviousSiblingBy: function(node, method) {            while (node) {                node = node.previousSibling;                if ( testElement(node, method) ) {                    return node;                }            }            return null;        },         /**         * Returns the previous sibling that is an HTMLElement          * @method getPreviousSibling         * @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point          * @return {Object} HTMLElement or null if not found         */        getPreviousSibling: function(node) {            node = Y.Dom.get(node);            if (!node) {                YAHOO.log('getPreviousSibling failed: invalid node argument', 'error', 'Dom');                return null;            }            return Y.Dom.getPreviousSiblingBy(node);        },         /**         * Returns the next HTMLElement sibling that passes the boolean method.          * For performance reasons, IDs are not accepted and argument validation omitted.         * Returns the nearest HTMLElement sibling if no method provided.         * @method getNextSiblingBy         * @param {HTMLElement} node The HTMLElement to use as the starting point          * @param {Function} method A boolean function used to test siblings         * that receives the sibling node being tested as its only argument         * @return {Object} HTMLElement or null if not found         */        getNextSiblingBy: function(node, method) {            while (node) {                node = node.nextSibling;                if ( testElement(node, method) ) {                    return node;                }            }            return null;        },         /**         * Returns the next sibling that is an HTMLElement          * @method getNextSibling         * @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point          * @return {Object} HTMLElement or null if not found         */        getNextSibling: function(node) {            node = Y.Dom.get(node);            if (!node) {                YAHOO.log('getNextSibling failed: invalid node argument', 'error', 'Dom');                return null;            }            return Y.Dom.getNextSiblingBy(node);        },         /**         * Returns the first HTMLElement child that passes the test method.          * @method getFirstChildBy         * @param {HTMLElement} node The HTMLElement to use as the starting point          * @param {Function} method A boolean function used to test children         * that receives the node being tested as its only argument         * @return {Object} HTMLElement or null if not found         */        getFirstChildBy: function(node, method) {            var child = ( testElement(node.firstChild, method) ) ? node.firstChild : null;            return child || Y.Dom.getNextSiblingBy(node.firstChild, method);        },         /**         * Returns the first HTMLElement child.          * @method getFirstChild         * @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point          * @return {Object} HTMLElement or null if not found         */        getFirstChild: function(node, method) {            node = Y.Dom.get(node);            if (!node) {                YAHOO.log('getFirstChild failed: invalid node argument', 'error', 'Dom');                return null;            }            return Y.Dom.getFirstChildBy(node);        },         /**         * Returns the last HTMLElement child that passes the test method.          * @method getLastChildBy         * @param {HTMLElement} node The HTMLElement to use as the starting point          * @param {Function} method A boolean function used to test children         * that receives the node being tested as its only argument

⌨️ 快捷键说明

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