2017-02-10 01:24:28 +00:00
|
|
|
/* global $, _, currentBasePath */
|
2016-09-09 23:22:18 +00:00
|
|
|
|
2017-02-09 01:52:37 +00:00
|
|
|
// -> Create New Document
|
2016-09-09 23:22:18 +00:00
|
|
|
|
2017-02-09 01:52:37 +00:00
|
|
|
let suggestedCreatePath = currentBasePath + '/new-page'
|
2016-09-09 23:22:18 +00:00
|
|
|
|
|
|
|
$('.btn-create-prompt').on('click', (ev) => {
|
2017-02-09 01:52:37 +00:00
|
|
|
$('#txt-create-prompt').val(suggestedCreatePath)
|
|
|
|
$('#modal-create-prompt').toggleClass('is-active')
|
2017-02-10 01:24:28 +00:00
|
|
|
setInputSelection($('#txt-create-prompt').get(0), currentBasePath.length + 1, suggestedCreatePath.length) // eslint-disable-line no-undef
|
2017-02-09 01:52:37 +00:00
|
|
|
$('#txt-create-prompt').removeClass('is-danger').next().addClass('is-hidden')
|
|
|
|
})
|
2016-09-09 23:22:18 +00:00
|
|
|
|
|
|
|
$('#txt-create-prompt').on('keypress', (ev) => {
|
2017-02-09 01:52:37 +00:00
|
|
|
if (ev.which === 13) {
|
|
|
|
$('.btn-create-go').trigger('click')
|
|
|
|
}
|
|
|
|
})
|
2016-09-09 23:22:18 +00:00
|
|
|
|
|
|
|
$('.btn-create-go').on('click', (ev) => {
|
2017-02-10 01:24:28 +00:00
|
|
|
let newDocPath = makeSafePath($('#txt-create-prompt').val()) // eslint-disable-line no-undef
|
2017-02-09 01:52:37 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
})
|