# Yahoo! UI Library

### node 3.3.0

Yahoo! UI Library > node > node-region.js (source view)
Search:
Filters Show Private Show Protected Show Deprecated

    /**
     * Returns a region object for the node
     * @config region
     * @for Node
     * @type Node
     */
    Y.Node.ATTRS.region = {
        getter: function() {
            var node = Y.Node.getDOMNode(this),
                region;

            if (node && !node.tagName) {
                if (node.nodeType === 9) { // document
                    node = node.documentElement;
                }
            }
            if (node.alert) {
                region = Y.DOM.viewportRegion(node);
            } else {
                region = Y.DOM.region(node);
            }
            return region;
        }
    };

    /**
     * Returns a region object for the node's viewport
     * @config viewportRegion
     * @type Node
     */
    Y.Node.ATTRS.viewportRegion = {
        getter: function() {
            return Y.DOM.viewportRegion(Y.Node.getDOMNode(this));
        }
    };

    Y.Node.importMethod(Y.DOM, 'inViewportRegion');

    // these need special treatment to extract 2nd node arg
    /**
     * Compares the intersection of the node with another node or region
     * @method intersect
     * @for Node
     * @param {Node|Object} node2 The node or region to compare with.
     * @param {Object} altRegion An alternate region to use (rather than this node's).
     * @return {Object} An object representing the intersection of the regions.
     */
    Y.Node.prototype.intersect = function(node2, altRegion) {
        var node1 = Y.Node.getDOMNode(this);
        if (Y.instanceOf(node2, Y.Node)) { // might be a region object
            node2 = Y.Node.getDOMNode(node2);
        }
        return Y.DOM.intersect(node1, node2, altRegion);
    };

    /**
     * Determines whether or not the node is within the giving region.
     * @method inRegion
     * @param {Node|Object} node2 The node or region to compare with.
     * @param {Boolean} all Whether or not all of the node must be in the region.
     * @param {Object} altRegion An alternate region to use (rather than this node's).
     * @return {Object} An object representing the intersection of the regions.
     */
    Y.Node.prototype.inRegion = function(node2, all, altRegion) {
        var node1 = Y.Node.getDOMNode(this);
        if (Y.instanceOf(node2, Y.Node)) { // might be a region object
            node2 = Y.Node.getDOMNode(node2);
        }
        return Y.DOM.inRegion(node1, node2, all, altRegion);
    };

Copyright © 2011 Yahoo! Inc. All rights reserved.