1、实现富文本编辑器

2、实现项目排序
This commit is contained in:
lifei6671
2017-04-29 21:28:09 +08:00
parent c289567ec2
commit ae8f4532f6
389 changed files with 24153 additions and 139874 deletions

View File

@@ -1,18 +1,4 @@
function showError($msg,$id) {
if(!$id){
$id = "#form-error-message"
}
$($id).addClass("error-message").removeClass("success-message").text($msg);
return false;
}
function showSuccess($msg,$id) {
if(!$id){
$id = "#form-error-message"
}
$($id).addClass("success-message").removeClass("error-message").text($msg);
return true;
}
$(function () {
window.addDocumentModalFormHtml = $(this).find("form").html();
@@ -32,12 +18,24 @@ $(function () {
flowChart : true,
htmlDecode : "style,script,iframe,title,onmouseover,onmouseout,style",
lineNumbers : false,
tocStartLevel : 1,
tocm : true,
saveHTMLToTextarea : true,
onload : function() {
this.hideToolbar();
var keyMap = {
"Ctrl-S": function(cm) {
saveDocument(false);
},
"Cmd-S" : function(cm){
saveDocument(false);
},
"Ctrl-A": function(cm) {
cm.execCommand("selectAll");
}
};
this.addKeyMap(keyMap);
var $select_node_id = window.treeCatalog.get_selected();
if($select_node_id) {
var $select_node = window.treeCatalog.get_node($select_node_id[0])
@@ -67,7 +65,6 @@ $(function () {
}else if(name === "history"){
}else if(name === "save"){
saveDocument(false);
}else if(name === "sidebar"){
@@ -84,7 +81,22 @@ $(function () {
window.editor.resize();
});
}else if(name === "release"){
if(Object.prototype.toString.call(window.documentCategory) === '[object Array]' && window.documentCategory.length > 0){
$.ajax({
url : window.releaseURL,
type : "post",
dataType : "json",
success : function (res) {
if(res.errcode === 0){
layer.msg("发布任务已推送到任务队列,稍后将在后台执行。");
}else{
layer.msg(res.message);
}
}
});
}else{
layer.msg("没有需要发布的文档")
}
}else if(name === "tasks") {
//插入GFM任务列表
var cm = window.editor.cm;
@@ -111,36 +123,6 @@ $(function () {
}
}) ;
//实现小提示
$("[data-toggle='tooltip']").hover(function () {
var title = $(this).attr('data-title');
var direction = $(this).attr("data-direction");
var tips = 3;
if(direction === "top"){
tips = 1;
}else if(direction === "right"){
tips = 2;
}else if(direction === "bottom"){
tips = 3;
}else if(direction === "left"){
tips = 4;
}
index = layer.tips(title, this, {
tips: tips
});
}, function () {
layer.close(index);
});
$("#btnAddDocument").on("click",function () {
$("#addDocumentModal").modal("show");
});
$("#addDocumentModal").on("hidden.bs.modal",function () {
$(this).find("form").html(window.addDocumentModalFormHtml);
}).on("shown.bs.modal",function () {
$(this).find("input[name='doc_name']").focus();
});
/***
* 加载指定的文档到编辑器中
* @param $node
@@ -173,95 +155,16 @@ $(function () {
}
/**
* 创建文档
* 保存文档到服务器
* @param $is_cover 是否强制覆盖
*/
function openCreateCatalogDialog($node) {
var $then = $("#addDocumentModal");
var doc_id = $node ? $node.id : 0;
$then.find("input[name='parent_id']").val(doc_id);
$then.modal("show");
}
/**
* 将一个节点推送到现有数组中
* @param $node
*/
function pushDocumentCategory($node) {
for (var index in window.documentCategory){
var item = window.documentCategory[index];
if(item.id === $node.id){
window.documentCategory[index] = $node;
console.log( window.documentCategory[index]);
return;
}
}
window.documentCategory.push($node);
}
/**
* 打开文档编辑界面
* @param $node
*/
function openEditCatalogDialog($node) {
var $then = $("#addDocumentModal");
var doc_id = parseInt($node ? $node.id : 0);
var text = $node ? $node.text : '';
var parentId = $node && $node.parent !== '#' ? $node.parent : 0;
$then.find("input[name='doc_id']").val(doc_id);
$then.find("input[name='parent_id']").val(parentId);
$then.find("input[name='doc_name']").val(text);
for (var index in window.documentCategory){
var item = window.documentCategory[index];
if(item.id === doc_id){
$then.find("input[name='doc_identify']").val(item.identify);
break;
}
}
$then.modal({ show : true });
}
/**
* 删除一个文档
* @param $node
*/
function openDeleteDocumentDialog($node) {
var index = layer.confirm('你确定要删除该文档吗?', {
btn: ['确定','取消'] //按钮
}, function(){
$.post(window.deleteURL,{"identify" : window.book.identify,"doc_id" : $node.id}).done(function (res) {
layer.close(index);
if(res.errcode === 0){
window.treeCatalog.delete_node($node);
resetEditor($node);
}else{
layer.msg("删除失败",{icon : 2})
}
}).fail(function () {
layer.close(index);
layer.msg("删除失败",{icon : 2})
});
});
}
function saveDocument($is_cover) {
function saveDocument($is_cover,callback) {
var index = null;
var node = window.selectNode;
var content = window.editor.getMarkdown();
var html = window.editor.getPreviewedHTML();
var version = "";
if(content === ""){
resetEditorChanged(false);
return;
}
if(!node){
layer.msg("获取当前文档信息失败");
return;
@@ -297,12 +200,15 @@ $(function () {
break;
}
}
if(typeof callback === "function"){
callback();
}
}else if(res.errcode === 6005){
var confirmIndex = layer.confirm('你确定要删除该文档吗?', {
var confirmIndex = layer.confirm('文档已被其他人修改确定覆盖已存在的文档吗?', {
btn: ['确定','取消'] //按钮
}, function(){
layer.close(confirmIndex);
saveDocument(true);
saveDocument(true,callback);
});
}else{
layer.msg(res.message);
@@ -315,6 +221,10 @@ $(function () {
}
/**
* 设置编辑器变更状态
* @param $is_change
*/
function resetEditorChanged($is_change) {
if($is_change && !window.isLoad ){
$("#markdown-save").removeClass('disabled').addClass('change');
@@ -424,39 +334,13 @@ $(function () {
}).on('select_node.jstree', function (node, selected, event) {
if($("#markdown-save").hasClass('change')) {
if(confirm("编辑内容未保存,需要保存吗?")){
saveDocument();
saveDocument(false,function () {
loadDocument(selected);
});
return true;
}
}
loadDocument(selected);
}).on("move_node.jstree", function (node, parent) {
var parentNode = window.treeCatalog.get_node(parent.parent);
var nodeData = window.getSiblingSort(parentNode);
if (parent.parent != parent.old_parent) {
parentNode = window.treeCatalog.get_node(parent.old_parent);
var newNodeData = window.getSiblingSort(parentNode);
if (newNodeData.length > 0) {
nodeData = nodeData.concat(newNodeData);
}
}
var index = layer.load(1, {
shade: [0.1, '#fff'] //0.1透明度的白色背景
});
$.post("https://wiki.iminho.me/docs/sort/2", JSON.stringify(nodeData)).done(function (res) {
layer.close(index);
if (res.errcode != 0) {
layer.msg(res.message);
} else {
layer.msg("保存排序成功");
}
}).fail(function () {
layer.close(index);
layer.msg("保存排序失败");
});
});
}).on("move_node.jstree",jstree_save);
});