增加新的约束和替换编辑器
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
<script src="../utils/CommonUtil.js"></script>
|
||||
<link rel="stylesheet" href="../public/css/layui/css/layui.css" />
|
||||
<link rel="stylesheet" href="../public/css/public.css" />
|
||||
<link rel="stylesheet" href="../public/js/wangeditor-v5/style.css" />
|
||||
<link rel="stylesheet" href="../public/css/fabumianfeiwenzhang.css" />
|
||||
</head>
|
||||
<body>
|
||||
@@ -122,6 +123,10 @@
|
||||
class="meui-input publish-editor-textarea"
|
||||
name="nr"
|
||||
></textarea>
|
||||
<div class="publish-editor">
|
||||
<div id="editor-toolbar" class="publish-editor-toolbar"></div>
|
||||
<div id="editor-container" class="publish-editor-container"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="submit-row">
|
||||
@@ -169,11 +174,12 @@
|
||||
</button>
|
||||
|
||||
<script src="../public/js/lay-config.js" charset="utf-8"></script>
|
||||
<script charset="utf-8" src="../public/js/ke/kindeditor.min.js"></script>
|
||||
<script charset="utf-8" src="../public/js/wangeditor-v5/index.js"></script>
|
||||
<script>
|
||||
var menuList = [];
|
||||
var layer;
|
||||
var editor;
|
||||
var editorToolbar;
|
||||
var pageReady = false;
|
||||
var publishPermission = {
|
||||
canFree: false,
|
||||
@@ -183,48 +189,54 @@
|
||||
var FREE_TITLE_MIN_LENGTH = 15;
|
||||
var FREE_TITLE_MAX_LENGTH = 30;
|
||||
|
||||
function autoFormatEditorContent() {
|
||||
if (!editor) return;
|
||||
try {
|
||||
if (typeof editor.clickToolbar === "function") {
|
||||
editor.clickToolbar("quickformat");
|
||||
} else if (typeof editor.exec === "function") {
|
||||
editor.exec("quickformat");
|
||||
}
|
||||
if (typeof editor.sync === "function") editor.sync();
|
||||
} catch (e) {
|
||||
console.warn("auto quickformat failed", e);
|
||||
function syncEditorContent() {
|
||||
var contentInput = document.getElementById("input-content1");
|
||||
if (!contentInput || !editor || typeof editor.getHtml !== "function") {
|
||||
return;
|
||||
}
|
||||
contentInput.value = editor.getHtml();
|
||||
}
|
||||
|
||||
KindEditor.ready(function (K) {
|
||||
editor = K.create('textarea[id="input-content1"]', {
|
||||
width: "100%",
|
||||
height: "400px",
|
||||
afterBlur: function () {
|
||||
autoFormatEditorContent();
|
||||
function autoFormatEditorContent() {
|
||||
syncEditorContent();
|
||||
}
|
||||
|
||||
function initRichTextEditor() {
|
||||
var contentInput = document.getElementById("input-content1");
|
||||
if (!window.wangEditor || !window.wangEditor.createEditor) {
|
||||
console.error("wangEditor v5 is not loaded");
|
||||
return;
|
||||
}
|
||||
|
||||
editor = window.wangEditor.createEditor({
|
||||
selector: "#editor-container",
|
||||
html: contentInput ? contentInput.value : "",
|
||||
config: {
|
||||
placeholder: contentInput
|
||||
? contentInput.getAttribute("placeholder") || ""
|
||||
: "",
|
||||
onChange: syncEditorContent,
|
||||
onBlur: syncEditorContent,
|
||||
},
|
||||
items: [
|
||||
"source",
|
||||
"justifyleft",
|
||||
"justifycenter",
|
||||
"justifyright",
|
||||
"justifyfull",
|
||||
"fontsize",
|
||||
"forecolor",
|
||||
"hilitecolor",
|
||||
"bold",
|
||||
"italic",
|
||||
"underline",
|
||||
"strikethrough",
|
||||
"table",
|
||||
"clearhtml",
|
||||
"quickformat",
|
||||
"selectall",
|
||||
"link",
|
||||
],
|
||||
mode: "default",
|
||||
});
|
||||
});
|
||||
|
||||
editorToolbar = window.wangEditor.createToolbar({
|
||||
editor: editor,
|
||||
selector: "#editor-toolbar",
|
||||
config: {
|
||||
excludeKeys: [
|
||||
"group-video",
|
||||
"insertVideo",
|
||||
"uploadVideo",
|
||||
"emotion",
|
||||
],
|
||||
},
|
||||
mode: "default",
|
||||
});
|
||||
}
|
||||
|
||||
initRichTextEditor();
|
||||
|
||||
layui.use(["layer", "jquery"], function () {
|
||||
layer = layui.layer;
|
||||
@@ -600,15 +612,14 @@
|
||||
|
||||
function getEditorHtml() {
|
||||
autoFormatEditorContent();
|
||||
if (editor && typeof editor.sync === "function") editor.sync();
|
||||
return editor && typeof editor.html === "function"
|
||||
? editor.html()
|
||||
return editor && typeof editor.getHtml === "function"
|
||||
? editor.getHtml()
|
||||
: layui.$("#input-content1").val();
|
||||
}
|
||||
|
||||
function getEditorText() {
|
||||
if (editor && typeof editor.text === "function")
|
||||
return editor.text().trim();
|
||||
if (editor && typeof editor.getText === "function")
|
||||
return editor.getText().trim();
|
||||
return layui.$("<div>").html(getEditorHtml()).text().trim();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user