You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
997 B

  1. /* global $, _, currentBasePath */
  2. // -> Create New Document
  3. let suggestedCreatePath = currentBasePath + '/new-page'
  4. $('.btn-create-prompt').on('click', (ev) => {
  5. $('#txt-create-prompt').val(suggestedCreatePath)
  6. $('#modal-create-prompt').toggleClass('is-active')
  7. setInputSelection($('#txt-create-prompt').get(0), currentBasePath.length + 1, suggestedCreatePath.length) // eslint-disable-line no-undef
  8. $('#txt-create-prompt').removeClass('is-danger').next().addClass('is-hidden')
  9. })
  10. $('#txt-create-prompt').on('keypress', (ev) => {
  11. if (ev.which === 13) {
  12. $('.btn-create-go').trigger('click')
  13. }
  14. })
  15. $('.btn-create-go').on('click', (ev) => {
  16. let newDocPath = makeSafePath($('#txt-create-prompt').val()) // eslint-disable-line no-undef
  17. if (_.isEmpty(newDocPath)) {
  18. $('#txt-create-prompt').addClass('is-danger').next().removeClass('is-hidden')
  19. } else {
  20. $('#txt-create-prompt').parent().addClass('is-loading')
  21. window.location.assign('/create/' + newDocPath)
  22. }
  23. })