Browse Source

remove jQuery usage

pull/532/head
korelstar 11 months ago
parent
commit
ca89679fbd
  1. 3
      .eslintrc.js
  2. 21
      src/components/EditorEasyMDE.vue
  3. 17
      src/components/Note.vue

3
.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' }],

21
src/components/EditorEasyMDE.vue

@ -60,26 +60,29 @@ export default {
this.mde.codemirror.on('change', () => {
this.$emit('input', this.mde.value())
})
this.initializeCheckboxes()
document.querySelectorAll('.CodeMirror-code').forEach((codeElement) => {
codeElement.addEventListener('mousedown', this.onClickCodeElement)
codeElement.addEventListener('touchstart', this.onClickCodeElement)
})
},
initializeCheckboxes() {
// TODO move the following from jQuery to plain JS
$('.CodeMirror-code').on('mousedown.checkbox touchstart.checkbox', '.cm-formatting-task', event => {
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,

17
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)
},
},

Loading…
Cancel
Save