2
YUI 3.13.0 (build 508226d)
3
Copyright 2013 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
8
YUI.add('node-screen', function (Y, NAME) {
11
* Extended Node interface for managing regions and screen positioning.
12
* Adds support for positioning elements and normalizes window size and scroll detection.
14
* @submodule node-screen
17
// these are all "safe" returns, no wrapping required
20
* Returns the inner width of the viewport (exludes scrollbar).
28
* Returns the inner height of the viewport (exludes scrollbar).
49
* Pixel distance the page has been scrolled horizontally
56
* Pixel distance the page has been scrolled vertically
63
Y.Node.ATTRS[name] = {
65
var args = Array.prototype.slice.call(arguments);
66
args.unshift(Y.Node.getDOMNode(this));
68
return Y.DOM[name].apply(this, args);
74
Y.Node.ATTRS.scrollLeft = {
76
var node = Y.Node.getDOMNode(this);
77
return ('scrollLeft' in node) ? node.scrollLeft : Y.DOM.docScrollX(node);
80
setter: function(val) {
81
var node = Y.Node.getDOMNode(this);
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
93
Y.Node.ATTRS.scrollTop = {
95
var node = Y.Node.getDOMNode(this);
96
return ('scrollTop' in node) ? node.scrollTop : Y.DOM.docScrollY(node);
99
setter: function(val) {
100
var node = Y.Node.getDOMNode(this);
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
112
Y.Node.importMethod(Y.DOM, [
114
* Gets the current position of the node in page coordinates.
117
* @return {Array} The XY position of the node
122
* Set the position of the node in page coordinates, regardless of how the node is positioned.
124
* @param {Array} xy Contains X & Y values for new position (coordinates are page-based)
130
* Gets the current position of the node in page coordinates.
132
* @return {Int} The X position of the node
137
* Set the position of the node in page coordinates, regardless of how the node is positioned.
139
* @param {Int} x X value for new position (coordinates are page-based)
145
* Gets the current position of the node in page coordinates.
147
* @return {Int} The Y position of the node
152
* Set the position of the node in page coordinates, regardless of how the node is positioned.
154
* @param {Int} y Y value for new position (coordinates are page-based)
160
* Swaps the XY position of this node with another node.
162
* @param {Node | HTMLElement} otherNode The node to swap with.
170
* @submodule node-screen
174
* Returns a region object for the node
179
Y.Node.ATTRS.region = {
181
var node = this.getDOMNode(),
184
if (node && !node.tagName) {
185
if (node.nodeType === 9) { // document
186
node = node.documentElement;
189
if (Y.DOM.isWindow(node)) {
190
region = Y.DOM.viewportRegion(node);
192
region = Y.DOM.region(node);
199
* Returns a region object for the node's viewport
200
* @config viewportRegion
203
Y.Node.ATTRS.viewportRegion = {
205
return Y.DOM.viewportRegion(Y.Node.getDOMNode(this));
209
Y.Node.importMethod(Y.DOM, 'inViewportRegion');
211
// these need special treatment to extract 2nd node arg
213
* Compares the intersection of the node with another node or region
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.
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);
225
return Y.DOM.intersect(node1, node2, altRegion);
229
* Determines whether or not the node is within the giving region.
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.
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);
241
return Y.DOM.inRegion(node1, node2, all, altRegion);
245
}, '3.13.0', {"requires": ["dom-screen", "node-base"]});