PageRenderTime 44ms CodeModel.GetById 30ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/ext-4.1.0_b3/src/core/dom/Element.static-more.js

https://bitbucket.org/srogerf/javascript
JavaScript | 159 lines | 128 code | 26 blank | 5 comment | 33 complexity | 1b3d58fca44cc9a7cb4f3c46403c5b0e MD5 | raw file
  1/**
  2 * @class Ext.dom.Element
  3 */
  4(function(){
  5    var doc = document,
  6        isCSS1 = doc.compatMode == "CSS1Compat",
  7        ELEMENT = Ext.Element,
  8        fly = function(el){
  9            if (!_fly) {
 10                _fly = new Ext.Element.Flyweight();
 11            }
 12            _fly.dom = el;
 13            return _fly;
 14        }, _fly;
 15
 16    Ext.apply(ELEMENT, {
 17
 18        getViewWidth : function(full) {
 19            return full ? ELEMENT.getDocumentWidth() : ELEMENT.getViewportWidth();
 20        },
 21
 22        getViewHeight : function(full) {
 23            return full ? ELEMENT.getDocumentHeight() : ELEMENT.getViewportHeight();
 24        },
 25
 26        getDocumentHeight: function() {
 27            return Math.max(!isCSS1 ? doc.body.scrollHeight : doc.documentElement.scrollHeight, ELEMENT.getViewportHeight());
 28        },
 29
 30        getDocumentWidth: function() {
 31            return Math.max(!isCSS1 ? doc.body.scrollWidth : doc.documentElement.scrollWidth, ELEMENT.getViewportWidth());
 32        },
 33
 34        getViewportHeight: function(){
 35            return Ext.isIE ?
 36                   (Ext.isStrict ? doc.documentElement.clientHeight : doc.body.clientHeight) :
 37                   self.innerHeight;
 38        },
 39
 40        getViewportWidth : function() {
 41            return (!Ext.isStrict && !Ext.isOpera) ? doc.body.clientWidth :
 42                   Ext.isIE ? doc.documentElement.clientWidth : self.innerWidth;
 43        },
 44
 45        getY : function(el) {
 46            return ELEMENT.getXY(el)[1];
 47        },
 48
 49        getX : function(el) {
 50            return ELEMENT.getXY(el)[0];
 51        },
 52
 53        getOffsetParent: function (el) {
 54            el = Ext.getDom(el);
 55            try {
 56                // accessing offsetParent can throw "Unspecified Error" in IE6-8 (not 9)
 57                return el.offsetParent;
 58            } catch (e) {
 59                var body = document.body; // safe bet, unless...
 60                return (el == body) ? null : body;
 61            }
 62        },
 63
 64        getXY : function(el) {
 65            var p,
 66                pe,
 67                b,
 68                bt,
 69                bl,
 70                dbd,
 71                x = 0,
 72                y = 0,
 73                scroll,
 74                hasAbsolute,
 75                bd = (doc.body || doc.documentElement),
 76                ret;
 77
 78            el = Ext.getDom(el);
 79
 80            if(el != bd){
 81                hasAbsolute = fly(el).isStyle("position", "absolute");
 82
 83                if (el.getBoundingClientRect) {
 84                    try {
 85                        b = el.getBoundingClientRect();
 86                        scroll = fly(document).getScroll();
 87                        ret = [ Math.round(b.left + scroll.left), Math.round(b.top + scroll.top) ];
 88                    } catch (e) {
 89                        // IE6-8 can also throw from getBoundingClientRect...
 90                    }
 91                }
 92
 93                if (!ret) {
 94                    for (p = el; p; p = ELEMENT.getOffsetParent(p)) {
 95                        pe = fly(p);
 96                        x += p.offsetLeft;
 97                        y += p.offsetTop;
 98
 99                        hasAbsolute = hasAbsolute || pe.isStyle("position", "absolute");
100
101                        if (Ext.isGecko) {
102                            y += bt = parseInt(pe.getStyle("borderTopWidth"), 10) || 0;
103                            x += bl = parseInt(pe.getStyle("borderLeftWidth"), 10) || 0;
104
105                            if (p != el && !pe.isStyle('overflow','visible')) {
106                                x += bl;
107                                y += bt;
108                            }
109                        }
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 || [0,0];
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])) {
146                    style[pos] = pts[pos] + "px";
147                }
148            }
149        },
150
151        setX : function(el, x) {
152            ELEMENT.setXY(el, [x, false]);
153        },
154
155        setY : function(el, y) {
156            ELEMENT.setXY(el, [false, y]);
157        }
158    });
159})();