Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e4bb7a9

Browse files
committed
[shengqi] #57 自动保存已编辑未创建的话题
1 parent 9e35d04 commit e4bb7a9

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/Discussion.Web/wwwroot/scripts/markdown-editor.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,22 @@ import * as imageResizing from './editor/image-resize'
1919
export function setupEditor(userCanImport) {
2020
var editorOptions = defaultEditorOptions();
2121

22-
$('#content-editor').summernote(editorOptions);
22+
var editor = $('#content-editor');
23+
editor.summernote(editorOptions);
24+
25+
var contentEditor = editor.data('summernote');
26+
var draft = localStorage.getItem('draft');
27+
if(draft){
28+
contentEditor.layoutInfo.editable.html(draft);
29+
contentEditor.triggerEvent('change');
30+
}
31+
32+
setInterval(function(){
33+
var contentEditor = $('#content-editor').data('summernote');
34+
var htmlContent = contentEditor.code();
35+
localStorage.setItem('draft', htmlContent);
36+
}, 5000);
37+
2338
$('#topic-type-dropdown .topic-type-item').on('click', function (e) {
2439
var item = $(this);
2540

@@ -60,6 +75,7 @@ export function setupEditor(userCanImport) {
6075
}
6176
$.post(url, newTopic)
6277
.done(function () {
78+
localStorage.removeItem('draft');
6379
location.replace("/");
6480
}).fail(function(){
6581
console.error('error on creating new topic');
@@ -106,6 +122,7 @@ export function setupEditor(userCanImport) {
106122
}
107123
}
108124

125+
109126
function defaultEditorOptions(){
110127
var options = $.extend({}, $.summernote.options, {
111128
lang: 'zh-CN',

tools/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Cake" version="0.30.0" />
3+
<package id="Cake" version="0.37.0" />
44
</packages>

0 commit comments

Comments
 (0)