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

📄 dom-debug.js

📁 很棒的在线教学系统
💻 JS
📖 第 1 页 / 共 4 页
字号:
         * @param {HTMLDocument} document (optional) The document to get the scroll value of         * @return {Int}  The amount that the document is scrolled to the left         */        getDocumentScrollLeft: function(doc) {            doc = doc || document;            return Math.max(doc.documentElement.scrollLeft, doc.body.scrollLeft);        },         /**         * Returns the top scroll value of the document          * @method getDocumentScrollTop         * @param {HTMLDocument} document (optional) The document to get the scroll value of         * @return {Int}  The amount that the document is scrolled to the top         */        getDocumentScrollTop: function(doc) {            doc = doc || document;            return Math.max(doc.documentElement.scrollTop, doc.body.scrollTop);        },        /**         * Inserts the new node as the previous sibling of the reference node          * @method insertBefore         * @param {String | HTMLElement} newNode The node to be inserted         * @param {String | HTMLElement} referenceNode The node to insert the new node before          * @return {HTMLElement} The node that was inserted (or null if insert fails)          */        insertBefore: function(newNode, referenceNode) {            newNode = Y.Dom.get(newNode);             referenceNode = Y.Dom.get(referenceNode);                         if (!newNode || !referenceNode || !referenceNode.parentNode) {                YAHOO.log('insertAfter failed: missing or invalid arg(s)', 'error', 'Dom');                return null;            }                   return referenceNode.parentNode.insertBefore(newNode, referenceNode);         },        /**         * Inserts the new node as the next sibling of the reference node          * @method insertAfter         * @param {String | HTMLElement} newNode The node to be inserted         * @param {String | HTMLElement} referenceNode The node to insert the new node after          * @return {HTMLElement} The node that was inserted (or null if insert fails)          */        insertAfter: function(newNode, referenceNode) {            newNode = Y.Dom.get(newNode);             referenceNode = Y.Dom.get(referenceNode);                         if (!newNode || !referenceNode || !referenceNode.parentNode) {                YAHOO.log('insertAfter failed: missing or invalid arg(s)', 'error', 'Dom');                return null;            }                   if (referenceNode.nextSibling) {                return referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);             } else {                return referenceNode.parentNode.appendChild(newNode);            }        },        /**         * Creates a Region based on the viewport relative to the document.          * @method getClientRegion         * @return {Region} A Region object representing the viewport which accounts for document scroll         */        getClientRegion: function() {            var t = Y.Dom.getDocumentScrollTop(),                l = Y.Dom.getDocumentScrollLeft(),                r = Y.Dom.getViewportWidth() + l,                b = Y.Dom.getViewportHeight() + t;            return new Y.Region(t, r, b, l);        }    };        var getXY = function() {        if (document.documentElement.getBoundingClientRect) { // IE            return function(el) {                var box = el.getBoundingClientRect(),                    round = Math.round;                var rootNode = el.ownerDocument;                return [round(box.left + Y.Dom.getDocumentScrollLeft(rootNode)), round(box.top +                        Y.Dom.getDocumentScrollTop(rootNode))];            };        } else {            return function(el) { // manually calculate by crawling up offsetParents                var pos = [el.offsetLeft, el.offsetTop];                var parentNode = el.offsetParent;                // safari: subtract body offsets if el is abs (or any offsetParent), unless body is offsetParent                var accountForBody = (isSafari &&                        Y.Dom.getStyle(el, 'position') == 'absolute' &&                        el.offsetParent == el.ownerDocument.body);                if (parentNode != el) {                    while (parentNode) {                        pos[0] += parentNode.offsetLeft;                        pos[1] += parentNode.offsetTop;                        if (!accountForBody && isSafari &&                                 Y.Dom.getStyle(parentNode,'position') == 'absolute' ) {                             accountForBody = true;                        }                        parentNode = parentNode.offsetParent;                    }                }                if (accountForBody) { //safari doubles in this case                    pos[0] -= el.ownerDocument.body.offsetLeft;                    pos[1] -= el.ownerDocument.body.offsetTop;                }                 parentNode = el.parentNode;                // account for any scrolled ancestors                while ( parentNode.tagName && !patterns.ROOT_TAG.test(parentNode.tagName) )                 {                    if (parentNode.scrollTop || parentNode.scrollLeft) {                        pos[0] -= parentNode.scrollLeft;                        pos[1] -= parentNode.scrollTop;                    }                                        parentNode = parentNode.parentNode;                 }                return pos;            };        }    }() // NOTE: Executing for loadtime branching})();/** * A region is a representation of an object on a grid.  It is defined * by the top, right, bottom, left extents, so is rectangular by default.  If  * other shapes are required, this class could be extended to support it. * @namespace YAHOO.util * @class Region * @param {Int} t the top extent * @param {Int} r the right extent * @param {Int} b the bottom extent * @param {Int} l the left extent * @constructor */YAHOO.util.Region = function(t, r, b, l) {    /**     * The region's top extent     * @property top     * @type Int     */    this.top = t;        /**     * The region's top extent as index, for symmetry with set/getXY     * @property 1     * @type Int     */    this[1] = t;    /**     * The region's right extent     * @property right     * @type int     */    this.right = r;    /**     * The region's bottom extent     * @property bottom     * @type Int     */    this.bottom = b;    /**     * The region's left extent     * @property left     * @type Int     */    this.left = l;        /**     * The region's left extent as index, for symmetry with set/getXY     * @property 0     * @type Int     */    this[0] = l;};/** * Returns true if this region contains the region passed in * @method contains * @param  {Region}  region The region to evaluate * @return {Boolean}        True if the region is contained with this region,  *                          else false */YAHOO.util.Region.prototype.contains = function(region) {    return ( region.left   >= this.left   &&              region.right  <= this.right  &&              region.top    >= this.top    &&              region.bottom <= this.bottom    );    // this.logger.debug("does " + this + " contain " + region + " ... " + ret);};/** * Returns the area of the region * @method getArea * @return {Int} the region's area */YAHOO.util.Region.prototype.getArea = function() {    return ( (this.bottom - this.top) * (this.right - this.left) );};/** * Returns the region where the passed in region overlaps with this one * @method intersect * @param  {Region} region The region that intersects * @return {Region}        The overlap region, or null if there is no overlap */YAHOO.util.Region.prototype.intersect = function(region) {    var t = Math.max( this.top,    region.top    );    var r = Math.min( this.right,  region.right  );    var b = Math.min( this.bottom, region.bottom );    var l = Math.max( this.left,   region.left   );        if (b >= t && r >= l) {        return new YAHOO.util.Region(t, r, b, l);    } else {        return null;    }};/** * Returns the region representing the smallest region that can contain both * the passed in region and this region. * @method union * @param  {Region} region The region that to create the union with * @return {Region}        The union region */YAHOO.util.Region.prototype.union = function(region) {    var t = Math.min( this.top,    region.top    );    var r = Math.max( this.right,  region.right  );    var b = Math.max( this.bottom, region.bottom );    var l = Math.min( this.left,   region.left   );    return new YAHOO.util.Region(t, r, b, l);};/** * toString * @method toString * @return string the region properties */YAHOO.util.Region.prototype.toString = function() {    return ( "Region {"    +             "top: "       + this.top    +              ", right: "   + this.right  +              ", bottom: "  + this.bottom +              ", left: "    + this.left   +              "}" );};/** * Returns a region that is occupied by the DOM element * @method getRegion * @param  {HTMLElement} el The element * @return {Region}         The region that the element occupies * @static */YAHOO.util.Region.getRegion = function(el) {    var p = YAHOO.util.Dom.getXY(el);    var t = p[1];    var r = p[0] + el.offsetWidth;    var b = p[1] + el.offsetHeight;    var l = p[0];    return new YAHOO.util.Region(t, r, b, l);};//////////////////////////////////////////////////////////////////////////////** * A point is a region that is special in that it represents a single point on  * the grid. * @namespace YAHOO.util * @class Point * @param {Int} x The X position of the point * @param {Int} y The Y position of the point * @constructor * @extends YAHOO.util.Region */YAHOO.util.Point = function(x, y) {   if (YAHOO.lang.isArray(x)) { // accept input from Dom.getXY, Event.getXY, etc.      y = x[1]; // dont blow away x yet      x = x[0];   }       /**     * The X position of the point, which is also the right, left and index zero (for Dom.getXY symmetry)     * @property x     * @type Int     */    this.x = this.right = this.left = this[0] = x;         /**     * The Y position of the point, which is also the top, bottom and index one (for Dom.getXY symmetry)     * @property y     * @type Int     */    this.y = this.top = this.bottom = this[1] = y;};YAHOO.util.Point.prototype = new YAHOO.util.Region();YAHOO.register("dom", YAHOO.util.Dom, {version: "2.6.0", build: "1321"});

⌨️ 快捷键说明

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