-
Notifications
You must be signed in to change notification settings - Fork 5
/
plugin.html-validate.video.js
52 lines (45 loc) · 1.44 KB
/
plugin.html-validate.video.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
const { Rule } = require('html-validate');
const { nodeIgnore } = require('./plugin.html-validate.utils');
/**
* @typedef { import('html-validate').DOMReadyEvent } DOMReadyEvent
*/
/**
* Lint `video[playsinline]` required attribute.
*/
class VideoPlaysinlineRequired extends Rule {
/**
* @param {object} options - plugin options
*/
constructor(options) {
super({ ignore: '.wysiwyg video', ...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 videos = document.querySelectorAll('video');
const ignores = this.options.ignore ? document.querySelectorAll(this.options.ignore) : [];
videos.forEach((video) => {
if (nodeIgnore(video, ignores)) {
return;
}
const autoplay = video.hasAttribute('autoplay');
const playsinline = video.hasAttribute('playsinline');
if (autoplay && !playsinline) {
this.report(video, '<video> required `playsinline` attribute with `autoplay` attribute.');
}
});
}
}
module.exports = { VideoPlaysinlineRequired };
module.exports.rules = {
'pitcher/video-playsinline-required': VideoPlaysinlineRequired,
};