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.

35 lines
1.1 KiB

  1. 'use strict'
  2. import $ from 'jquery'
  3. import _ from 'lodash'
  4. import { setInputSelection } from '../helpers/form'
  5. import { makeSafePath } from '../helpers/pages'
  6. // -> Create New Document
  7. module.exports = (currentBasePath) => {
  8. let suggestedCreatePath = currentBasePath + '/new-page'
  9. $('.btn-create-prompt').on('click', (ev) => {
  10. $('#txt-create-prompt').val(suggestedCreatePath)
  11. $('#modal-create-prompt').toggleClass('is-active')
  12. setInputSelection($('#txt-create-prompt').get(0), currentBasePath.length + 1, suggestedCreatePath.length)
  13. $('#txt-create-prompt').removeClass('is-danger').next().addClass('is-hidden')
  14. })
  15. $('#txt-create-prompt').on('keypress', (ev) => {
  16. if (ev.which === 13) {
  17. $('.btn-create-go').trigger('click')
  18. }
  19. })
  20. $('.btn-create-go').on('click', (ev) => {
  21. let newDocPath = makeSafePath($('#txt-create-prompt').val())
  22. if (_.isEmpty(newDocPath)) {
  23. $('#txt-create-prompt').addClass('is-danger').next().removeClass('is-hidden')
  24. } else {
  25. $('#txt-create-prompt').parent().addClass('is-loading')
  26. window.location.assign('/create/' + newDocPath)
  27. }
  28. })
  29. }