remove jQuery usage

This commit is contained in:
korelstar 2020-06-05 23:09:39 +02:00
parent df28f31ac6
commit ca89679fbd
3 changed files with 28 additions and 19 deletions

View File

@ -2,9 +2,6 @@ module.exports = {
extends: [ extends: [
'@nextcloud', '@nextcloud',
], ],
globals: {
$: 'readonly',
},
rules: { rules: {
// no ending html tag on a new line (was warn in "vue/strongly-recommended") // no ending html tag on a new line (was warn in "vue/strongly-recommended")
'vue/html-closing-bracket-newline': ['error', { multiline: 'always' }], 'vue/html-closing-bracket-newline': ['error', { multiline: 'always' }],

View File

@ -60,26 +60,29 @@ export default {
this.mde.codemirror.on('change', () => { this.mde.codemirror.on('change', () => {
this.$emit('input', this.mde.value()) this.$emit('input', this.mde.value())
}) })
this.initializeCheckboxes()
},
initializeCheckboxes() { document.querySelectorAll('.CodeMirror-code').forEach((codeElement) => {
// TODO move the following from jQuery to plain JS codeElement.addEventListener('mousedown', this.onClickCodeElement)
$('.CodeMirror-code').on('mousedown.checkbox touchstart.checkbox', '.cm-formatting-task', event => { codeElement.addEventListener('touchstart', this.onClickCodeElement)
event.preventDefault()
event.stopImmediatePropagation()
this.toggleCheckbox(event.target)
}) })
}, },
onClickCodeElement(event) {
const element = event.target.closest('.cm-formatting-task')
if (element !== null) {
event.preventDefault()
event.stopImmediatePropagation()
this.toggleCheckbox(event.target)
}
},
toggleCheckbox(el) { toggleCheckbox(el) {
// TODO move the following from jQuery to plain JS
const $el = $(el)
const doc = this.mde.codemirror.getDoc() 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 line = doc.getLineHandle(index)
const newvalue = ($el.text() === '[x]') ? '[ ]' : '[x]' const newvalue = (el.textContent === '[x]') ? '[ ]' : '[x]'
// + 1 for some reason... not sure why // + 1 for some reason... not sure why
doc.replaceRange(newvalue, doc.replaceRange(newvalue,

View File

@ -126,13 +126,17 @@ export default {
created() { created() {
this.fetchData() this.fetchData()
// TODO move the following from jQuery to plain JS document.addEventListener('webkitfullscreenchange', this.onDetectFullscreen)
$(document).bind('webkitfullscreenchange mozfullscreenchange fullscreenchange', this.onDetectFullscreen) document.addEventListener('mozfullscreenchange', this.onDetectFullscreen)
$(document).bind('keypress.notes.save', this.onKeyPress) document.addEventListener('fullscreenchange', this.onDetectFullscreen)
document.addEventListener('keydown', this.onKeyPress)
}, },
destroyed() { 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) store.commit('setSidebarOpen', false)
this.onUpdateTitle(null) this.onUpdateTitle(null)
}, },
@ -246,6 +250,11 @@ export default {
}, },
onManualSave() { onManualSave() {
const note = {
...this.note,
autotitle: routeIsNewNote(this.$route),
}
store.commit('add', note)
saveNoteManually(this.note.id) saveNoteManually(this.note.id)
}, },
}, },