d05eafe12446052f55dd85de80d8f58873dae5443324d88465b89fb04da19c2caa5bc6b3df1104713de21843804b0c080a836015c27c8f2f7469588d24749a 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { BlockEmbed } from '../blots/block.js';
  2. import Link from './link.js';
  3. const ATTRIBUTES = ['height', 'width'];
  4. class Video extends BlockEmbed {
  5. static blotName = 'video';
  6. static className = 'ql-video';
  7. static tagName = 'IFRAME';
  8. static create(value) {
  9. const 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((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. html() {
  41. const {
  42. video
  43. } = this.value();
  44. return `<a href="${video}">${video}</a>`;
  45. }
  46. }
  47. export default Video;
  48. //# sourceMappingURL=video.js.map