Fix todo checkboxes
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Peter Stuifzand 2020-10-27 00:14:45 +01:00
parent 891390d98e
commit 12ea8c3cc4
2 changed files with 20 additions and 17 deletions

View File

@ -219,6 +219,7 @@ function Editor(holder, input) {
if (text === undefined) { if (text === undefined) {
return; return;
} }
if (!scope) { if (!scope) {
scope = editor.scope || {} scope = editor.scope || {}
} }
@ -264,9 +265,10 @@ function Editor(holder, input) {
holder.$listEditor = editor holder.$listEditor = editor
editor.scope = {} editor.scope = {}
$(holder).find('.content input[type="checkbox"]').on('click', function (event) { $(holder).on('click', '.content input[type="checkbox"]', function (event) {
let that = this let that = this
let id = $(this).closest('.list-item').data('id') let li = $(this).parents('.list-item');
let id = li.attr('data-id')
editor.update(id, function (item, prev, next) { editor.update(id, function (item, prev, next) {
if (that.checked) { if (that.checked) {
item.text = item.text.replace('#[[TODO]]', '#[[DONE]]') item.text = item.text.replace('#[[TODO]]', '#[[DONE]]')
@ -275,8 +277,7 @@ function Editor(holder, input) {
} }
return item return item
}); });
event.stopPropagation() return true
return false
}) })
editor.on('change', function () { editor.on('change', function () {
@ -491,7 +492,6 @@ function Editor(holder, input) {
}) })
} }
let timeout = null;
let searchInput = document.getElementById('search-input'); let searchInput = document.getElementById('search-input');
search(searchInput).then(searcher => { search(searchInput).then(searcher => {
let showSearch = _.debounce(function (searcher) { let showSearch = _.debounce(function (searcher) {

View File

@ -52,7 +52,7 @@ function editor(root, inputData, options) {
function copy(element, opt) { function copy(element, opt) {
let item = $(element).parents('.list-item') let item = $(element).parents('.list-item')
let id = item.data('id') let id = item.attr('data-id')
if (opt.recursive) { if (opt.recursive) {
return saveTree(id) return saveTree(id)
@ -65,7 +65,7 @@ function editor(root, inputData, options) {
function zoomin(element, opt) { function zoomin(element, opt) {
let item = $(element).parents('.list-item') let item = $(element).parents('.list-item')
let id = item.data('id') let id = item.attr('data-id')
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
resolve(id); resolve(id);
}); });
@ -134,7 +134,7 @@ function editor(root, inputData, options) {
function newItem(value) { function newItem(value) {
let el = $('<div class="list-item">') let el = $('<div class="list-item">')
.data('id', value.id) .attr('data-id', value.id)
.data('indented', value.indented) .data('indented', value.indented)
.css('margin-left', (value.indented * 32) + 'px') .css('margin-left', (value.indented * 32) + 'px')
let line = $('<div class="line">') let line = $('<div class="line">')
@ -177,7 +177,8 @@ function editor(root, inputData, options) {
hasChildren = next && (value.indented < next.indented) hasChildren = next && (value.indented < next.indented)
} }
let $li = $(li).data('id', value.id) let $li = $(li)
.attr('data-id', value.id)
.toggleClass('selected', cursor.atPosition(index)) .toggleClass('selected', cursor.atPosition(index))
.toggleClass('selection-first', selection.isSelectedFirst(index)) .toggleClass('selection-first', selection.isSelectedFirst(index))
.toggleClass('selection-last', selection.isSelectedLast(index)) .toggleClass('selection-last', selection.isSelectedLast(index))
@ -185,10 +186,10 @@ function editor(root, inputData, options) {
.toggleClass('hidden', value.indented >= hideLevel) .toggleClass('hidden', value.indented >= hideLevel)
.toggleClass('border', value.indented >= 1) .toggleClass('border', value.indented >= 1)
.css('margin-left', (value.indented * 32) + 'px') .css('margin-left', (value.indented * 32) + 'px')
.find('.content')
value.hidden = value.indented >= hideLevel value.hidden = value.indented >= hideLevel
options.transform(value.text, $li, value.id, EDITOR) options.transform(value.text, $li.find('.content'), value.id, EDITOR)
if (value.indented < hideLevel) { if (value.indented < hideLevel) {
if (value.fold !== 'open') { if (value.fold !== 'open') {
@ -202,7 +203,7 @@ function editor(root, inputData, options) {
.toggleClass('open', value.fold === 'open') .toggleClass('open', value.fold === 'open')
.toggleClass('no-children', !hasChildren) .toggleClass('no-children', !hasChildren)
$(li).toggleClass('no-children', !hasChildren) $li.toggleClass('no-children', !hasChildren)
.toggleClass('open', value.fold === 'open') .toggleClass('open', value.fold === 'open')
}); });
@ -262,12 +263,12 @@ function editor(root, inputData, options) {
let startID = null; let startID = null;
drake.on('drag', function (el, source) { drake.on('drag', function (el, source) {
startID = $(el).data('id') startID = $(el).attr('data-id')
}) })
drake.on('drop', function (el, target, source, sibling) { drake.on('drop', function (el, target, source, sibling) {
let stopID = $(sibling).data('id') let stopID = $(sibling).attr('data-id')
if (startID === stopID) { if (startID === stopID) {
return return
} }
@ -293,7 +294,7 @@ function editor(root, inputData, options) {
let text = element.val() let text = element.val()
$(element).closest('.list-item').removeClass('editor'); $(element).closest('.list-item').removeClass('editor');
store.update(element.data('id'), (value) => { store.update(element.attr('data-id'), (value) => {
return _.merge(value, { return _.merge(value, {
text: text text: text
}) })
@ -305,7 +306,7 @@ function editor(root, inputData, options) {
} }
let $span = $('<div class="content">'); let $span = $('<div class="content">');
options.transform(text, $span, element.data('id'), EDITOR) options.transform(text, $span, element.attr('data-id'), EDITOR)
element.replaceWith($span); element.replaceWith($span);
trigger('stop-editing', currentEditor[0]) trigger('stop-editing', currentEditor[0])
editing = false editing = false
@ -479,6 +480,8 @@ function editor(root, inputData, options) {
}) })
$(root).on('click', '.content', function (event) { $(root).on('click', '.content', function (event) {
if ($(event.target).hasClass('checkbox')) return true;
let currentIndex = $(root).children('div.list-item').index($(this).parents('.list-item')[0]) let currentIndex = $(root).children('div.list-item').index($(this).parents('.list-item')[0])
if (cursor.atPosition(currentIndex) && currentEditor !== null && currentEditor.closest('.list-item')[0] === this) { if (cursor.atPosition(currentIndex) && currentEditor !== null && currentEditor.closest('.list-item')[0] === this) {
return true return true
@ -506,7 +509,7 @@ function editor(root, inputData, options) {
let item = $(this).parents('.list-item') let item = $(this).parents('.list-item')
let elements = $(root).children('div.list-item'); let elements = $(root).children('div.list-item');
let index = elements.index(item) let index = elements.index(item)
store.update(item.data('id'), function (item) { store.update(item.attr('data-id'), function (item) {
item.fold = open ? 'open' : 'closed' item.fold = open ? 'open' : 'closed'
return item return item
}) })