diff --git a/.eslintrc.js b/.eslintrc.js index 565d05ce..4b5581fc 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -2,9 +2,6 @@ module.exports = { extends: [ '@nextcloud', ], - globals: { - $: 'readonly', - }, rules: { // no ending html tag on a new line (was warn in "vue/strongly-recommended") 'vue/html-closing-bracket-newline': ['error', { multiline: 'always' }], diff --git a/src/components/EditorEasyMDE.vue b/src/components/EditorEasyMDE.vue index ea817fd8..b92d71f6 100644 --- a/src/components/EditorEasyMDE.vue +++ b/src/components/EditorEasyMDE.vue @@ -60,26 +60,29 @@ export default { this.mde.codemirror.on('change', () => { this.$emit('input', this.mde.value()) }) - this.initializeCheckboxes() - }, - initializeCheckboxes() { - // TODO move the following from jQuery to plain JS - $('.CodeMirror-code').on('mousedown.checkbox touchstart.checkbox', '.cm-formatting-task', event => { - event.preventDefault() - event.stopImmediatePropagation() - this.toggleCheckbox(event.target) + document.querySelectorAll('.CodeMirror-code').forEach((codeElement) => { + codeElement.addEventListener('mousedown', this.onClickCodeElement) + codeElement.addEventListener('touchstart', this.onClickCodeElement) }) }, + onClickCodeElement(event) { + const element = event.target.closest('.cm-formatting-task') + if (element !== null) { + event.preventDefault() + event.stopImmediatePropagation() + this.toggleCheckbox(event.target) + } + }, + toggleCheckbox(el) { - // TODO move the following from jQuery to plain JS - const $el = $(el) const doc = this.mde.codemirror.getDoc() - const index = $el.parents('.CodeMirror-line').index() + const domLine = el.closest('.CodeMirror-line') + const index = [].indexOf.call(domLine.parentElement.children, domLine) const line = doc.getLineHandle(index) - const newvalue = ($el.text() === '[x]') ? '[ ]' : '[x]' + const newvalue = (el.textContent === '[x]') ? '[ ]' : '[x]' // + 1 for some reason... not sure why doc.replaceRange(newvalue, diff --git a/src/components/Note.vue b/src/components/Note.vue index ab4acc85..d04dbd86 100644 --- a/src/components/Note.vue +++ b/src/components/Note.vue @@ -126,13 +126,17 @@ export default { created() { this.fetchData() - // TODO move the following from jQuery to plain JS - $(document).bind('webkitfullscreenchange mozfullscreenchange fullscreenchange', this.onDetectFullscreen) - $(document).bind('keypress.notes.save', this.onKeyPress) + document.addEventListener('webkitfullscreenchange', this.onDetectFullscreen) + document.addEventListener('mozfullscreenchange', this.onDetectFullscreen) + document.addEventListener('fullscreenchange', this.onDetectFullscreen) + document.addEventListener('keydown', this.onKeyPress) }, destroyed() { - $(document).unbind('keypress.notes.save') + document.removeEventListener('webkitfullscreenchange', this.onDetectFullscreen) + document.removeEventListener('mozfullscreenchange', this.onDetectFullscreen) + document.removeEventListener('fullscreenchange', this.onDetectFullscreen) + document.removeEventListener('keydown', this.onKeyPress) store.commit('setSidebarOpen', false) this.onUpdateTitle(null) }, @@ -246,6 +250,11 @@ export default { }, onManualSave() { + const note = { + ...this.note, + autotitle: routeIsNewNote(this.$route), + } + store.commit('add', note) saveNoteManually(this.note.id) }, },