update wangEditor

This commit is contained in:
gsw945
2021-08-25 17:32:31 +08:00
parent 097af0077e
commit 354f32be38
27 changed files with 25367 additions and 20237 deletions

106
static/js/class2browser.js Normal file
View File

@@ -0,0 +1,106 @@
/**
* 将es6的class语法转为浏览器可以直接使用的语法,
* 取自 https://babeljs.io/repl
* 需要添加 @babel/plugin-transform-classes
* 是要到的方法添加了`c2b`前缀
*/
function c2b_classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function c2b_createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
function c2b_inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function");
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: { value: subClass, writable: true, configurable: true }
});
if (superClass) _setPrototypeOf(subClass, superClass);
}
function _setPrototypeOf(o, p) {
_setPrototypeOf =
Object.setPrototypeOf ||
function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function c2b_createSuper(Derived) {
var hasNativeReflectConstruct = _isNativeReflectConstruct();
return function _createSuperInternal() {
var Super = _getPrototypeOf(Derived),
result;
if (hasNativeReflectConstruct) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
function _possibleConstructorReturn(self, call) {
if (call && (typeof call === "object" || typeof call === "function")) {
return call;
} else if (call !== void 0) {
throw new TypeError(
"Derived constructors may only return object or undefined"
);
}
return _assertThisInitialized(self);
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError(
"this hasn't been initialised - super() hasn't been called"
);
}
return self;
}
function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Boolean.prototype.valueOf.call(
Reflect.construct(Boolean, [], function () {})
);
return true;
} catch (e) {
return false;
}
}
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf
? Object.getPrototypeOf
: function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _getPrototypeOf(o);
}

View File

@@ -1,21 +1,60 @@
$(function () {
wangEditor.config.mapAk = window.baiduMapKey;
window.addDocumentModalFormHtml = $(this).find("form").html();
wangEditor.config.printLog = false;
window.editor = new wangEditor('htmlEditor');
window.editor = new wangEditor('#htmlEditor');
editor.config.mapAk = window.baiduMapKey;
editor.config.printLog = false;
editor.config.showMenuTooltips = true
editor.config.menuTooltipPosition = 'down'
editor.config.uploadImgUrl = window.imageUploadURL;
editor.config.uploadImgFileName = "editormd-image-file";
editor.config.uploadParams = {
"editor" : "wangEditor"
};
wangEditor.config.menus.splice(0,0,"|");
wangEditor.config.menus.splice(0,0,"history");
wangEditor.config.menus.splice(0,0,"save");
wangEditor.config.menus.splice(0,0,"release");
wangEditor.config.menus.splice(29,0,"attach")
editor.config.uploadImgServer = window.imageUploadURL;
editor.config.customUploadImg = function (resultFiles, insertImgFn) {
// resultFiles 是 input 中选中的文件列表
// insertImgFn 是获取图片 url 后,插入到编辑器的方法
var file = resultFiles[0];
// file type is only image.
if (/^image\//.test(file.type)) {
var form = new FormData();
form.append('editormd-image-file', file, file.name);
var layerIndex = 0;
$.ajax({
url: window.imageUploadURL,
type: "POST",
dataType: "json",
data: form,
processData: false,
contentType: false,
error: function() {
layer.close(layerIndex);
layer.msg("图片上传失败");
},
success: function(data) {
layer.close(layerIndex);
if(data.errcode !== 0){
layer.msg(data.message);
}else{
insertImgFn(data.url);
}
}
});
} else {
console.warn('You could only upload images.');
}
};
/*
editor.config.menus.splice(0,0,"|");
editor.config.menus.splice(0,0,"history");
editor.config.menus.splice(0,0,"save");
editor.config.menus.splice(0,0,"release");
editor.config.menus.splice(29,0,"attach")
//移除地图、背景色
editor.config.menus = $.map(wangEditor.config.menus, function(item, key) {
editor.config.menus = $.map(editor.config.menus, function(item, key) {
if (item === 'fullscreen') {
return null;
@@ -23,16 +62,8 @@ $(function () {
return item;
});
window.editor.ready(function () {
if(window.documentCategory.length > 0){
var item = window.documentCategory[0];
var $select_node = { node : {id : item.id}};
loadDocument($select_node);
}
});
*/
/*
window.editor.config.uploadImgFns.onload = function (resultText, xhr) {
// resultText 服务器端返回的text
// xhr 是 xmlHttpRequest 对象IE8、9中不支持
@@ -47,13 +78,15 @@ $(function () {
layer.msg(res.message);
}
};
*/
window.editor.onchange = function () {
window.editor.config.onchange = function (newHtml) {
var saveMenu = window.editor.menus.menuList.find((item) => item.key == 'save');
// 判断内容是否改变
if (window.source !== this.$txt.html()) {
window.editor.menus.save.$domNormal.addClass('selected');
if (window.source !== window.editor.txt.html()) {
saveMenu.$elem.addClass('selected');
} else {
window.editor.menus.save.$domNormal.removeClass('selected');
saveMenu.$elem.removeClass('selected');
}
};
@@ -62,7 +95,11 @@ $(function () {
$("#htmlEditor").css("height","100%");
if(window.documentCategory.length > 0){
var item = window.documentCategory[0];
var $select_node = { node : {id : item.id}};
loadDocument($select_node);
}
/***
* 加载指定的文档到编辑器中
@@ -78,8 +115,8 @@ $(function () {
if(res.errcode === 0){
window.isLoad = true;
window.editor.clear();
window.editor.$txt.html(res.data.content);
window.editor.txt.clear();
window.editor.txt.html(res.data.content);
// 将原始内容备份
window.source = res.data.content;
var node = { "id" : res.data.doc_id,'parent' : res.data.parent_id === 0 ? '#' : res.data.parent_id ,"text" : res.data.doc_name,"identify" : res.data.identify,"version" : res.data.version};
@@ -105,7 +142,7 @@ $(function () {
var index = null;
var node = window.selectNode;
var html = window.editor.$txt.html() ;
var html = window.editor.txt.html() ;
var content = "";
if($.trim(html) !== ""){
@@ -149,7 +186,7 @@ $(function () {
// 更新内容备份
window.source = res.data.content;
// 触发编辑器 onchange 回调函数
window.editor.onchange();
window.editor.config.onchange();
if(typeof callback === "function"){
callback();
}
@@ -267,7 +304,7 @@ $(function () {
}).on('loaded.jstree', function () {
window.treeCatalog = $(this).jstree();
}).on('select_node.jstree', function (node, selected, event) {
if(window.editor.menus.save.$domNormal.hasClass('selected')) {
if(window.editor.menus.menuList.find((item) => item.key == 'save').$elem.hasClass('selected')) {
if(confirm("编辑内容未保存,需要保存吗?")){
saveDocument(false,function () {
loadDocument(selected);
@@ -283,7 +320,7 @@ $(function () {
window.releaseBook = function () {
if(Object.prototype.toString.call(window.documentCategory) === '[object Array]' && window.documentCategory.length > 0){
if(window.editor.menus.save.$domNormal.hasClass('selected')) {
if(window.editor.menus.menuList.find((item) => item.key == 'save').$elem.hasClass('selected')) {
if(confirm("编辑内容未保存,需要保存吗?")) {
saveDocument();
}

View File

@@ -0,0 +1,42 @@
(function () {
// 获取 wangEditor 构造函数和 jquery
var E = window.wangEditor;
var $ = window.jQuery;
let SaveMenu = (function (_BtnMenu) {
c2b_inherits(SaveMenu, _BtnMenu);
var _super = c2b_createSuper(SaveMenu);
function SaveMenu(editor) {
c2b_classCallCheck(this, SaveMenu);
const $elem = E.$(`<div class="w-e-menu" data-title="保存">
<i class="fa fa-floppy-o" aria-hidden="true"></i>
</div>`);
return _super.call(this, $elem, editor);
}
c2b_createClass(SaveMenu, [
{
key: "clickHandler",
value: function clickHandler() {
window.saveDocument();
}
},
{
key: "tryChangeActive",
value: function tryChangeActive() {
// this.active();
}
}
]);
return SaveMenu;
})(E.BtnMenu);
var menuKey = 'save';
E.registerMenu(menuKey, SaveMenu);
})();