|
|
@@ -391,6 +391,7 @@ Vue.component('spaceEditor', {
|
|
|
previewMode: 'pc',
|
|
|
previewUrl: '',
|
|
|
previewLoading: false,
|
|
|
+ videoPlaybackSyncTimer: undefined,
|
|
|
}
|
|
|
},
|
|
|
name: "spaceEditor",
|
|
|
@@ -827,6 +828,7 @@ Vue.component('spaceEditor', {
|
|
|
|
|
|
this.editor.setData(wrapper.innerHTML);
|
|
|
this.$emit("input", this.editor.getData());
|
|
|
+ this.deferSyncEditorPlayableVideos();
|
|
|
space.message.success("正文已完成排版整理");
|
|
|
},
|
|
|
insertHtml: function (html) {
|
|
|
@@ -838,6 +840,7 @@ Vue.component('spaceEditor', {
|
|
|
var modelFragment = this.editor.data.toModel(viewFragment);
|
|
|
this.editor.model.insertContent(modelFragment);
|
|
|
this.$emit("input", this.editor.getData());
|
|
|
+ this.deferSyncEditorPlayableVideos();
|
|
|
},
|
|
|
escapeHtmlAttr: function (value) {
|
|
|
return String(value || "").replace(/[&<>"']/g, function (text) {
|
|
|
@@ -931,6 +934,138 @@ Vue.component('spaceEditor', {
|
|
|
editable.addEventListener("paste", handler);
|
|
|
editable.addEventListener("drop", handler);
|
|
|
},
|
|
|
+ findClosestEditorMedia: function (target) {
|
|
|
+ if (!target) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (target.nodeType == 3) {
|
|
|
+ target = target.parentNode;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!target || target.nodeType != 1) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (/^(video|iframe)$/i.test(target.tagName)) {
|
|
|
+ return target;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (target.closest) {
|
|
|
+ return target.closest("video, iframe");
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ },
|
|
|
+ prepareEditorPlayableMedia: function (media) {
|
|
|
+ if (!media || media.nodeType != 1) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var tagName = (media.tagName || "").toLowerCase();
|
|
|
+ if (tagName == "video") {
|
|
|
+ media.setAttribute("controls", "controls");
|
|
|
+ media.setAttribute("playsinline", "playsinline");
|
|
|
+ media.setAttribute("webkit-playsinline", "webkit-playsinline");
|
|
|
+ if (!media.getAttribute("preload")) {
|
|
|
+ media.setAttribute("preload", "metadata");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ media.classList.add("space-editor-playable-media");
|
|
|
+ var mediaWidget = media.closest ? media.closest("figure.media") : null;
|
|
|
+ if (mediaWidget) {
|
|
|
+ mediaWidget.classList.add("space-editor-playable-media-widget");
|
|
|
+ }
|
|
|
+ },
|
|
|
+ bindPlayableMediaNativeEvents: function (media) {
|
|
|
+ if (!media || media.getAttribute("data-space-playable-media-bound") == "true") {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.prepareEditorPlayableMedia(media);
|
|
|
+ media.setAttribute("data-space-playable-media-bound", "true");
|
|
|
+
|
|
|
+ var _this = this;
|
|
|
+ var stopWidgetSelection = function (event) {
|
|
|
+ _this.prepareEditorPlayableMedia(media);
|
|
|
+ event.stopPropagation();
|
|
|
+ };
|
|
|
+ var eventNames = ["pointerdown", "pointerup", "mousedown", "mouseup", "click", "dblclick", "touchstart", "touchend"];
|
|
|
+ for (var i = 0; i < eventNames.length; i++) {
|
|
|
+ media.addEventListener(eventNames[i], stopWidgetSelection);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ syncEditorPlayableVideos: function () {
|
|
|
+ if (!this.editor || !this.editor.ui || !this.editor.ui.getEditableElement) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var editable = this.editor.ui.getEditableElement();
|
|
|
+ if (!editable) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var medias = editable.querySelectorAll("video, iframe");
|
|
|
+ for (var i = 0; i < medias.length; i++) {
|
|
|
+ this.bindPlayableMediaNativeEvents(medias[i]);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ deferSyncEditorPlayableVideos: function () {
|
|
|
+ if (this.videoPlaybackSyncTimer) {
|
|
|
+ window.clearTimeout(this.videoPlaybackSyncTimer);
|
|
|
+ }
|
|
|
+
|
|
|
+ var _this = this;
|
|
|
+ this.videoPlaybackSyncTimer = window.setTimeout(function () {
|
|
|
+ _this.syncEditorPlayableVideos();
|
|
|
+ _this.videoPlaybackSyncTimer = undefined;
|
|
|
+ }, 0);
|
|
|
+ },
|
|
|
+ bindEditorVideoPlayback: function () {
|
|
|
+ if (!this.editor || !this.editor.ui || !this.editor.ui.getEditableElement) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var editable = this.editor.ui.getEditableElement();
|
|
|
+ if (!editable || editable.getAttribute("data-space-playable-media-root") == "true") {
|
|
|
+ this.syncEditorPlayableVideos();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ editable.setAttribute("data-space-playable-media-root", "true");
|
|
|
+ var _this = this;
|
|
|
+ var stopNativeWidgetSelection = function (event) {
|
|
|
+ var media = _this.findClosestEditorMedia(event.target);
|
|
|
+ if (!media) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ _this.prepareEditorPlayableMedia(media);
|
|
|
+ event.stopPropagation();
|
|
|
+ };
|
|
|
+
|
|
|
+ ["pointerdown", "pointerup", "mousedown", "mouseup", "click", "dblclick", "touchstart", "touchend"].forEach(function (eventName) {
|
|
|
+ editable.addEventListener(eventName, stopNativeWidgetSelection);
|
|
|
+ });
|
|
|
+
|
|
|
+ if (this.editor.editing && this.editor.editing.view && this.editor.editing.view.document) {
|
|
|
+ ["mousedown", "mouseup", "click", "dblclick", "touchstart", "touchend"].forEach(function (eventName) {
|
|
|
+ _this.editor.editing.view.document.on(eventName, function (evt, data) {
|
|
|
+ var domTarget = data ? (data.domTarget || (data.domEvent ? data.domEvent.target : null)) : null;
|
|
|
+ var media = _this.findClosestEditorMedia(domTarget);
|
|
|
+ if (!media) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ _this.prepareEditorPlayableMedia(media);
|
|
|
+ evt.stop();
|
|
|
+ }, { priority: "highest" });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ this.syncEditorPlayableVideos();
|
|
|
+ },
|
|
|
getPreviewPostData: function () {
|
|
|
var data = this.previewdata || {};
|
|
|
return {
|
|
|
@@ -1036,9 +1171,11 @@ Vue.component('spaceEditor', {
|
|
|
_this.alignFullScreenToolbarButton();
|
|
|
_this.mountVideoUploadToolbarButton();
|
|
|
_this.bindVideoPasteUpload();
|
|
|
+ _this.bindEditorVideoPlayback();
|
|
|
|
|
|
if (_this.htmlContent != undefined) {
|
|
|
_this.editor.setData(_this.htmlContent);
|
|
|
+ _this.deferSyncEditorPlayableVideos();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1080,6 +1217,7 @@ Vue.component('spaceEditor', {
|
|
|
// 监听编辑器的内容变动事件
|
|
|
editor.model.document.on('change:data', function () {
|
|
|
_this.$emit("input", editor.getData());
|
|
|
+ _this.deferSyncEditorPlayableVideos();
|
|
|
});
|
|
|
|
|
|
}).catch(error => {
|