Skip to content

Instantly share code, notes, and snippets.

@martindrapeau
Last active May 17, 2024 07:14
Show Gist options
  • Save martindrapeau/8183099 to your computer and use it in GitHub Desktop.
Save martindrapeau/8183099 to your computer and use it in GitHub Desktop.
Patches Telerik Tooltip control in IE10 which fails with Javascript error
/*
* Patches Telerik Tooltip control in IE10 which fails with this Javascript error:
*
* SCRIPT5007: Unable to get property 'documentElement' of undefined or null reference
* Telerik.Web.UI.WebResource.axd, line 151 character 2
*
* Solution is to redefine the bugged function and replace a.document.documentElement
* with (a.document || a.ownerDocument).documentElement, thus avoiding a paid upgrade.
*
* To use, include this script after Telerik's.
*
*
* Alternate solution if unable to load this Javascript file is to force the browser in
* IE9 mode with META:
* <meta http-equiv="X-UA-Compatible" content="IE=9">
* In some cases that is not enough. Fallback is to ask users to manually go in IE9 mode.
*
*/
window.$telerik.getLocation = window.TelerikCommonScripts.getLocation = Telerik.Web.CommonScripts.getLocation = function (a) {
var v = a && a.ownerDocument ? a.ownerDocument : document;
if (a === v.documentElement) {
return new Sys.UI.Point(0, 0);
}
if (Sys.Browser.agent == Sys.Browser.InternetExplorer) {
if (a.window === a || a.nodeType === 9 || !a.getClientRects || !a.getBoundingClientRect || a.parentElement == null) {
return new Sys.UI.Point(0, 0);
}
var F = a.getClientRects();
if (!F || !F.length) {
return new Sys.UI.Point(0, 0);
}
var j = F[0];
var G = 0;
var z = 0;
var y = false;
try {
y = a.ownerDocument.parentWindow.frameElement;
} catch (f) {
y = true;
}
if (y) {
var c = a.getBoundingClientRect();
if (!c) {
return new Sys.UI.Point(0, 0);
}
var D = j.left;
var s = j.top;
for (var l = 1; l < F.length; l++) {
var o = F[l];
if (o.left < D) {
D = o.left;
}
if (o.top < s) {
s = o.top;
}
}
G = D - c.left;
z = s - c.top;
}
/* var C = a.document.documentElement; */
var C = (a.document || a.ownerDocument).documentElement;
var e = 0;
if (Sys.Browser.version < 8 || $telerik.quirksMode) {
var I = 1;
if (y && y.getAttribute) {
var g = y.getAttribute("frameborder");
if (g != null) {
I = parseInt(g, 10);
if (isNaN(I)) {
I = g.toLowerCase() == "no" ? 0 : 1;
}
}
}
e = 2 * I;
}
var M = new Sys.UI.Point(j.left - e - G + $telerik.getCorrectScrollLeft(C), j.top - e - z + C.scrollTop);
if ($telerik.quirksMode) {
M.x += $telerik.getCorrectScrollLeft(document.body);
M.y += document.body.scrollTop;
}
return M;
}
var M = Sys.UI.DomElement.getLocation(a);
if ($telerik.isOpera) {
var d = $telerik.getCurrentStyle(a, "display");
if (d != "inline") {
var E = a.parentNode;
} else {
var E = a.offsetParent;
}
while (E) {
var b = E.tagName.toUpperCase();
if (b == "BODY" || b == "HTML") {
break;
}
if (b == "TABLE" && E.parentNode && E.parentNode.style.display == "inline-block") {
var J = E.offsetLeft;
var h = E.style.display;
E.style.display = "inline-block";
if (E.offsetLeft > J) {
M.x += E.offsetLeft - J;
}
E.style.display = h;
}
M.x -= $telerik.getCorrectScrollLeft(E);
M.y -= E.scrollTop;
if (d != "inline") {
E = E.parentNode;
} else {
E = E.offsetParent;
}
}
}
var q = Math.max(v.documentElement.scrollTop, v.body.scrollTop);
var t = Math.max(v.documentElement.scrollLeft, v.body.scrollLeft);
if (!$telerik.isOpera) {
var K = a;
while (K) {
if ($telerik.getCurrentStyle(K, "position") == "fixed") {
M.y += q;
M.x += t;
q = 0;
t = 0;
break;
}
K = K.offsetParent;
}
}
if ($telerik.isSafari) {
if (q > 0 || t > 0) {
var A = v.documentElement.getElementsByTagName("form");
if (A && A.length > 0) {
var k = Sys.UI.DomElement.getLocation(A[0]);
if (k.y && k.y < 0) {
M.y += q;
}
if (k.x && k.x < 0) {
M.x += t;
}
} else {
var n = a.parentNode,
m = false,
H = false;
while (n && n.tagName) {
var B = Sys.UI.DomElement.getLocation(n);
if (B.y < 0) {
m = true;
}
if (B.x < 0) {
H = true;
}
n = n.parentNode;
}
if (m) {
M.y += q;
}
if (H) {
M.x += t;
}
}
}
var E = a.parentNode;
var u = null;
var w = null;
while (E && E.tagName.toUpperCase() != "BODY" && E.tagName.toUpperCase() != "HTML") {
if (E.tagName.toUpperCase() == "TD") {
u = E;
} else {
if (E.tagName.toUpperCase() == "TABLE") {
w = E;
} else {
var p = $telerik.getCurrentStyle(E, "position");
if (p == "absolute" || p == "relative") {
var x = $telerik.getCurrentStyle(E, "borderTopWidth", 0);
var L = $telerik.getCurrentStyle(E, "borderLeftWidth", 0);
M.x += parseInt(x);
M.y += parseInt(L);
}
}
}
var p = $telerik.getCurrentStyle(E, "position");
if (p == "absolute" || p == "relative") {
M.x -= E.scrollLeft;
M.y -= E.scrollTop;
}
if (u && w) {
M.x += parseInt($telerik.getCurrentStyle(w, "borderTopWidth"), 0);
M.y += parseInt($telerik.getCurrentStyle(w, "borderLeftWidth", 0));
if ($telerik.getCurrentStyle(w, "borderCollapse") != "collapse") {
M.x += parseInt($telerik.getCurrentStyle(u, "borderTopWidth", 0));
M.y += parseInt($telerik.getCurrentStyle(u, "borderLeftWidth", 0));
}
u = null;
w = null;
} else {
if (w) {
if ($telerik.getCurrentStyle(w, "borderCollapse") != "collapse") {
M.x += parseInt($telerik.getCurrentStyle(w, "borderTopWidth", 0));
M.y += parseInt($telerik.getCurrentStyle(w, "borderLeftWidth", 0));
}
w = null;
}
}
E = E.parentNode;
}
}
return M;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment