This repository was archived by the owner on Aug 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpolyfill.classlist.js
More file actions
47 lines (38 loc) · 1.4 KB
/
polyfill.classlist.js
File metadata and controls
47 lines (38 loc) · 1.4 KB
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
/* global DOMTokenList */
(function () {
var testElement = document.createElement('_');
testElement.classList.add('c1', 'c2');
// Polyfill for IE 10/11 and Firefox <26, where classList.add and
// classList.remove exist but support only one argument at a time.
if (!testElement.classList.contains('c2')) {
var createMethod = function (method) {
var original = DOMTokenList.prototype[method];
DOMTokenList.prototype[method] = function (token) {
var i;
var length = arguments.length;
for (i = 0; i < length; i++) {
token = arguments[i];
original.call(this, token);
}
};
};
createMethod('add');
createMethod('remove');
}
testElement.classList.toggle('c3', false);
// Polyfill for IE 10 and Firefox <24, where classList.toggle does not
// support the second argument.
if (testElement.classList.contains('c3')) {
var originalToggle = DOMTokenList.prototype.toggle;
DOMTokenList.prototype.toggle = function (token, force) {
/* jshint -W018 */
if (1 in arguments && !this.contains(token) === !force) {
return force;
}
else {
return originalToggle.call(this, token);
}
};
}
testElement = null;
}());