PageRenderTime 45ms CodeModel.GetById 12ms app.highlight 27ms RepoModel.GetById 2ms app.codeStats 0ms

/hippo/src/main/webapp/ext/src/adapter/core/ext-base-dom.js

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