This repository has been archived by the owner on Oct 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 116
/
dre-ie8-upfront-fix.js
81 lines (75 loc) · 2.16 KB
/
dre-ie8-upfront-fix.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
(function(window, Object, HTMLElement){
if (HTMLElement in window) return;
var
timer = 0,
clearTimeout = window.clearTimeout,
setTimeout = window.setTimeout,
ElementPrototype = Element.prototype,
gOPD = Object.getOwnPropertyDescriptor,
defineProperty = Object.defineProperty,
notifyChanges = function () {
document.dispatchEvent(new CustomEvent('readystatechange'));
},
scheduleNotification = function (target, name) {
clearTimeout(timer);
timer = setTimeout(notifyChanges, 10);
},
wrapSetter = function (name) {
var
descriptor = gOPD(ElementPrototype, name),
// why not just overwrite the setter?
// BECAUSE IE8, THAT'S WHY!
substitute = {
configurable: descriptor.configurable,
enumerable: descriptor.enumerable,
get: function () {
return descriptor.get.call(this);
},
set: function asd(value) {
// caveat, this slows down innerHTML
// "just a tiny bit" ...
delete ElementPrototype[name];
// AHHAHAHAHAAHAHAHAAHAHAHHAHAHHAHAHHAHHAHAHHAHHAHAH
this[name] = value;
// needed for the next call
defineProperty(ElementPrototype, name, substitute);
scheduleNotification(this);
}
}
;
defineProperty(ElementPrototype, name, substitute);
},
wrapMethod = function (name) {
var
descriptor = gOPD(ElementPrototype, name),
value = descriptor.value
;
descriptor.value = function () {
var result = value.apply(this, arguments);
scheduleNotification(this);
return result;
};
defineProperty(
ElementPrototype,
name,
descriptor
);
}
;
wrapSetter('innerHTML');
wrapSetter('innerText');
wrapSetter('outerHTML');
wrapSetter('outerText');
wrapSetter('textContent');
wrapMethod('appendChild');
wrapMethod('applyElement');
wrapMethod('insertAdjacentElement');
wrapMethod('insertAdjacentHTML');
wrapMethod('insertAdjacentText');
wrapMethod('insertBefore');
wrapMethod('insertData');
wrapMethod('replaceAdjacentText');
wrapMethod('replaceChild');
wrapMethod('removeChild');
window[HTMLElement] = Element;
}(window, Object, 'HTMLElement'));