From 9ba6812c90e90d46b73c4e6d4899e0fbee4f45ec Mon Sep 17 00:00:00 2001 From: panfuy Date: Fri, 1 May 2020 21:35:17 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E7=AE=A1=E7=90=86=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E7=BC=96=E8=BE=91=E5=99=A8=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E5=88=B0=E6=BA=90=E7=A0=81=E6=A8=A1=E5=BC=8F=E5=90=8EHTML?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=A2=AB=E6=9B=B4=E6=8D=A2=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E5=8E=9F=E6=A0=BC=E5=BC=8F=E5=87=BA=E7=8E=B0=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/webapp/static/admin/js/jpressadmin.js | 16 +++++++++++----- .../WEB-INF/views/admin/page/page_write.html | 18 ++++++++++++++---- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/jpress-web/src/main/webapp/static/admin/js/jpressadmin.js b/jpress-web/src/main/webapp/static/admin/js/jpressadmin.js index f92c7313a..e97925631 100755 --- a/jpress-web/src/main/webapp/static/admin/js/jpressadmin.js +++ b/jpress-web/src/main/webapp/static/admin/js/jpressadmin.js @@ -144,8 +144,8 @@ function initEditor(editor, height, type) { height = height || 467; type = type || 'html'; //默认用ckeditor - if (type == 'html') { - return initCkEdtior(editor, height); + if (type == 'html' || type == 'html-source') { + return initCkEdtior(editor, height, type); } else if (type == 'markdown') { return initMarkdownEditor(editor, height); } @@ -176,7 +176,7 @@ function doListenerCtrlsAndCommands(func) { }); } -function initCkEdtior(editor, height) { +function initCkEdtior(editor, height,type) { CKEDITOR.config.toolbar = [ ['Bold', 'Italic', 'Underline', 'Strike', 'RemoveFormat'], @@ -205,6 +205,11 @@ function initCkEdtior(editor, height) { extraPlugins: 'entities,codesnippet,uploadimage,flash,image,wordcount,notification,html5audio,html5video,widget,widgetselection,clipboard,lineutils', codeSnippet_theme: 'monokai_sublime', height: height, + allowedContent: true, // 保存内容包含javascript、style标签的时候,数据库中有javascript、style标签 , + pasteFromWordRemoveFontStyles: false, // 保证word导入格式 + pasteFromWordRemoveStyles: false, // 保证word导入格式 + forcePasteAsPlainText: false, // 不强制复制来的内容去除格式 + startupMode: (type == 'html-source') ? 'source' : 'wysiwyg', // 源码模式:source、 所见所得模式:wysiwyg uploadUrl: jpress.cpath + '/commons/ckeditor/upload', imageUploadUrl: jpress.cpath + '/commons/ckeditor/upload', filebrowserUploadUrl: jpress.cpath + '/commons/ckeditor/upload', @@ -223,10 +228,11 @@ function initCkEdtior(editor, height) { ds && ds(); } }); + // 编辑组件准备完毕时,加载全局事件 + var der = window.doEditorReady; + der && der(ed); }); - - ed.on("dialogShow", function (event) { // 方便调试 _dialogShowEvent = event; diff --git a/module-page/module-page-web/src/main/webapp/WEB-INF/views/admin/page/page_write.html b/module-page/module-page-web/src/main/webapp/WEB-INF/views/admin/page/page_write.html index c63de4118..391d9fe15 100755 --- a/module-page/module-page-web/src/main/webapp/WEB-INF/views/admin/page/page_write.html +++ b/module-page/module-page-web/src/main/webapp/WEB-INF/views/admin/page/page_write.html @@ -27,6 +27,16 @@ toastr.success('内容保存成功。'); }); } + // 全局函数,在CKEditor组件初始化完成后,调用此方法 + window.doEditorReady = function (editor) { + // 切换到源码的按钮,增加点击事件,保存当前组件是否在源码编辑框 + $(".cke_button__source").on("click", function () { + setTimeout(function () { + var mode = editor.mode == "source"?'html-source':"html"; + $("#editModeId").val(mode); + }, 300); + }); + } $("#removeThumbnail").on("click", function () { $("#thumbnail").attr("src", "#(CPATH)/static/commons/img/nothumbnail.jpg"); @@ -38,7 +48,7 @@ function doChangeEditor(id) { if (confirm('确定要切换编辑器吗?切换可能出现前台渲染内容缺失的问题。')) { - var changeMode = editMode == "html" ? "markdown" : "html"; + var changeMode = editMode == "markdown" ? "html" : "markdown"; if (id != '0') { ajaxGet('#(CPATH)/admin/page/doChangeEditMode?id=' + id + "&mode=" + changeMode); } else { @@ -113,10 +123,10 @@ #end - #if(editMode && editMode == 'html') - 使用 markdown 编辑 - #else + #if(editMode && editMode == 'markdown') 可视化编辑 + #else + 使用 markdown 编辑 #end -- Gitee