create.js 997 Bytes
Newer Older
1
/* global $, _, currentBasePath */
NGPixel's avatar
NGPixel committed
2

3
// -> Create New Document
NGPixel's avatar
NGPixel committed
4

5
let suggestedCreatePath = currentBasePath + '/new-page'
NGPixel's avatar
NGPixel committed
6 7

$('.btn-create-prompt').on('click', (ev) => {
8 9
  $('#txt-create-prompt').val(suggestedCreatePath)
  $('#modal-create-prompt').toggleClass('is-active')
10
  setInputSelection($('#txt-create-prompt').get(0), currentBasePath.length + 1, suggestedCreatePath.length) // eslint-disable-line no-undef
11 12
  $('#txt-create-prompt').removeClass('is-danger').next().addClass('is-hidden')
})
NGPixel's avatar
NGPixel committed
13 14

$('#txt-create-prompt').on('keypress', (ev) => {
15 16 17 18
  if (ev.which === 13) {
    $('.btn-create-go').trigger('click')
  }
})
NGPixel's avatar
NGPixel committed
19 20

$('.btn-create-go').on('click', (ev) => {
21
  let newDocPath = makeSafePath($('#txt-create-prompt').val()) // eslint-disable-line no-undef
22 23 24 25 26 27 28
  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)
  }
})