2016-09-11 02:53:21 +00:00
|
|
|
|
|
|
|
// ====================================
|
|
|
|
// Markdown Editor
|
|
|
|
// ====================================
|
|
|
|
|
|
|
|
if($('#mk-editor').length === 1) {
|
|
|
|
|
2016-09-11 16:03:06 +00:00
|
|
|
let mdeModalOpenState = false;
|
|
|
|
let mdeCurrentEditor = null;
|
2016-09-11 02:53:21 +00:00
|
|
|
|
2016-09-25 21:32:39 +00:00
|
|
|
Vue.filter('filesize', (v) => {
|
|
|
|
return _.toUpper(filesize(v));
|
2016-10-17 23:52:04 +00:00
|
|
|
});
|
2016-09-25 21:32:39 +00:00
|
|
|
|
2016-09-17 04:26:02 +00:00
|
|
|
//=include editor-image.js
|
2016-12-22 01:38:12 +00:00
|
|
|
//=include editor-file.js
|
2017-01-03 03:20:24 +00:00
|
|
|
//=include editor-video.js
|
2016-09-11 16:03:06 +00:00
|
|
|
//=include editor-codeblock.js
|
2016-09-11 02:53:21 +00:00
|
|
|
|
|
|
|
var mde = new SimpleMDE({
|
|
|
|
autofocus: true,
|
|
|
|
autoDownloadFontAwesome: false,
|
|
|
|
element: $("#mk-editor").get(0),
|
|
|
|
placeholder: 'Enter Markdown formatted content here...',
|
|
|
|
spellChecker: false,
|
|
|
|
status: false,
|
|
|
|
toolbar: [{
|
|
|
|
name: "bold",
|
|
|
|
action: SimpleMDE.toggleBold,
|
2016-12-28 02:46:06 +00:00
|
|
|
className: "icon-bold",
|
2016-09-11 02:53:21 +00:00
|
|
|
title: "Bold",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "italic",
|
|
|
|
action: SimpleMDE.toggleItalic,
|
2016-12-28 02:46:06 +00:00
|
|
|
className: "icon-italic",
|
2016-09-11 02:53:21 +00:00
|
|
|
title: "Italic",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "strikethrough",
|
|
|
|
action: SimpleMDE.toggleStrikethrough,
|
2016-12-28 02:46:06 +00:00
|
|
|
className: "icon-strikethrough",
|
2016-09-11 02:53:21 +00:00
|
|
|
title: "Strikethrough",
|
|
|
|
},
|
|
|
|
'|',
|
|
|
|
{
|
|
|
|
name: "heading-1",
|
|
|
|
action: SimpleMDE.toggleHeading1,
|
2016-12-28 02:46:06 +00:00
|
|
|
className: "icon-header fa-header-x fa-header-1",
|
2016-09-11 02:53:21 +00:00
|
|
|
title: "Big Heading",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "heading-2",
|
|
|
|
action: SimpleMDE.toggleHeading2,
|
2016-12-28 02:46:06 +00:00
|
|
|
className: "icon-header fa-header-x fa-header-2",
|
2016-09-11 02:53:21 +00:00
|
|
|
title: "Medium Heading",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "heading-3",
|
|
|
|
action: SimpleMDE.toggleHeading3,
|
2016-12-28 02:46:06 +00:00
|
|
|
className: "icon-header fa-header-x fa-header-3",
|
2016-09-11 02:53:21 +00:00
|
|
|
title: "Small Heading",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "quote",
|
|
|
|
action: SimpleMDE.toggleBlockquote,
|
2016-12-28 02:46:06 +00:00
|
|
|
className: "icon-quote-left",
|
2016-09-11 02:53:21 +00:00
|
|
|
title: "Quote",
|
|
|
|
},
|
|
|
|
'|',
|
|
|
|
{
|
|
|
|
name: "unordered-list",
|
|
|
|
action: SimpleMDE.toggleUnorderedList,
|
2017-01-03 03:20:24 +00:00
|
|
|
className: "icon-th-list",
|
2016-09-11 02:53:21 +00:00
|
|
|
title: "Bullet List",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "ordered-list",
|
|
|
|
action: SimpleMDE.toggleOrderedList,
|
2016-12-28 02:46:06 +00:00
|
|
|
className: "icon-list-ol",
|
2016-09-11 02:53:21 +00:00
|
|
|
title: "Numbered List",
|
|
|
|
},
|
|
|
|
'|',
|
|
|
|
{
|
|
|
|
name: "link",
|
|
|
|
action: (editor) => {
|
2016-11-29 03:03:18 +00:00
|
|
|
/*if(!mdeModalOpenState) {
|
2016-09-11 16:03:06 +00:00
|
|
|
mdeModalOpenState = true;
|
|
|
|
$('#modal-editor-link').slideToggle();
|
2016-11-29 03:03:18 +00:00
|
|
|
}*/
|
2016-09-11 02:53:21 +00:00
|
|
|
},
|
2016-12-28 02:46:06 +00:00
|
|
|
className: "icon-link2",
|
2016-09-11 02:53:21 +00:00
|
|
|
title: "Insert Link",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "image",
|
|
|
|
action: (editor) => {
|
2016-09-17 04:26:02 +00:00
|
|
|
if(!mdeModalOpenState) {
|
2016-09-19 03:03:19 +00:00
|
|
|
vueImage.open();
|
2016-09-17 04:26:02 +00:00
|
|
|
}
|
2016-09-11 02:53:21 +00:00
|
|
|
},
|
2017-01-03 03:20:24 +00:00
|
|
|
className: "icon-image",
|
2016-09-11 02:53:21 +00:00
|
|
|
title: "Insert Image",
|
|
|
|
},
|
2016-09-12 04:00:52 +00:00
|
|
|
{
|
|
|
|
name: "file",
|
|
|
|
action: (editor) => {
|
2016-12-22 01:38:12 +00:00
|
|
|
if(!mdeModalOpenState) {
|
|
|
|
vueFile.open();
|
|
|
|
}
|
2016-09-12 04:00:52 +00:00
|
|
|
},
|
2017-01-03 03:20:24 +00:00
|
|
|
className: "icon-paper",
|
2016-09-12 04:00:52 +00:00
|
|
|
title: "Insert File",
|
|
|
|
},
|
2016-12-28 02:46:06 +00:00
|
|
|
{
|
|
|
|
name: "video",
|
|
|
|
action: (editor) => {
|
2017-01-03 03:20:24 +00:00
|
|
|
if(!mdeModalOpenState) {
|
|
|
|
vueVideo.open();
|
|
|
|
}
|
2016-12-28 02:46:06 +00:00
|
|
|
},
|
|
|
|
className: "icon-video-camera2",
|
|
|
|
title: "Insert Video Player",
|
|
|
|
},
|
2016-09-11 02:53:21 +00:00
|
|
|
'|',
|
|
|
|
{
|
|
|
|
name: "inline-code",
|
|
|
|
action: (editor) => {
|
2016-09-11 16:03:06 +00:00
|
|
|
|
2016-09-11 02:53:21 +00:00
|
|
|
if(!editor.codemirror.doc.somethingSelected()) {
|
|
|
|
return alerts.pushError('Invalid selection','You must select at least 1 character first.');
|
|
|
|
}
|
|
|
|
let curSel = editor.codemirror.doc.getSelections();
|
|
|
|
curSel = _.map(curSel, (s) => {
|
|
|
|
return '`' + s + '`';
|
|
|
|
});
|
|
|
|
editor.codemirror.doc.replaceSelections(curSel);
|
2016-09-12 04:00:52 +00:00
|
|
|
|
2016-09-11 02:53:21 +00:00
|
|
|
},
|
2016-12-28 02:46:06 +00:00
|
|
|
className: "icon-terminal",
|
2016-09-11 02:53:21 +00:00
|
|
|
title: "Inline Code",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "code-block",
|
|
|
|
action: (editor) => {
|
2016-09-11 16:03:06 +00:00
|
|
|
if(!mdeModalOpenState) {
|
|
|
|
mdeModalOpenState = true;
|
|
|
|
|
|
|
|
if(mde.codemirror.doc.somethingSelected()) {
|
2016-12-22 01:38:12 +00:00
|
|
|
vueCodeBlock.initContent = mde.codemirror.doc.getSelection();
|
2016-09-11 16:03:06 +00:00
|
|
|
}
|
|
|
|
|
2016-12-04 01:20:06 +00:00
|
|
|
vueCodeBlock.open();
|
2016-09-11 16:03:06 +00:00
|
|
|
|
|
|
|
}
|
2016-09-11 02:53:21 +00:00
|
|
|
},
|
2016-12-28 02:46:06 +00:00
|
|
|
className: "icon-code",
|
2016-09-11 02:53:21 +00:00
|
|
|
title: "Code Block",
|
|
|
|
},
|
|
|
|
'|',
|
|
|
|
{
|
|
|
|
name: "table",
|
|
|
|
action: (editor) => {
|
|
|
|
//todo
|
|
|
|
},
|
2016-12-28 02:46:06 +00:00
|
|
|
className: "icon-table",
|
2016-09-11 02:53:21 +00:00
|
|
|
title: "Insert Table",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "horizontal-rule",
|
|
|
|
action: SimpleMDE.drawHorizontalRule,
|
2016-12-28 02:46:06 +00:00
|
|
|
className: "icon-minus2",
|
2016-09-11 02:53:21 +00:00
|
|
|
title: "Horizontal Rule",
|
|
|
|
}
|
|
|
|
],
|
|
|
|
shortcuts: {
|
|
|
|
"toggleBlockquote": null,
|
|
|
|
"toggleFullScreen": null
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-10-17 23:52:04 +00:00
|
|
|
//-> Save
|
2016-09-11 02:53:21 +00:00
|
|
|
|
2016-12-22 01:38:12 +00:00
|
|
|
let saveCurrentDocument = (ev) => {
|
2016-10-17 23:52:04 +00:00
|
|
|
$.ajax(window.location.href, {
|
|
|
|
data: {
|
|
|
|
markdown: mde.value()
|
|
|
|
},
|
|
|
|
dataType: 'json',
|
|
|
|
method: 'PUT'
|
|
|
|
}).then((rData, rStatus, rXHR) => {
|
|
|
|
if(rData.ok) {
|
|
|
|
window.location.assign('/' + pageEntryPath);
|
|
|
|
} else {
|
|
|
|
alerts.pushError('Something went wrong', rData.error);
|
|
|
|
}
|
|
|
|
}, (rXHR, rStatus, err) => {
|
|
|
|
alerts.pushError('Something went wrong', 'Save operation failed.');
|
|
|
|
});
|
2017-01-03 03:20:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$('.btn-edit-save, .btn-create-save').on('click', (ev) => {
|
|
|
|
saveCurrentDocument(ev);
|
|
|
|
});
|
|
|
|
|
|
|
|
$(window).bind('keydown', (ev) => {
|
|
|
|
if (ev.ctrlKey || ev.metaKey) {
|
|
|
|
switch (String.fromCharCode(ev.which).toLowerCase()) {
|
|
|
|
case 's':
|
|
|
|
ev.preventDefault();
|
|
|
|
saveCurrentDocument(ev);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2016-09-11 02:53:21 +00:00
|
|
|
|
2016-10-17 23:52:04 +00:00
|
|
|
}
|