@@ -60,26 +60,29 @@ export default {
6060 this .mde .codemirror .on (' change' , () => {
6161 this .$emit (' input' , this .mde .value ())
6262 })
63- this .initializeCheckboxes ()
63+
64+ document .querySelectorAll (' .CodeMirror-code' ).forEach ((codeElement ) => {
65+ codeElement .addEventListener (' mousedown' , this .onClickCodeElement )
66+ codeElement .addEventListener (' touchstart' , this .onClickCodeElement )
67+ })
6468 },
6569
66- initializeCheckboxes ( ) {
67- // TODO move the following from jQuery to plain JS
68- $ ( ' .CodeMirror-code ' ). on ( ' mousedown.checkbox touchstart.checkbox ' , ' .cm-formatting-task ' , event => {
70+ onClickCodeElement ( event ) {
71+ const element = event . target . closest ( ' .cm-formatting-task ' )
72+ if (element !== null ) {
6973 event .preventDefault ()
7074 event .stopImmediatePropagation ()
7175 this .toggleCheckbox (event .target )
72- })
76+ }
7377 },
7478
7579 toggleCheckbox (el ) {
76- // TODO move the following from jQuery to plain JS
77- const $el = $ (el)
7880 const doc = this .mde .codemirror .getDoc ()
79- const index = $el .parents (' .CodeMirror-line' ).index ()
81+ const domLine = el .closest (' .CodeMirror-line' )
82+ const index = [].indexOf .call (domLine .parentElement .children , domLine)
8083 const line = doc .getLineHandle (index)
8184
82- const newvalue = ($ el .text () === ' [x]' ) ? ' [ ]' : ' [x]'
85+ const newvalue = (el .textContent === ' [x]' ) ? ' [ ]' : ' [x]'
8386
8487 // + 1 for some reason... not sure why
8588 doc .replaceRange (newvalue,
0 commit comments