Upgrade to ExtJS 3.0.3 - Released 10/11/2009
[extjs.git] / docs / source / ext-base-dom.html
1 <html>
2 <head>
3   <title>The source code</title>
4     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
6 </head>
7 <body  onload="prettyPrint();">
8     <pre class="prettyprint lang-js">/*!
9  * Ext JS Library 3.0.3
10  * Copyright(c) 2006-2009 Ext JS, LLC
11  * licensing@extjs.com
12  * http://www.extjs.com/license
13  */
14 (function(){\r
15         var doc = document,\r
16                 isCSS1 = doc.compatMode == "CSS1Compat",\r
17                 MAX = Math.max,         \r
18         ROUND = Math.round,\r
19                 PARSEINT = parseInt;\r
20                 \r
21         Ext.lib.Dom = {\r
22             isAncestor : function(p, c) {\r
23                     var ret = false;\r
24                         \r
25                         p = Ext.getDom(p);\r
26                         c = Ext.getDom(c);\r
27                         if (p && c) {\r
28                                 if (p.contains) {\r
29                                         return p.contains(c);\r
30                                 } else if (p.compareDocumentPosition) {\r
31                                         return !!(p.compareDocumentPosition(c) & 16);\r
32                                 } else {\r
33                                         while (c = c.parentNode) {\r
34                                                 ret = c == p || ret;                                    \r
35                                         }\r
36                                 }                   \r
37                         }       \r
38                         return ret;\r
39                 },\r
40                 \r
41         getViewWidth : function(full) {\r
42             return full ? this.getDocumentWidth() : this.getViewportWidth();\r
43         },\r
44 \r
45         getViewHeight : function(full) {\r
46             return full ? this.getDocumentHeight() : this.getViewportHeight();\r
47         },\r
48 \r
49         getDocumentHeight: function() {            \r
50             return MAX(!isCSS1 ? doc.body.scrollHeight : doc.documentElement.scrollHeight, this.getViewportHeight());\r
51         },\r
52 \r
53         getDocumentWidth: function() {            \r
54             return MAX(!isCSS1 ? doc.body.scrollWidth : doc.documentElement.scrollWidth, this.getViewportWidth());\r
55         },\r
56 \r
57         getViewportHeight: function(){\r
58                 return Ext.isIE ? \r
59                            (Ext.isStrict ? doc.documentElement.clientHeight : doc.body.clientHeight) :\r
60                            self.innerHeight;\r
61         },\r
62 \r
63         getViewportWidth : function() {\r
64                 return !Ext.isStrict && !Ext.isOpera ? doc.body.clientWidth :\r
65                            Ext.isIE ? doc.documentElement.clientWidth : self.innerWidth;\r
66         },\r
67         \r
68         getY : function(el) {\r
69             return this.getXY(el)[1];\r
70         },\r
71 \r
72         getX : function(el) {\r
73             return this.getXY(el)[0];\r
74         },\r
75 \r
76         getXY : function(el) {\r
77             var p, \r
78                 pe, \r
79                 b,\r
80                 bt, \r
81                 bl,     \r
82                 dbd,            \r
83                 x = 0,\r
84                 y = 0, \r
85                 scroll,\r
86                 hasAbsolute, \r
87                 bd = (doc.body || doc.documentElement),\r
88                 ret = [0,0];\r
89                 \r
90             el = Ext.getDom(el);\r
91 \r
92             if(el != bd){\r
93                     if (el.getBoundingClientRect) {\r
94                         b = el.getBoundingClientRect();\r
95                         scroll = fly(document).getScroll();\r
96                         ret = [ROUND(b.left + scroll.left), ROUND(b.top + scroll.top)];\r
97                     } else {  \r
98                             p = el;             \r
99                             hasAbsolute = fly(el).isStyle("position", "absolute");\r
100                 \r
101                             while (p) {\r
102                                     pe = fly(p);                \r
103                                 x += p.offsetLeft;\r
104                                 y += p.offsetTop;\r
105                 \r
106                                 hasAbsolute = hasAbsolute || pe.isStyle("position", "absolute");\r
107                                                 \r
108                                 if (Ext.isGecko) {                                  \r
109                                     y += bt = PARSEINT(pe.getStyle("borderTopWidth"), 10) || 0;\r
110                                     x += bl = PARSEINT(pe.getStyle("borderLeftWidth"), 10) || 0;        \r
111                 \r
112                                     if (p != el && !pe.isStyle('overflow','visible')) {\r
113                                         x += bl;\r
114                                         y += bt;\r
115                                     }\r
116                                 }\r
117                                 p = p.offsetParent;\r
118                             }\r
119                 \r
120                             if (Ext.isSafari && hasAbsolute) {\r
121                                 x -= bd.offsetLeft;\r
122                                 y -= bd.offsetTop;\r
123                             }\r
124                 \r
125                             if (Ext.isGecko && !hasAbsolute) {\r
126                                 dbd = fly(bd);\r
127                                 x += PARSEINT(dbd.getStyle("borderLeftWidth"), 10) || 0;\r
128                                 y += PARSEINT(dbd.getStyle("borderTopWidth"), 10) || 0;\r
129                             }\r
130                 \r
131                             p = el.parentNode;\r
132                             while (p && p != bd) {\r
133                                 if (!Ext.isOpera || (p.tagName != 'TR' && !fly(p).isStyle("display", "inline"))) {\r
134                                     x -= p.scrollLeft;\r
135                                     y -= p.scrollTop;\r
136                                 }\r
137                                 p = p.parentNode;\r
138                             }\r
139                             ret = [x,y];\r
140                     }\r
141                 }\r
142             return ret\r
143         },\r
144 \r
145         setXY : function(el, xy) {\r
146             (el = Ext.fly(el, '_setXY')).position();\r
147             \r
148             var pts = el.translatePoints(xy),\r
149                 style = el.dom.style,\r
150                 pos;                    \r
151             \r
152             for (pos in pts) {              \r
153                     if(!isNaN(pts[pos])) style[pos] = pts[pos] + "px"\r
154             }\r
155         },\r
156 \r
157         setX : function(el, x) {\r
158             this.setXY(el, [x, false]);\r
159         },\r
160 \r
161         setY : function(el, y) {\r
162             this.setXY(el, [false, y]);\r
163         }\r
164     };\r
165 })();</pre>
166 </body>
167 </html>