-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
editor.js
86 lines (82 loc) · 1.8 KB
/
editor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* Editor Script
*
* @package WikiDocs
* @repository https://github.com/Zavy86/wikidocs
*/
/**
* Simple Markdown Editor (EasyMDE)
*/
var simplemde=new EasyMDE({
element:document.getElementById("simplemde"),
autoDownloadFontAwesome:false,
spellChecker:false,
autofocus:true,
forceSync:true,
//hideIcons:["image"],
showIcons:["code","table"],
blockStyles:{
bold:"**",
italic:"*",
code:"```"
}
});
/**
* Changed status
*/
var changed=false;
var changed_draft=false;
/**
* Event Handlers
*/
// content changed
simplemde.codemirror.on("change",function(){changed=true;changed_draft=true;});
// prevent exit without save
$(window).on("beforeunload",function(){if(changed){return confirm("Do you really want to exit without save?");}});
// save button click
$("#editor-save").click(function(){
//if(!changed){return false;}
changed=false;
$("#editor-form").submit();
});
// revision change
$("#editor-revision").click(function(){
if($("input[name='revision']").val()==="1"){
$("input[name='revision']").val("0");
$("#editor-revision-checkbox").text("check_box_outline_blank");
}else{
$("input[name='revision']").val("1");
$("#editor-revision-checkbox").text("check_box");
}
});
/**
* Timer Handler
*/
setInterval(function(){
if(changed_draft){
$.ajax({
url:APP.URL+"submit.php?act=draft_save_ajax",
type:"POST",
data:{
document:DOC.ID,
content:$("textarea[name='content']").val()
},
cache:false,
success:function(response){
// decode response
decoded=JSON.parse(response);
// alert if error
if(decoded.error===1){
alert(decoded.code);
}else{
// drfat saved
changed_draft=false;
}
},
error:function(XMLHttpRequest,textStatus,errorThrown){
// alert
alert("Status: "+textStatus+" Error: "+errorThrown);
}
});
}
},10000);