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