zxl
5 小时以前 eb5b0cd3e99caa28f1be06340fb8d888388a8959
manager/src/views/activity/video.js
@@ -3,23 +3,17 @@
const BlockEmbed = Quill.import('blots/block/embed');
const Link = Quill.import('formats/link');
const ATTRIBUTES = ['height', 'width', 'controls', 'src', 'poster'];
const ATTRIBUTES = ['height', 'width', 'controls', 'src', ];
class VideoBlot extends BlockEmbed {
  static create(value) {
    const node = super.create();
    // 设置基本属性
    node.setAttribute('controls', 'controls');
    node.setAttribute('controlsList', 'nodownload');
    node.setAttribute('preload', 'metadata');
    // 支持对象形式的value
    if (typeof value === 'object') {
      node.setAttribute('src', this.sanitize(value.url));
      node.setAttribute('poster', value.poster || '');
      node.setAttribute('width', value.width || '100%');
      node.setAttribute('height', value.height || 'auto');
      node.setAttribute('controls', value.controls || 'controls');
    } else {
      node.setAttribute('src', this.sanitize(value));
    }
@@ -43,9 +37,9 @@
  static value(node) {
    return {
      url: node.getAttribute('src'),
      poster: node.getAttribute('poster'),
      width: node.getAttribute('width'),
      height: node.getAttribute('height')
      height: node.getAttribute('height'),
      controls: node.getAttribute('controls'),
    };
  }
@@ -66,4 +60,10 @@
VideoBlot.className = 'ql-video';
VideoBlot.tagName = 'video';
// 添加不会被 sanitize 的标记
VideoBlot.sanitize = function(url) {
  const sanitized = Link.sanitize(url);
  return sanitized === Link.PROTOCOL_WHITELIST[0] ? 'about:blank' : sanitized;
};
export default VideoBlot;