From 5dfc6da7c95d6de6f9f65895dabc2e38834dc68d Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Fri, 18 Jan 2019 17:59:29 -0700 Subject: [PATCH] Add checklist item toggling (close #2) --- config.xml | 2 +- package.json | 2 +- www/css/notecards.css | 29 +++++++++++++++++++++++ www/js/home.js | 54 ++++++++++++++++++++++++++++++++++++++++++- www/package.json | 2 +- www/routes.js | 2 +- 6 files changed, 86 insertions(+), 5 deletions(-) diff --git a/config.xml b/config.xml index 00388bc..a74f3df 100644 --- a/config.xml +++ b/config.xml @@ -1,5 +1,5 @@ - + NotePost A cross-platform client app for NotePost. diff --git a/package.json b/package.json index 61b0573..488c9a7 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "com.netsyms.NotePostApp", "displayName": "NotePost", - "version": "1.0.0", + "version": "1.1.0", "description": "A cross-platform client app for NotePost.", "main": "index.js", "scripts": { diff --git a/www/css/notecards.css b/www/css/notecards.css index 5de0bc2..7799ee7 100644 --- a/www/css/notecards.css +++ b/www/css/notecards.css @@ -86,6 +86,35 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. background-image: url(../img/starbg_light.svg); } +.notecard .card-content ul, .notecard .card-content ol { + padding-left: 0; +} + +.notecard .card-content li > ul, .notecard .card-content li > ol { + padding-left: 1em; +} + +.notecard .card-content li > ul > li.parsedown-task-list-close, .notecard .card-content li > ul > li.parsedown-task-list-open { + margin-left: 1em; +} + +.notecard .card-content li:not(.parsedown-task-list-close):not(.parsedown-task-list-open) { + margin-left: 1em; +} + +.parsedown-task-list-close { + text-decoration: line-through; + list-style-type: none; +} + +.parsedown-task-list-open { + list-style-type: none; +} + +.parsedown-task-list { + cursor: pointer; +} + .popover .list .list-button { color: inherit; } \ No newline at end of file diff --git a/www/js/home.js b/www/js/home.js index 136d458..2df729e 100644 --- a/www/js/home.js +++ b/www/js/home.js @@ -19,6 +19,55 @@ $(".view-main").on("input change", "#searchbar-input", function () { }); }); +$(".view-main").on("click", ".parsedown-task-list", function (e) { + var noteid = $(this).closest(".notecard").data("id"); + var note = NOTES.get(noteid); + var checkbox = $(this).find("input[type=checkbox]"); + var line = $(this); + var text = line.text().trim(); + // The checkbox has already changed by itself if it was clicked directly + var checked = checkbox.prop("checked"); + if (e.target.nodeName != "INPUT") { + checked = !checked; + } + console.log(checkbox); + console.log(line); + console.log(checked); + + var lines = note.content.split("\n"); + var newcontent = ""; + + for (i in lines) { + var li = lines[i].trim(); + if (!li.match(/^- \[[x ]\] .*/i)) { + continue; + } + var linecleaned = li.replace(/^- \[[x ]\] /i, '').trim(); + if (text != linecleaned) { + continue; + } + if (li.match(/^- \[[x]\] .*/i)) { + lines[i] = li.replace(/^- \[[x]\] /i, "- [ ] "); + line.addClass("parsedown-task-list-open"); + line.removeClass("parsedown-task-list-close"); + checkbox.prop("checked", false); + } else if (li.match(/^- \[[ ]\] .*/i)) { + lines[i] = li.replace(/^- \[[ ]\] /i, "- [x] "); + line.addClass("parsedown-task-list-close"); + line.removeClass("parsedown-task-list-open"); + checkbox.prop("checked", true); + } + } + + note.content = lines.join("\n"); + note.modified = null; + note.html = null; + + NOTES.set(NOTES.fix(note)); + + NOTES.sync(); +}); + function loadCards(callback) { // Do it twice as a workaround for the stupid sync issue NOTES.sync(function () { @@ -46,7 +95,10 @@ function loadCards(callback) { id: note.noteid }); } - console.log(trayitems); + $(".notecard .card-content ul li:has(input[type=checkbox])").addClass("parsedown-task-list"); + $(".notecard .card-content ul li:has(input[type=checkbox]:checkbox:not(:checked))").addClass("parsedown-task-list-open"); + $(".notecard .card-content ul li:has(input[type=checkbox]:checkbox:checked)").addClass("parsedown-task-list-close"); + $(".parsedown-task-list input[type=checkbox]").removeAttr("disabled"); var noteElements = document.getElementsByClassName("notecard-col"); window.shuffleInstance.add(noteElements); window.shuffleInstance.sort({ diff --git a/www/package.json b/www/package.json index cea2176..b574e41 100644 --- a/www/package.json +++ b/www/package.json @@ -1,7 +1,7 @@ { "name": "com.netsyms.NotePostApp", "displayName": "NotePost", - "version": "1.0.0", + "version": "1.1.0", "description": "A cross-platform client app for NotePost.", "author": "Netsyms Technologies", "license": "MPL-2.0", diff --git a/www/routes.js b/www/routes.js index 671cd43..bb51904 100644 --- a/www/routes.js +++ b/www/routes.js @@ -109,7 +109,7 @@ var routes = [ }, { setting: "versions", - title: "NotePost app v1.0.0", + title: "NotePost app v1.1.0", text: "Copyright © 2018-2019 Netsyms Technologies. License: Mozilla Public License 2.0.", onclick: "" },