video.js 1.1 KB

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