-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathplugin.html-validate.iframe.js
More file actions
51 lines (44 loc) · 1.33 KB
/
plugin.html-validate.iframe.js
File metadata and controls
51 lines (44 loc) · 1.33 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
48
49
50
51
const { Rule } = require('html-validate');
const { nodeIgnore } = require('./plugin.html-validate.utils');
/**
* @typedef { import('html-validate').DOMReadyEvent } DOMReadyEvent
*/
/**
* Lint `iframe[loading]` required attribute.
*/
class IframeLoadingRequired extends Rule {
/**
* @param {object} options - plugin options
*/
constructor(options) {
super({ ignore: '.wysiwyg iframe', ...options });
this.domReady = this.domReady.bind(this);
}
/**
* Setup plugin events.
*/
setup() {
this.on('dom:ready', this.domReady);
}
/**
* Lint html document.
* @param {DOMReadyEvent.document} document - document object
*/
domReady({ document }) {
const iframes = document.querySelectorAll('iframe');
const ignores = this.options.ignore ? document.querySelectorAll(this.options.ignore) : [];
iframes.forEach((iframe) => {
if (nodeIgnore(iframe, ignores)) {
return;
}
const loading = iframe.getAttributeValue('loading');
if (!loading) {
this.report(iframe, '<iframe> required `loading` attribute.');
}
});
}
}
module.exports = { IframeLoadingRequired };
module.exports.rules = {
'pitcher/iframe-loading-required': IframeLoadingRequired,
};