<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8" />
<title>test清单</title>
<link rel="stylesheet" th:href="@{/css/style.css}" />
<link rel="stylesheet" th:href="@{/css/editormd.css}" />
<link rel="shortcut icon" href="https://pandao.github.io/editor.md/favicon.ico" type="image/x-icon" />
<script th:inline="javascript">
var testEditor;
/*提交表单的js*/
function contentCommit(){
var redId = getUrlParam("redId");
var documentId = getUrlParam("releaseListId");
var documentName = "test清单";
let mdContent = $('#content').val();
var content = {
redId:redId,
documentId:documentId,
documentName:documentName,
content:mdContent
};
$.ajax({
type:"POST",
url: "./addText",
contentType: "application/json",
data: JSON.stringify(content),
success: function(data){
if ("Y"==data.ifSuccess){
alert("保存成功!");
} else {
alert("保存失败!");
}
},
error:function (data) {
alert("出错啦!请联系管理员!");
return false;
}
});
}
function selectChangeHistory(){
var redId = getUrlParam("redId");
var docType = "6";
mdEditorForm.method = "post";
// 提交至服务器的路径
mdEditorForm.action = "historyList"+"?redId="+redId+"&documentType="+docType;
mdEditorForm.submit();
}
// 对encodeURI()编码过的 URI 进行解码。
function getUrlParam(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if(r != null){
return decodeURI(r[2]);
}
return "";//如果此处只写return;则返回的是undefined
};
window.onload= function() {
var text = [[${mdText}]];
document.querySelector('.textArea').value =text;
testEditor = editormd("test-editormd", {
width : "90%",
height : 640,
syncScrolling : "single",
path : "../horaeguide/lib/",
/**下述为新增,上面一行记得加逗号结束*/
/*指定需要显示的功能按钮*/
toolbarIcons : function() {
return ["undo", "redo", "|","bold", "italic","ucwords","uppercase","lowercase","|","h1","h2","h3","h4","h5","h6","|","list-ul","list-ol","table","datetime","hr", "||", "watch", "fullscreen", "preview", "releaseIcon", "selectHistoryIcon"]
},
/*自定义功能按钮,下面我自定义了2个,一个是发布,一个是修改历史*/
toolbarIconTexts : {
releaseIcon : "<span bgcolor=\"gray\">发布</span>",
selectHistoryIcon : "<span bgcolor=\"red\">修改历史</span>",
},
/*给自定义按钮指定回调函数*/
toolbarHandlers:{
releaseIcon : function(cm, icon, cursor, selection) {
contentCommit();//提交表单代码在下面
},
selectHistoryIcon : function(cm, icon, cursor, selection) {
selectChangeHistory();// 查询文档修改历史
},
},
// 设置初始化为预览模式
onload:function(){
$('#test-editormd [name="preview"]').click();
}
});
// 对escape()编码的字符串进行解码
function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if(r != null){
return unescape(r[2]);
}
return null;//如果此处只写return;则返回的是undefined
};
}
</script>
</head>
<body>
<div id="layout">
<header>
<h1>test页面</h1>
</header>
// target="_blank" 在新标签页打开页面
<form name="mdEditorForm" target="_blank">
<div id="test-editormd">
<textarea name="content" id="content" style="display:block;" class="textArea"> </textarea>
</div>
</form>
</div>
<script th:src="@{/js/jquery.min.js}"></script>
<script th:src="@{/js/editormd.min.js}"></script>
</body>
</html>
网友评论