forked from gilbitron/Pico-Editor-Plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
editor.html
147 lines (131 loc) · 4.77 KB
/
editor.html
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8" />
<title>Pico Editor</title>
<link rel="stylesheet" href="{{ base_url }}/plugins/pico_editor/pico_editor.css" type="text/css" />
<meta name="robots" content="noindex, nofollow" />
</head>
<body>
<div id="saving">Saving...</div>
<div id="sidebar">
<div class="controls">
<a href="#" class="new btn" title="New">1</a>
<a href="{{ base_url }}/admin/logout" class="logout btn" title="Logout">2</a>
</div>
<ul class="nav">
{% for page in pages %}
<li><a href="#" data-url="{{ page.url }}" class="post"><span data-icon="3" aria-hidden="true"></span>{% if page.title %}{{ page.title }}{% else %}Untitled{% endif %}</a>
<a href="{{ page.url }}" target="_blank" class="view" title="View">5</a>
<a href="#" data-url="{{ page.url }}" class="delete" title="Delete">4</a></li>
{% endfor %}
</ul>
</div>
<div id="main">
<div id="epiceditor"></div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="{{ base_url }}/plugins/pico_editor/epiceditor/js/epiceditor.min.js"></script>
<script>
$(document).ready(function() {
var unsaved = false;
var editor = new EpicEditor({
container: 'epiceditor',
basePath: '{{ base_url }}/plugins/pico_editor/epiceditor',
clientSideStorage: false,
file: {
name: 'epiceditor',
defaultContent: '',
autoSave: 5000
},
theme: {
base: '{{ base_url }}/plugins/pico_editor/epiceditor/themes/base/epiceditor.css',
preview: '{{ base_url }}/plugins/pico_editor/epiceditor/themes/preview/github.css',
editor: '{{ base_url }}/plugins/pico_editor/epiceditor/themes/editor/epic-light.css'
},
button: {
preview: true,
fullscreen: false
},
focusOnLoad: true
}).load();
$(editor.getElement('editor')).on('keyup', function (){
if(!unsaved){
unsaved = true;
document.title += ' *';
}
});
// New
$('.controls .new').on('click', function(e){
e.preventDefault();
var title = prompt('Please enter a post title', '');
if(title != null && title != ''){
$.post('admin/new', { title: title }, function(data){
if(data.error){
alert(data.error);
} else {
$('.nav .post').removeClass('open');
$('#epiceditor').data('currentFile', data.file);
editor.importFile('epiceditor', data.content);
unsaved = false;
document.title = document.title.replace(' *', '');
$('.nav').prepend('<li><a href="#" data-url="{{ base_url }}/'+ data.file +'" class="post open"><span data-icon="3" aria-hidden="true"></span>'+ data.title +'</a><a href="{{ base_url }}/'+ data.file +'" target="_blank" class="view" title="View">5</a><a href="#" data-url="{{ base_url }}/'+ data.file +'" class="delete" title="Delete">4</a></li>')
}
}, 'json');
}
});
// Open post
$('.nav').on('click', '.post', function(e){
e.preventDefault();
if(unsaved && !confirm('You have unsaved changes. Are you sure you want to leave this post?')) return false;
$('.nav .post').removeClass('open');
$(this).addClass('open');
var fileUrl = $(this).attr('data-url');
$.post('admin/open', { file: fileUrl }, function(data){
$('#epiceditor').data('currentFile', fileUrl);
editor.importFile('epiceditor', data);
unsaved = false;
document.title = document.title.replace(' *', '');
});
});
// Save post
editor.on('autosave', function () {
$('#saving').text('Saving...').addClass('active');
$.post('admin/save', { file: $('#epiceditor').data('currentFile'), content: editor.exportFile() }, function(data){
$('#saving').text('Saved');
unsaved = false;
document.title = document.title.replace(' *', '');
setTimeout(function(){
$('#saving').removeClass('active');
}, 1000);
});
});
// Save on preview
editor.on('preview', function () {
editor.emit('autosave');
});
// Delete post
$('.nav').on('click', '.delete', function(e){
e.preventDefault();
if(!confirm('Are you sure you want to delete this file?')) return false;
$('.nav .post').removeClass('open');
var li = $(this).parents('li');
var fileUrl = $(this).attr('data-url');
$.post('admin/delete', { file: fileUrl }, function(data){
li.remove();
$('#epiceditor').data('currentFile', '');
editor.importFile('epiceditor', '');
unsaved = false;
document.title = document.title.replace(' *', '');
});
});
// Window resize
$('body,#main,#epiceditor').height($(window).height());
$(window).resize(function() {
$('body,#main,#epiceditor').height($(window).height());
editor.reflow();
});
});
</script>
</div>
</body>
</html>