]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/javascript/yui3/build/node/node-screen.js
Release 6.2.0beta4
[Github/sugarcrm.git] / jssource / src_files / include / javascript / yui3 / build / node / node-screen.js
1 /*
2 Copyright (c) 2009, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.net/yui/license.txt
5 version: 3.0.0
6 build: 1549
7 */
8 YUI.add('node-screen', function(Y) {
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 {Int}
24      */
25     'winWidth',
26
27     /**
28      * Returns the inner height of the viewport (exludes scrollbar). 
29      * @config winHeight
30      * @type {Int}
31      */
32     'winHeight',
33
34     /**
35      * Document width 
36      * @config winHeight
37      * @type {Int}
38      */
39     'docWidth',
40
41     /**
42      * Document height 
43      * @config docHeight
44      * @type {Int}
45      */
46     'docHeight',
47
48     /**
49      * Amount page has been scroll vertically 
50      * @config docScrollX
51      * @type {Int}
52      */
53     'docScrollX',
54
55     /**
56      * Amount page has been scroll horizontally 
57      * @config docScrollY
58      * @type {Int}
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 {Int} 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 {Int} 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 {Int} 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 {Int} y Y value for new position (coordinates are page-based)
155  * @chainable
156  */
157     'setY'
158 ]);
159
160 /**
161  * Returns a region object for the node 
162  * @config region
163  * @for Node
164  * @type Node
165  */
166 Y.Node.ATTRS.region = {
167     getter: function() {
168         var node = Y.Node.getDOMNode(this);
169         if (node && !node.tagName) {
170             if (node.nodeType === 9) { // document
171                 node = node.documentElement;
172             } else if (node.alert) { // window
173                 node = node.document.documentElement;
174             }
175         }
176         return Y.DOM.region(node);
177     }
178 };
179     
180 /**
181  * Returns a region object for the node's viewport 
182  * @config viewportRegion
183  * @type Node
184  */
185 Y.Node.ATTRS.viewportRegion = {
186     getter: function() {
187         return Y.DOM.viewportRegion(Y.Node.getDOMNode(this));
188     }
189 };
190
191 Y.Node.importMethod(Y.DOM, 'inViewportRegion');
192
193 // these need special treatment to extract 2nd node arg
194 /**
195  * Compares the intersection of the node with another node or region 
196  * @method intersect         
197  * @for Node
198  * @param {Node|Object} node2 The node or region to compare with.
199  * @param {Object} altRegion An alternate region to use (rather than this node's). 
200  * @return {Object} An object representing the intersection of the regions. 
201  */
202 Y.Node.prototype.intersect = function(node2, altRegion) {
203     var node1 = Y.Node.getDOMNode(this);
204     if (node2 instanceof Y.Node) { // might be a region object
205         node2 = Y.Node.getDOMNode(node2);
206     }
207     return Y.DOM.intersect(node1, node2, altRegion); 
208 };
209
210 /**
211  * Determines whether or not the node is within the giving region.
212  * @method inRegion         
213  * @param {Node|Object} node2 The node or region to compare with.
214  * @param {Boolean} all Whether or not all of the node must be in the region. 
215  * @param {Object} altRegion An alternate region to use (rather than this node's). 
216  * @return {Object} An object representing the intersection of the regions. 
217  */
218 Y.Node.prototype.inRegion = function(node2, all, altRegion) {
219     var node1 = Y.Node.getDOMNode(this);
220     if (node2 instanceof Y.Node) { // might be a region object
221         node2 = Y.Node.getDOMNode(node2);
222     }
223     return Y.DOM.inRegion(node1, node2, all, altRegion); 
224 };
225
226
227 }, '3.0.0' ,{requires:['dom-screen']});