76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass(function(Y) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Adds position and region management functionality to DOM.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @module dom
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @submodule dom-screen
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass GET_BOUNDING_CLIENT_RECT = 'getBoundingClientRect',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // TODO: does caption matter?
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Returns the inner height of the viewport (exludes scrollbar).
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method winHeight
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @return {Number} The current height of the viewport.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Y.log('winHeight returning ' + h, 'info', 'dom-screen');
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Returns the inner width of the viewport (exludes scrollbar).
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method winWidth
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @return {Number} The current width of the viewport.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Y.log('winWidth returning ' + w, 'info', 'dom-screen');
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Document height
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method docHeight
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @return {Number} The current height of the document.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Y.log('docHeight returning ' + h, 'info', 'dom-screen');
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return Math.max(h, Y_DOM._getWinSize(node).height);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Document width
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method docWidth
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @return {Number} The current width of the document.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Y.log('docWidth returning ' + w, 'info', 'dom-screen');
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return Math.max(w, Y_DOM._getWinSize(node).width);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Amount page has been scroll horizontally
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method docScrollX
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @return {Number} The current amount the screen is scrolled horizontally.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass doc = doc || (node) ? Y_DOM._getDoc(node) : Y.config.doc; // perf optimization
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return Math.max(doc[DOCUMENT_ELEMENT].scrollLeft, doc.body.scrollLeft, pageOffset);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Amount page has been scroll vertically
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method docScrollY
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @return {Number} The current amount the screen is scrolled vertically.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass doc = doc || (node) ? Y_DOM._getDoc(node) : Y.config.doc; // perf optimization
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return Math.max(doc[DOCUMENT_ELEMENT].scrollTop, doc.body.scrollTop, pageOffset);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Gets the current position of an element based on page coordinates.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Element must be part of the DOM tree to have page coordinates
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * (display:none or elements not appended return false).
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method getXY
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param element The target element
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @return {Array} The XY position of the element
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass getXY: function() {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (Y.config.doc[DOCUMENT_ELEMENT][GET_BOUNDING_CLIENT_RECT]) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return function(node) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var xy = null,
4f2a5ab26d156b92bf936f5410341e2ccded9f03Matt Sweeney // inline inDoc check for perf
4f2a5ab26d156b92bf936f5410341e2ccded9f03Matt Sweeney // inline scroll calc for perf
4f2a5ab26d156b92bf936f5410341e2ccded9f03Matt Sweeney scrollLeft = (SCROLL_NODE) ? doc[SCROLL_NODE].scrollLeft : Y_DOM.docScrollX(node, doc);
4f2a5ab26d156b92bf936f5410341e2ccded9f03Matt Sweeney scrollTop = (SCROLL_NODE) ? doc[SCROLL_NODE].scrollTop : Y_DOM.docScrollY(node, doc);
4f2a5ab26d156b92bf936f5410341e2ccded9f03Matt Sweeney if (Y.UA.ie) { // IE < 8, quirks, or compatMode
4f2a5ab26d156b92bf936f5410341e2ccded9f03Matt Sweeney if (!doc.documentMode || doc.documentMode < 8 || mode === _BACK_COMPAT) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return function(node) { // manually calculate by crawling up offsetParents
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass //Calculate the Top and Left border sizes (assumes pixels)
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var xy = null,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // TODO: refactor with !! or just falsey
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass bCheck = ((Y.UA.gecko || Y.UA.webkit > 519) ? true : false);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // TODO: worth refactoring for TOP/LEFT only?
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // account for any scrolled ancestors
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass //Firefox does something funky with borders when overflow is not visible.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (Y.UA.gecko && (Y_DOM.getStyle(parentNode, 'overflow') !== 'visible')) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass //Fix FIXED position -- add scrollbars
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }(),// NOTE: Executing for loadtime branching
733d14a9d3c26dfffceb08589598dc5bc1a5070eLuke Smith Gets the width of vertical scrollbars on overflowed containers in the body
733d14a9d3c26dfffceb08589598dc5bc1a5070eLuke Smith @method getScrollbarWidth
733d14a9d3c26dfffceb08589598dc5bc1a5070eLuke Smith @return {Number} Pixel width of a scrollbar in the current browser
733d14a9d3c26dfffceb08589598dc5bc1a5070eLuke Smith // 0.1 because cached doesn't support falsy refetch values
733d14a9d3c26dfffceb08589598dc5bc1a5070eLuke Smith testNode.style.cssText = "position:absolute;visibility:hidden;overflow:scroll;width:20px;";
733d14a9d3c26dfffceb08589598dc5bc1a5070eLuke Smith testNode.appendChild(doc.createElement('p')).style.height = '1px';
733d14a9d3c26dfffceb08589598dc5bc1a5070eLuke Smith width = testNode.offsetWidth - testNode.clientWidth;
733d14a9d3c26dfffceb08589598dc5bc1a5070eLuke Smith }, null, 0.1),
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Gets the current X position of an element based on page coordinates.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Element must be part of the DOM tree to have page coordinates
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * (display:none or elements not appended return false).
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method getX
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param element The target element
8647b185da5af4753fd23c77eafc9770e629bb36Dav Glass * @return {Number} The X position of the element
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Gets the current Y position of an element based on page coordinates.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Element must be part of the DOM tree to have page coordinates
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * (display:none or elements not appended return false).
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method getY
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param element The target element
8647b185da5af4753fd23c77eafc9770e629bb36Dav Glass * @return {Number} The Y position of the element
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Set the position of an html element in page coordinates.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method setXY
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param element The target element
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {Array} xy Contains X & Y values for new position (coordinates are page-based)
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {Boolean} noRetry By default we try and set the position a second time if the first fails
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass setStyle(node, LEFT, xy[0] - currentXY[0] + delta[0] + 'px');
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass setStyle(node, TOP, xy[1] - currentXY[1] + delta[1] + 'px');
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Y.log('setXY setting position to ' + xy, 'info', 'dom-screen');
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Y.log('setXY failed to set ' + node + ' to ' + xy, 'info', 'dom-screen');
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Set the X position of an html element in page coordinates, regardless of how the element is positioned.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * The element(s) must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method setX
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param element The target element
8647b185da5af4753fd23c77eafc9770e629bb36Dav Glass * @param {Number} x The X values for new position (coordinates are page-based)
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Set the Y position of an html element in page coordinates, regardless of how the element is positioned.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * The element(s) must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method setY
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param element The target element
8647b185da5af4753fd23c77eafc9770e629bb36Dav Glass * @param {Number} y The Y values for new position (coordinates are page-based)
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method swapXY
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @description Swap the xy position with another node
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {Node} node The node to swap with
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {Node} otherNode The other node to swap with
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @return {Node}
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var t = parseInt(Y_DOM[GET_COMPUTED_STYLE](node, BORDER_TOP_WIDTH), 10) || 0,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass l = parseInt(Y_DOM[GET_COMPUTED_STYLE](node, BORDER_LEFT_WIDTH), 10) || 0;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass doc = doc || (node) ? Y_DOM._getDoc(node) : Y.config.doc;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var doc = (node) ? Y_DOM._getDoc(node) : Y.config.doc,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return { height: root.scrollHeight, width: root.scrollWidth };
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass(function(Y) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Returns an Object literal containing the following about this element: (top, right, bottom, left)
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method region
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {HTMLElement} element The DOM element.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @return {Object} Object literal containing the following about this element: (top, right, bottom, left)
8647b185da5af4753fd23c77eafc9770e629bb36Dav Glass * Find the intersect information for the passed nodes.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method intersect
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {HTMLElement} element The first element
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {HTMLElement | Object} element2 The element or region to check the interect with
8647b185da5af4753fd23c77eafc9770e629bb36Dav Glass * @param {Object} altRegion An object literal containing the region for the first element if we already have the data (for performance e.g. DragDrop)
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @return {Object} Object literal containing the following intersection data: (top, right, bottom, left, area, yoff, xoff, inRegion)
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var r = altRegion || DOM.region(node), region = {},
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return false;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass area: ((off[BOTTOM] - off[TOP]) * (off[RIGHT] - off[LEFT])),
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass inRegion: DOM.inRegion(node, node2, false, altRegion)
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Check if any part of this node is in the passed region
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method inRegion
8647b185da5af4753fd23c77eafc9770e629bb36Dav Glass * @param {Object} node The node to get the region from
8647b185da5af4753fd23c77eafc9770e629bb36Dav Glass * @param {Object} node2 The second node to get the region from or an Object literal of the region
2b212c64f5ff71daad07c5ec7d8a0664b3256c28Dav Glass * @param {Boolean} all Should all of the node be inside the region
8647b185da5af4753fd23c77eafc9770e629bb36Dav Glass * @param {Object} altRegion An object literal containing the region for this node if we already have the data (for performance e.g. DragDrop)
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @return {Boolean} True if in region, false if not.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return false;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (off[BOTTOM] >= off[TOP] && off[RIGHT] >= off[LEFT]) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return true;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return false;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Check if any part of this element is in the viewport
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method inViewportRegion
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {HTMLElement} element The DOM element.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {Boolean} all Should all of the node be inside the region
8647b185da5af4753fd23c77eafc9770e629bb36Dav Glass * @param {Object} altRegion An object literal containing the region for this node if we already have the data (for performance e.g. DragDrop)
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @return {Boolean} True if in region, false if not.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass inViewportRegion: function(node, all, altRegion) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return DOM.inRegion(node, DOM.viewportRegion(node), all, altRegion);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass _getRegion: function(t, r, b, l) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Returns an Object literal containing the following about the visible region of viewport: (top, right, bottom, left)
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method viewportRegion
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @return {Object} Object literal containing the following about the visible region of the viewport: (top, right, bottom, left)
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var ret = false,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney}, '@VERSION@' ,{requires:['dom-base', 'dom-style']});