Create mode + Source view + UI enhancements
This commit is contained in:
@@ -56,6 +56,12 @@ jQuery( document ).ready(function( $ ) {
|
||||
// Pages logic
|
||||
// ====================================
|
||||
|
||||
//=include pages/view.js
|
||||
//=include pages/create.js
|
||||
//=include pages/edit.js
|
||||
//=include pages/source.js
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
//=include helpers/form.js
|
||||
//=include helpers/pages.js
|
16
client/js/helpers/form.js
Normal file
16
client/js/helpers/form.js
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
function setInputSelection(input, startPos, endPos) {
|
||||
input.focus();
|
||||
if (typeof input.selectionStart != "undefined") {
|
||||
input.selectionStart = startPos;
|
||||
input.selectionEnd = endPos;
|
||||
} else if (document.selection && document.selection.createRange) {
|
||||
// IE branch
|
||||
input.select();
|
||||
var range = document.selection.createRange();
|
||||
range.collapse(true);
|
||||
range.moveEnd("character", endPos);
|
||||
range.moveStart("character", startPos);
|
||||
range.select();
|
||||
}
|
||||
}
|
11
client/js/helpers/pages.js
Normal file
11
client/js/helpers/pages.js
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
function makeSafePath(rawPath) {
|
||||
|
||||
let rawParts = _.split(_.trim(rawPath), '/');
|
||||
rawParts = _.map(rawParts, (r) => {
|
||||
return _.kebabCase(_.deburr(_.trim(r)));
|
||||
});
|
||||
|
||||
return _.join(_.filter(rawParts, (r) => { return !_.isEmpty(r); }), '/');
|
||||
|
||||
}
|
32
client/js/pages/create.js
Normal file
32
client/js/pages/create.js
Normal file
@@ -0,0 +1,32 @@
|
||||
|
||||
if($('#page-type-create').length) {
|
||||
|
||||
//-> Discard
|
||||
|
||||
$('.btn-create-discard').on('click', (ev) => {
|
||||
$('#modal-create-discard').toggleClass('is-active');
|
||||
});
|
||||
|
||||
//-> Save
|
||||
|
||||
$('.btn-create-save').on('click', (ev) => {
|
||||
|
||||
$.ajax(window.location.href, {
|
||||
data: {
|
||||
markdown: mde.value()
|
||||
},
|
||||
dataType: 'json',
|
||||
method: 'PUT'
|
||||
}).then((rData, rStatus, rXHR) => {
|
||||
if(rData.ok) {
|
||||
window.location.assign('/' + $('#page-type-create').data('entrypath'));
|
||||
} else {
|
||||
alerts.pushError('Something went wrong', rData.error);
|
||||
}
|
||||
}, (rXHR, rStatus, err) => {
|
||||
alerts.pushError('Something went wrong', 'Save operation failed.');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}
|
12
client/js/pages/source.js
Normal file
12
client/js/pages/source.js
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
if($('#page-type-source').length) {
|
||||
|
||||
var scEditor = ace.edit("source-display");
|
||||
scEditor.setTheme("ace/theme/tomorrow_night");
|
||||
scEditor.getSession().setMode("ace/mode/markdown");
|
||||
scEditor.setReadOnly(true);
|
||||
scEditor.renderer.updateFull();
|
||||
|
||||
console.log(scEditor.getSession().getLength());
|
||||
|
||||
}
|
34
client/js/pages/view.js
Normal file
34
client/js/pages/view.js
Normal file
@@ -0,0 +1,34 @@
|
||||
|
||||
if($('#page-type-view').length) {
|
||||
|
||||
let currentBasePath = ($('#page-type-view').data('entrypath') !== 'home') ? $('#page-type-view').data('entrypath') + '/' : '';
|
||||
let suggestedCreatePath = currentBasePath + 'new-page';
|
||||
|
||||
//-> Create New Document
|
||||
|
||||
$('.btn-create-prompt').on('click', (ev) => {
|
||||
$('#txt-create-prompt').val(suggestedCreatePath);
|
||||
$('#modal-create-prompt').toggleClass('is-active');
|
||||
setInputSelection($('#txt-create-prompt').get(0), currentBasePath.length, suggestedCreatePath.length);
|
||||
$('#txt-create-prompt').removeClass('is-danger').next().addClass('is-hidden');
|
||||
});
|
||||
|
||||
$('#txt-create-prompt').on('keypress', (ev) => {
|
||||
if(ev.which === 13) {
|
||||
$('.btn-create-go').trigger('click');
|
||||
}
|
||||
});
|
||||
|
||||
$('.btn-create-go').on('click', (ev) => {
|
||||
|
||||
let newDocPath = makeSafePath($('#txt-create-prompt').val());
|
||||
if(_.isEmpty(newDocPath)) {
|
||||
$('#txt-create-prompt').addClass('is-danger').next().removeClass('is-hidden');
|
||||
} else {
|
||||
$('#txt-create-prompt').parent().addClass('is-loading');
|
||||
window.location.assign('/create/' + newDocPath);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
Reference in New Issue
Block a user