Skip to content

Commit 7ea17a0

Browse files
committed
Hack-fix for Element.getXY in Chrome 12.
1 parent cdf8de1 commit 7ea17a0

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

template/resources/docs.js

+83
Original file line numberDiff line numberDiff line change
@@ -684,3 +684,86 @@ Ext.Ajax.on('requestcomplete', function(ajax, xhr, o){
684684
urchinTracker(o.url);
685685
}
686686
});
687+
688+
// Override Ext.lib.Dom.getXY
689+
//
690+
// For some reason el.getBoundingClientRect does not work correctly in Chrome 12.
691+
// As a hack-solution, don't use it in Chrome at all.
692+
(function() {
693+
var doc = document,
694+
isCSS1 = doc.compatMode == "CSS1Compat",
695+
MAX = Math.max,
696+
ROUND = Math.round,
697+
PARSEINT = parseInt;
698+
var fly = Ext.fly;
699+
700+
Ext.lib.Dom.getXY = function(el) {
701+
var p,
702+
pe,
703+
b,
704+
bt,
705+
bl,
706+
dbd,
707+
x = 0,
708+
y = 0,
709+
scroll,
710+
hasAbsolute,
711+
bd = (doc.body || doc.documentElement),
712+
ret = [0,0];
713+
714+
el = Ext.getDom(el);
715+
716+
if(el != bd){
717+
// Don't use getBoundingClientRect in Chrome
718+
if (el.getBoundingClientRect && !Ext.isChrome) {
719+
b = el.getBoundingClientRect();
720+
scroll = fly(document).getScroll();
721+
ret = [ROUND(b.left + scroll.left), ROUND(b.top + scroll.top)];
722+
} else {
723+
p = el;
724+
hasAbsolute = fly(el).isStyle("position", "absolute");
725+
726+
while (p) {
727+
pe = fly(p);
728+
x += p.offsetLeft;
729+
y += p.offsetTop;
730+
731+
hasAbsolute = hasAbsolute || pe.isStyle("position", "absolute");
732+
733+
if (Ext.isGecko) {
734+
y += bt = PARSEINT(pe.getStyle("borderTopWidth"), 10) || 0;
735+
x += bl = PARSEINT(pe.getStyle("borderLeftWidth"), 10) || 0;
736+
737+
if (p != el && !pe.isStyle('overflow','visible')) {
738+
x += bl;
739+
y += bt;
740+
}
741+
}
742+
p = p.offsetParent;
743+
}
744+
745+
if (Ext.isSafari && hasAbsolute) {
746+
x -= bd.offsetLeft;
747+
y -= bd.offsetTop;
748+
}
749+
750+
if (Ext.isGecko && !hasAbsolute) {
751+
dbd = fly(bd);
752+
x += PARSEINT(dbd.getStyle("borderLeftWidth"), 10) || 0;
753+
y += PARSEINT(dbd.getStyle("borderTopWidth"), 10) || 0;
754+
}
755+
756+
p = el.parentNode;
757+
while (p && p != bd) {
758+
if (!Ext.isOpera || (p.tagName != 'TR' && !fly(p).isStyle("display", "inline"))) {
759+
x -= p.scrollLeft;
760+
y -= p.scrollTop;
761+
}
762+
p = p.parentNode;
763+
}
764+
ret = [x,y];
765+
}
766+
}
767+
return ret;
768+
};
769+
})();

0 commit comments

Comments
 (0)