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