UNPKG

1.13 kBJavaScriptView Raw
1import { BlockEmbed } from '../blots/block';
2import Link from '../formats/link';
3
4const ATTRIBUTES = [
5 'height',
6 'width'
7];
8
9
10class Video extends BlockEmbed {
11 static create(value) {
12 let node = super.create(value);
13 node.setAttribute('frameborder', '0');
14 node.setAttribute('allowfullscreen', true);
15 node.setAttribute('src', this.sanitize(value));
16 return node;
17 }
18
19 static formats(domNode) {
20 return ATTRIBUTES.reduce(function(formats, attribute) {
21 if (domNode.hasAttribute(attribute)) {
22 formats[attribute] = domNode.getAttribute(attribute);
23 }
24 return formats;
25 }, {});
26 }
27
28 static sanitize(url) {
29 return Link.sanitize(url);
30 }
31
32 static value(domNode) {
33 return domNode.getAttribute('src');
34 }
35
36 format(name, value) {
37 if (ATTRIBUTES.indexOf(name) > -1) {
38 if (value) {
39 this.domNode.setAttribute(name, value);
40 } else {
41 this.domNode.removeAttribute(name);
42 }
43 } else {
44 super.format(name, value);
45 }
46 }
47}
48Video.blotName = 'video';
49Video.className = 'ql-video';
50Video.tagName = 'IFRAME';
51
52
53export default Video;