[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 /* 2 YUI 3.17.2 (build 9c3c78e) 3 Copyright 2014 Yahoo! Inc. All rights reserved. 4 Licensed under the BSD License. 5 http://yuilibrary.com/license/ 6 */ 7 8 YUI.add('node-screen', function (Y, NAME) { 9 10 /** 11 * Extended Node interface for managing regions and screen positioning. 12 * Adds support for positioning elements and normalizes window size and scroll detection. 13 * @module node 14 * @submodule node-screen 15 */ 16 17 // these are all "safe" returns, no wrapping required 18 Y.each([ 19 /** 20 * Returns the inner width of the viewport (exludes scrollbar). 21 * @config winWidth 22 * @for Node 23 * @type {Number} 24 */ 25 'winWidth', 26 27 /** 28 * Returns the inner height of the viewport (exludes scrollbar). 29 * @config winHeight 30 * @type {Number} 31 */ 32 'winHeight', 33 34 /** 35 * Document width 36 * @config docWidth 37 * @type {Number} 38 */ 39 'docWidth', 40 41 /** 42 * Document height 43 * @config docHeight 44 * @type {Number} 45 */ 46 'docHeight', 47 48 /** 49 * Pixel distance the page has been scrolled horizontally 50 * @config docScrollX 51 * @type {Number} 52 */ 53 'docScrollX', 54 55 /** 56 * Pixel distance the page has been scrolled vertically 57 * @config docScrollY 58 * @type {Number} 59 */ 60 'docScrollY' 61 ], 62 function(name) { 63 Y.Node.ATTRS[name] = { 64 getter: function() { 65 var args = Array.prototype.slice.call(arguments); 66 args.unshift(Y.Node.getDOMNode(this)); 67 68 return Y.DOM[name].apply(this, args); 69 } 70 }; 71 } 72 ); 73 74 Y.Node.ATTRS.scrollLeft = { 75 getter: function() { 76 var node = Y.Node.getDOMNode(this); 77 return ('scrollLeft' in node) ? node.scrollLeft : Y.DOM.docScrollX(node); 78 }, 79 80 setter: function(val) { 81 var node = Y.Node.getDOMNode(this); 82 if (node) { 83 if ('scrollLeft' in node) { 84 node.scrollLeft = val; 85 } else if (node.document || node.nodeType === 9) { 86 Y.DOM._getWin(node).scrollTo(val, Y.DOM.docScrollY(node)); // scroll window if win or doc 87 } 88 } else { 89 } 90 } 91 }; 92 93 Y.Node.ATTRS.scrollTop = { 94 getter: function() { 95 var node = Y.Node.getDOMNode(this); 96 return ('scrollTop' in node) ? node.scrollTop : Y.DOM.docScrollY(node); 97 }, 98 99 setter: function(val) { 100 var node = Y.Node.getDOMNode(this); 101 if (node) { 102 if ('scrollTop' in node) { 103 node.scrollTop = val; 104 } else if (node.document || node.nodeType === 9) { 105 Y.DOM._getWin(node).scrollTo(Y.DOM.docScrollX(node), val); // scroll window if win or doc 106 } 107 } else { 108 } 109 } 110 }; 111 112 Y.Node.importMethod(Y.DOM, [ 113 /** 114 * Gets the current position of the node in page coordinates. 115 * @method getXY 116 * @for Node 117 * @return {Array} The XY position of the node 118 */ 119 'getXY', 120 121 /** 122 * Set the position of the node in page coordinates, regardless of how the node is positioned. 123 * @method setXY 124 * @param {Array} xy Contains X & Y values for new position (coordinates are page-based) 125 * @chainable 126 */ 127 'setXY', 128 129 /** 130 * Gets the current position of the node in page coordinates. 131 * @method getX 132 * @return {Number} The X position of the node 133 */ 134 'getX', 135 136 /** 137 * Set the position of the node in page coordinates, regardless of how the node is positioned. 138 * @method setX 139 * @param {Number} x X value for new position (coordinates are page-based) 140 * @chainable 141 */ 142 'setX', 143 144 /** 145 * Gets the current position of the node in page coordinates. 146 * @method getY 147 * @return {Number} The Y position of the node 148 */ 149 'getY', 150 151 /** 152 * Set the position of the node in page coordinates, regardless of how the node is positioned. 153 * @method setY 154 * @param {Number} y Y value for new position (coordinates are page-based) 155 * @chainable 156 */ 157 'setY', 158 159 /** 160 * Swaps the XY position of this node with another node. 161 * @method swapXY 162 * @param {Node | HTMLElement} otherNode The node to swap with. 163 * @chainable 164 */ 165 'swapXY' 166 ]); 167 168 /** 169 * @module node 170 * @submodule node-screen 171 */ 172 173 /** 174 * Returns a region object for the node 175 * @config region 176 * @for Node 177 * @type Node 178 */ 179 Y.Node.ATTRS.region = { 180 getter: function() { 181 var node = this.getDOMNode(), 182 region; 183 184 if (node && !node.tagName) { 185 if (node.nodeType === 9) { // document 186 node = node.documentElement; 187 } 188 } 189 if (Y.DOM.isWindow(node)) { 190 region = Y.DOM.viewportRegion(node); 191 } else { 192 region = Y.DOM.region(node); 193 } 194 return region; 195 } 196 }; 197 198 /** 199 * Returns a region object for the node's viewport 200 * @config viewportRegion 201 * @type Node 202 */ 203 Y.Node.ATTRS.viewportRegion = { 204 getter: function() { 205 return Y.DOM.viewportRegion(Y.Node.getDOMNode(this)); 206 } 207 }; 208 209 Y.Node.importMethod(Y.DOM, 'inViewportRegion'); 210 211 // these need special treatment to extract 2nd node arg 212 /** 213 * Compares the intersection of the node with another node or region 214 * @method intersect 215 * @for Node 216 * @param {Node|Object} node2 The node or region to compare with. 217 * @param {Object} altRegion An alternate region to use (rather than this node's). 218 * @return {Object} An object representing the intersection of the regions. 219 */ 220 Y.Node.prototype.intersect = function(node2, altRegion) { 221 var node1 = Y.Node.getDOMNode(this); 222 if (Y.instanceOf(node2, Y.Node)) { // might be a region object 223 node2 = Y.Node.getDOMNode(node2); 224 } 225 return Y.DOM.intersect(node1, node2, altRegion); 226 }; 227 228 /** 229 * Determines whether or not the node is within the given region. 230 * @method inRegion 231 * @param {Node|Object} node2 The node or region to compare with. 232 * @param {Boolean} all Whether or not all of the node must be in the region. 233 * @param {Object} altRegion An alternate region to use (rather than this node's). 234 * @return {Boolean} True if in region, false if not. 235 */ 236 Y.Node.prototype.inRegion = function(node2, all, altRegion) { 237 var node1 = Y.Node.getDOMNode(this); 238 if (Y.instanceOf(node2, Y.Node)) { // might be a region object 239 node2 = Y.Node.getDOMNode(node2); 240 } 241 return Y.DOM.inRegion(node1, node2, all, altRegion); 242 }; 243 244 245 }, '3.17.2', {"requires": ["dom-screen", "node-base"]});
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |