-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathie-edge.js
59 lines (48 loc) · 1.67 KB
/
ie-edge.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
/**
* @file rule: ie-edge
* @author nighca<[email protected]>
*/
module.exports = {
name: 'ie-edge',
desc: '<meta http-equiv="X-UA-Compatible" content="IE=Edge"> recommended.',
lint: function (getCfg, document, reporter) {
var head = document.querySelector('head');
if (!head || !getCfg(head)) {
return;
}
var hasEdgeMeta = false;
head.querySelectorAll('meta').forEach(function (meta) {
if (
(meta.getAttribute('http-equiv') || '').toLowerCase() === 'x-ua-compatible'
&& (meta.getAttribute('content') || '').toLowerCase() === 'ie=edge'
) {
hasEdgeMeta = true;
}
});
if (!hasEdgeMeta) {
reporter.warn(head.startIndex, '011', '<meta http-equiv="X-UA-Compatible" content="IE=Edge"> recommended.');
}
},
format: function (getCfg, document, options) {
var head = document.querySelector('head');
if (!head || !getCfg(head)) {
return;
}
var edgeMeta = head.querySelector('meta[http-equiv="X-UA-Compatible"]');
if (edgeMeta) {
edgeMeta.setAttribute('content', 'IE=Edge');
}
else {
edgeMeta = document.createElement('meta');
edgeMeta.setAttribute('http-equiv', 'X-UA-Compatible');
edgeMeta.setAttribute('content', 'IE=Edge');
var title = head.querySelector('title');
if (title && title.nextSibling) {
head.insertBefore(edgeMeta, title.nextSibling);
}
else {
head.appendChild(edgeMeta);
}
}
}
};