76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav GlassYUI.add('dom-screen', function(Y) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass(function(Y) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass/**
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Adds position and region management functionality to DOM.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @module dom
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @submodule dom-screen
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @for DOM
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glassvar DOCUMENT_ELEMENT = 'documentElement',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass COMPAT_MODE = 'compatMode',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass POSITION = 'position',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass FIXED = 'fixed',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass RELATIVE = 'relative',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass LEFT = 'left',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass TOP = 'top',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass _BACK_COMPAT = 'BackCompat',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass MEDIUM = 'medium',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass BORDER_LEFT_WIDTH = 'borderLeftWidth',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass BORDER_TOP_WIDTH = 'borderTopWidth',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass GET_BOUNDING_CLIENT_RECT = 'getBoundingClientRect',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass GET_COMPUTED_STYLE = 'getComputedStyle',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Y_DOM = Y.DOM,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // TODO: how about thead/tbody/tfoot/tr?
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // TODO: does caption matter?
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass RE_TABLE = /^t(?:able|d|h)$/i,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass SCROLL_NODE;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glassif (Y.UA.ie) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (Y.config.doc[COMPAT_MODE] !== 'BackCompat') {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass SCROLL_NODE = DOCUMENT_ELEMENT;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass } else {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass SCROLL_NODE = 'body';
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass}
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav GlassY.mix(Y_DOM, {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
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 */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass winHeight: function(node) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var h = Y_DOM._getWinSize(node).height;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Y.log('winHeight returning ' + h, 'info', 'dom-screen');
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return h;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
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 */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass winWidth: function(node) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var w = Y_DOM._getWinSize(node).width;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Y.log('winWidth returning ' + w, 'info', 'dom-screen');
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return w;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Document height
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method docHeight
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @return {Number} The current height of the document.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass docHeight: function(node) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var h = Y_DOM._getDocSize(node).height;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Y.log('docHeight returning ' + h, 'info', 'dom-screen');
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return Math.max(h, Y_DOM._getWinSize(node).height);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Document width
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method docWidth
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @return {Number} The current width of the document.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass docWidth: function(node) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var w = Y_DOM._getDocSize(node).width;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Y.log('docWidth returning ' + w, 'info', 'dom-screen');
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return Math.max(w, Y_DOM._getWinSize(node).width);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
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 */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass docScrollX: function(node, doc) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass doc = doc || (node) ? Y_DOM._getDoc(node) : Y.config.doc; // perf optimization
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var dv = doc.defaultView,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass pageOffset = (dv) ? dv.pageXOffset : 0;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return Math.max(doc[DOCUMENT_ELEMENT].scrollLeft, doc.body.scrollLeft, pageOffset);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
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 */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass docScrollY: function(node, doc) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass doc = doc || (node) ? Y_DOM._getDoc(node) : Y.config.doc; // perf optimization
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var dv = doc.defaultView,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass pageOffset = (dv) ? dv.pageYOffset : 0;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return Math.max(doc[DOCUMENT_ELEMENT].scrollTop, doc.body.scrollTop, pageOffset);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
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
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass TODO: test inDocument/display?
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
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,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass scrollLeft,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass scrollTop,
4f2a5ab26d156b92bf936f5410341e2ccded9f03Matt Sweeney mode,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass box,
b85c7570068184d30c8487fe52ac67e0b1ddc35cMatt Sweeney offX,
b85c7570068184d30c8487fe52ac67e0b1ddc35cMatt Sweeney offY,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass doc,
4f2a5ab26d156b92bf936f5410341e2ccded9f03Matt Sweeney win,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass inDoc,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass rootNode;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (node && node.tagName) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass doc = node.ownerDocument;
a29cd60efb0b68d07e836d6165b623c81665421aMatt Sweeney mode = doc[COMPAT_MODE];
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
4f2a5ab26d156b92bf936f5410341e2ccded9f03Matt Sweeney if (mode !== _BACK_COMPAT) {
4f2a5ab26d156b92bf936f5410341e2ccded9f03Matt Sweeney rootNode = doc[DOCUMENT_ELEMENT];
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass } else {
4f2a5ab26d156b92bf936f5410341e2ccded9f03Matt Sweeney rootNode = doc.body;
4f2a5ab26d156b92bf936f5410341e2ccded9f03Matt Sweeney }
4f2a5ab26d156b92bf936f5410341e2ccded9f03Matt Sweeney
4f2a5ab26d156b92bf936f5410341e2ccded9f03Matt Sweeney // inline inDoc check for perf
a29cd60efb0b68d07e836d6165b623c81665421aMatt Sweeney if (rootNode.contains) {
a29cd60efb0b68d07e836d6165b623c81665421aMatt Sweeney inDoc = rootNode.contains(node);
a29cd60efb0b68d07e836d6165b623c81665421aMatt Sweeney } else {
a29cd60efb0b68d07e836d6165b623c81665421aMatt Sweeney inDoc = Y.DOM.contains(rootNode, node);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (inDoc) {
4f2a5ab26d156b92bf936f5410341e2ccded9f03Matt Sweeney win = doc.defaultView;
4f2a5ab26d156b92bf936f5410341e2ccded9f03Matt Sweeney
4f2a5ab26d156b92bf936f5410341e2ccded9f03Matt Sweeney // inline scroll calc for perf
4f2a5ab26d156b92bf936f5410341e2ccded9f03Matt Sweeney if (win && 'pageXOffset' in win) {
4f2a5ab26d156b92bf936f5410341e2ccded9f03Matt Sweeney scrollLeft = win.pageXOffset;
4f2a5ab26d156b92bf936f5410341e2ccded9f03Matt Sweeney scrollTop = win.pageYOffset;
4f2a5ab26d156b92bf936f5410341e2ccded9f03Matt Sweeney } else {
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 }
4f2a5ab26d156b92bf936f5410341e2ccded9f03Matt Sweeney
4f2a5ab26d156b92bf936f5410341e2ccded9f03Matt Sweeney if (Y.UA.ie) { // IE < 8, quirks, or compatMode
4f2a5ab26d156b92bf936f5410341e2ccded9f03Matt Sweeney if (!doc.documentMode || doc.documentMode < 8 || mode === _BACK_COMPAT) {
4f2a5ab26d156b92bf936f5410341e2ccded9f03Matt Sweeney offX = rootNode.clientLeft;
4f2a5ab26d156b92bf936f5410341e2ccded9f03Matt Sweeney offY = rootNode.clientTop;
4f2a5ab26d156b92bf936f5410341e2ccded9f03Matt Sweeney }
4f2a5ab26d156b92bf936f5410341e2ccded9f03Matt Sweeney }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass box = node[GET_BOUNDING_CLIENT_RECT]();
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass xy = [box.left, box.top];
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
b85c7570068184d30c8487fe52ac67e0b1ddc35cMatt Sweeney if (offX || offY) {
b85c7570068184d30c8487fe52ac67e0b1ddc35cMatt Sweeney xy[0] -= offX;
b85c7570068184d30c8487fe52ac67e0b1ddc35cMatt Sweeney xy[1] -= offY;
b85c7570068184d30c8487fe52ac67e0b1ddc35cMatt Sweeney
b85c7570068184d30c8487fe52ac67e0b1ddc35cMatt Sweeney }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if ((scrollTop || scrollLeft)) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (!Y.UA.ios || (Y.UA.ios >= 4.2)) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass xy[0] += scrollLeft;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass xy[1] += scrollTop;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass } else {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass xy = Y_DOM._getOffset(node);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return xy;
733d14a9d3c26dfffceb08589598dc5bc1a5070eLuke Smith };
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass } else {
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 doc,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass parentNode,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass bCheck,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass scrollTop,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass scrollLeft;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (node) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (Y_DOM.inDoc(node)) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass xy = [node.offsetLeft, node.offsetTop];
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass doc = node.ownerDocument;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass parentNode = node;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // TODO: refactor with !! or just falsey
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass bCheck = ((Y.UA.gecko || Y.UA.webkit > 519) ? true : false);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // TODO: worth refactoring for TOP/LEFT only?
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass while ((parentNode = parentNode.offsetParent)) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass xy[0] += parentNode.offsetLeft;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass xy[1] += parentNode.offsetTop;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (bCheck) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass xy = Y_DOM._calcBorders(parentNode, xy);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // account for any scrolled ancestors
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (Y_DOM.getStyle(node, POSITION) != FIXED) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass parentNode = node;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass while ((parentNode = parentNode.parentNode)) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass scrollTop = parentNode.scrollTop;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass scrollLeft = parentNode.scrollLeft;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
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 xy = Y_DOM._calcBorders(parentNode, xy);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (scrollTop || scrollLeft) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass xy[0] -= scrollLeft;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass xy[1] -= scrollTop;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass xy[0] += Y_DOM.docScrollX(node, doc);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass xy[1] += Y_DOM.docScrollY(node, doc);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass } else {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass //Fix FIXED position -- add scrollbars
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass xy[0] += Y_DOM.docScrollX(node, doc);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass xy[1] += Y_DOM.docScrollY(node, doc);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass } else {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass xy = Y_DOM._getOffset(node);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return xy;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass };
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }(),// NOTE: Executing for loadtime branching
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
733d14a9d3c26dfffceb08589598dc5bc1a5070eLuke Smith /**
733d14a9d3c26dfffceb08589598dc5bc1a5070eLuke Smith Gets the width of vertical scrollbars on overflowed containers in the body
733d14a9d3c26dfffceb08589598dc5bc1a5070eLuke Smith content.
733d14a9d3c26dfffceb08589598dc5bc1a5070eLuke Smith
733d14a9d3c26dfffceb08589598dc5bc1a5070eLuke Smith @method getScrollbarWidth
733d14a9d3c26dfffceb08589598dc5bc1a5070eLuke Smith @return {Number} Pixel width of a scrollbar in the current browser
733d14a9d3c26dfffceb08589598dc5bc1a5070eLuke Smith **/
733d14a9d3c26dfffceb08589598dc5bc1a5070eLuke Smith getScrollbarWidth: Y.cached(function () {
733d14a9d3c26dfffceb08589598dc5bc1a5070eLuke Smith var doc = Y.config.doc,
733d14a9d3c26dfffceb08589598dc5bc1a5070eLuke Smith testNode = doc.createElement('div'),
733d14a9d3c26dfffceb08589598dc5bc1a5070eLuke Smith body = doc.getElementsByTagName('body')[0],
733d14a9d3c26dfffceb08589598dc5bc1a5070eLuke Smith // 0.1 because cached doesn't support falsy refetch values
733d14a9d3c26dfffceb08589598dc5bc1a5070eLuke Smith width = 0.1;
733d14a9d3c26dfffceb08589598dc5bc1a5070eLuke Smith
733d14a9d3c26dfffceb08589598dc5bc1a5070eLuke Smith if (body) {
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 body.insertBefore(testNode, body.firstChild);
733d14a9d3c26dfffceb08589598dc5bc1a5070eLuke Smith width = testNode.offsetWidth - testNode.clientWidth;
733d14a9d3c26dfffceb08589598dc5bc1a5070eLuke Smith
733d14a9d3c26dfffceb08589598dc5bc1a5070eLuke Smith body.removeChild(testNode);
733d14a9d3c26dfffceb08589598dc5bc1a5070eLuke Smith }
733d14a9d3c26dfffceb08589598dc5bc1a5070eLuke Smith
733d14a9d3c26dfffceb08589598dc5bc1a5070eLuke Smith return width;
733d14a9d3c26dfffceb08589598dc5bc1a5070eLuke Smith }, null, 0.1),
733d14a9d3c26dfffceb08589598dc5bc1a5070eLuke Smith
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
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 */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass getX: function(node) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return Y_DOM.getXY(node)[0];
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
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 */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass getY: function(node) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return Y_DOM.getXY(node)[1];
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
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 */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass setXY: function(node, xy, noRetry) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var setStyle = Y_DOM.setStyle,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass pos,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass delta,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass newXY,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass currentXY;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (node && xy) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass pos = Y_DOM.getStyle(node, POSITION);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass delta = Y_DOM._getOffset(node);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (pos == 'static') { // default to relative
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass pos = RELATIVE;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass setStyle(node, POSITION, pos);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass currentXY = Y_DOM.getXY(node);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (xy[0] !== null) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass setStyle(node, LEFT, xy[0] - currentXY[0] + delta[0] + 'px');
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (xy[1] !== null) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass setStyle(node, TOP, xy[1] - currentXY[1] + delta[1] + 'px');
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (!noRetry) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass newXY = Y_DOM.getXY(node);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (newXY[0] !== xy[0] || newXY[1] !== xy[1]) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Y_DOM.setXY(node, xy, true);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Y.log('setXY setting position to ' + xy, 'info', 'dom-screen');
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass } else {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Y.log('setXY failed to set ' + node + ' to ' + xy, 'info', 'dom-screen');
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
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 */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass setX: function(node, x) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return Y_DOM.setXY(node, [x, null]);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
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 */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass setY: function(node, y) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return Y_DOM.setXY(node, [null, y]);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
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 */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass swapXY: function(node, otherNode) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var xy = Y_DOM.getXY(node);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Y_DOM.setXY(node, Y_DOM.getXY(otherNode));
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Y_DOM.setXY(otherNode, xy);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass _calcBorders: function(node, xy2) {
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 if (Y.UA.gecko) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (RE_TABLE.test(node.tagName)) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass t = 0;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass l = 0;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass xy2[0] += l;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass xy2[1] += t;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return xy2;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass _getWinSize: function(node, doc) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass doc = doc || (node) ? Y_DOM._getDoc(node) : Y.config.doc;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var win = doc.defaultView || doc.parentWindow,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass mode = doc[COMPAT_MODE],
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass h = win.innerHeight,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass w = win.innerWidth,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass root = doc[DOCUMENT_ELEMENT];
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if ( mode && !Y.UA.opera ) { // IE, Gecko
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (mode != 'CSS1Compat') { // Quirks
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass root = doc.body;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass h = root.clientHeight;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass w = root.clientWidth;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return { height: h, width: w };
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass _getDocSize: function(node) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var doc = (node) ? Y_DOM._getDoc(node) : Y.config.doc,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass root = doc[DOCUMENT_ELEMENT];
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (doc[COMPAT_MODE] != 'CSS1Compat') {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass root = doc.body;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return { height: root.scrollHeight, width: root.scrollWidth };
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass});
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass})(Y);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass(function(Y) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glassvar TOP = 'top',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass RIGHT = 'right',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass BOTTOM = 'bottom',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass LEFT = 'left',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass getOffsets = function(r1, r2) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var t = Math.max(r1[TOP], r2[TOP]),
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass r = Math.min(r1[RIGHT], r2[RIGHT]),
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass b = Math.min(r1[BOTTOM], r2[BOTTOM]),
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass l = Math.max(r1[LEFT], r2[LEFT]),
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass ret = {};
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass ret[TOP] = t;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass ret[RIGHT] = r;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass ret[BOTTOM] = b;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass ret[LEFT] = l;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return ret;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass DOM = Y.DOM;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav GlassY.mix(DOM, {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Returns an Object literal containing the following about this element: (top, right, bottom, left)
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @for DOM
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)
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass region: function(node) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var xy = DOM.getXY(node),
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass ret = false;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (node && xy) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass ret = DOM._getRegion(
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass xy[1], // top
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass xy[0] + node.offsetWidth, // right
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass xy[1] + node.offsetHeight, // bottom
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass xy[0] // left
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass );
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return ret;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
8647b185da5af4753fd23c77eafc9770e629bb36Dav Glass * Find the intersect information for the passed nodes.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method intersect
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @for DOM
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 */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass intersect: function(node, node2, altRegion) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var r = altRegion || DOM.region(node), region = {},
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass n = node2,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass off;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (n.tagName) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass region = DOM.region(n);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass } else if (Y.Lang.isObject(node2)) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass region = node2;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass } else {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return false;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass off = getOffsets(region, r);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass top: off[TOP],
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass right: off[RIGHT],
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass bottom: off[BOTTOM],
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass left: off[LEFT],
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass area: ((off[BOTTOM] - off[TOP]) * (off[RIGHT] - off[LEFT])),
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass yoff: ((off[BOTTOM] - off[TOP])),
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass xoff: (off[RIGHT] - off[LEFT]),
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass inRegion: DOM.inRegion(node, node2, false, altRegion)
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass };
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Check if any part of this node is in the passed region
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method inRegion
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @for DOM
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 */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass inRegion: function(node, node2, all, altRegion) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var region = {},
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass r = altRegion || DOM.region(node),
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass n = node2,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass off;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (n.tagName) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass region = DOM.region(n);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass } else if (Y.Lang.isObject(node2)) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass region = node2;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass } else {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return false;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (all) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return (
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass r[LEFT] >= region[LEFT] &&
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass r[RIGHT] <= region[RIGHT] &&
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass r[TOP] >= region[TOP] &&
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass r[BOTTOM] <= region[BOTTOM] );
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass } else {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass off = getOffsets(region, r);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (off[BOTTOM] >= off[TOP] && off[RIGHT] >= off[LEFT]) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return true;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass } else {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return false;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Check if any part of this element is in the viewport
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method inViewportRegion
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @for DOM
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 */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass inViewportRegion: function(node, all, altRegion) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return DOM.inRegion(node, DOM.viewportRegion(node), all, altRegion);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass _getRegion: function(t, r, b, l) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var region = {};
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass region[TOP] = region[1] = t;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass region[LEFT] = region[0] = l;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass region[BOTTOM] = b;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass region[RIGHT] = r;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass region.width = region[RIGHT] - region[LEFT];
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass region.height = region[BOTTOM] - region[TOP];
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return region;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
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 * @for DOM
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @return {Object} Object literal containing the following about the visible region of the viewport: (top, right, bottom, left)
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass viewportRegion: function(node) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass node = node || Y.config.doc.documentElement;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var ret = false,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass scrollX,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass scrollY;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (node) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass scrollX = DOM.docScrollX(node);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass scrollY = DOM.docScrollY(node);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass ret = DOM._getRegion(scrollY, // top
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass DOM.winWidth(node) + scrollX, // right
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass scrollY + DOM.winHeight(node), // bottom
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass scrollX); // left
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return ret;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass});
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass})(Y);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney}, '@VERSION@' ,{requires:['dom-base', 'dom-style']});