Browse Source

Add checklist item toggling (close #2)

Skylar Ittner 4 weeks ago
parent
commit
5dfc6da7c9
6 changed files with 86 additions and 5 deletions
  1. 1
    1
      config.xml
  2. 1
    1
      package.json
  3. 29
    0
      www/css/notecards.css
  4. 53
    1
      www/js/home.js
  5. 1
    1
      www/package.json
  6. 1
    1
      www/routes.js

+ 1
- 1
config.xml View File

@@ -1,5 +1,5 @@
1 1
 <?xml version='1.0' encoding='utf-8'?>
2
-<widget id="com.netsyms.NotePostApp" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cdv="http://cordova.apache.org/ns/1.0">
2
+<widget id="com.netsyms.NotePostApp" version="1.1.0" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cdv="http://cordova.apache.org/ns/1.0">
3 3
     <name>NotePost</name>
4 4
     <description>
5 5
         A cross-platform client app for NotePost.

+ 1
- 1
package.json View File

@@ -1,7 +1,7 @@
1 1
 {
2 2
   "name": "com.netsyms.NotePostApp",
3 3
   "displayName": "NotePost",
4
-  "version": "1.0.0",
4
+  "version": "1.1.0",
5 5
   "description": "A cross-platform client app for NotePost.",
6 6
   "main": "index.js",
7 7
   "scripts": {

+ 29
- 0
www/css/notecards.css View File

@@ -86,6 +86,35 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
86 86
     background-image: url(../img/starbg_light.svg);
87 87
 }
88 88
 
89
+.notecard .card-content ul, .notecard .card-content ol {
90
+    padding-left: 0;
91
+}
92
+
93
+.notecard .card-content li > ul, .notecard .card-content li > ol {
94
+    padding-left: 1em;
95
+}
96
+
97
+.notecard .card-content li > ul > li.parsedown-task-list-close, .notecard .card-content li > ul > li.parsedown-task-list-open {
98
+    margin-left: 1em;
99
+}
100
+
101
+.notecard .card-content li:not(.parsedown-task-list-close):not(.parsedown-task-list-open) {
102
+    margin-left: 1em;
103
+}
104
+
105
+.parsedown-task-list-close {
106
+    text-decoration: line-through;
107
+    list-style-type: none;
108
+}
109
+
110
+.parsedown-task-list-open {
111
+    list-style-type: none;
112
+}
113
+
114
+.parsedown-task-list {
115
+    cursor: pointer;
116
+}
117
+
89 118
 .popover .list .list-button {
90 119
     color: inherit;
91 120
 }

+ 53
- 1
www/js/home.js View File

@@ -19,6 +19,55 @@ $(".view-main").on("input change", "#searchbar-input", function () {
19 19
     });
20 20
 });
21 21
 
22
+$(".view-main").on("click", ".parsedown-task-list", function (e) {
23
+    var noteid = $(this).closest(".notecard").data("id");
24
+    var note = NOTES.get(noteid);
25
+    var checkbox = $(this).find("input[type=checkbox]");
26
+    var line = $(this);
27
+    var text = line.text().trim();
28
+    // The checkbox has already changed by itself if it was clicked directly
29
+    var checked = checkbox.prop("checked");
30
+    if (e.target.nodeName != "INPUT") {
31
+        checked = !checked;
32
+    }
33
+    console.log(checkbox);
34
+    console.log(line);
35
+    console.log(checked);
36
+
37
+    var lines = note.content.split("\n");
38
+    var newcontent = "";
39
+
40
+    for (i in lines) {
41
+        var li = lines[i].trim();
42
+        if (!li.match(/^- \[[x ]\] .*/i)) {
43
+            continue;
44
+        }
45
+        var linecleaned = li.replace(/^- \[[x ]\] /i, '').trim();
46
+        if (text != linecleaned) {
47
+            continue;
48
+        }
49
+        if (li.match(/^- \[[x]\] .*/i)) {
50
+            lines[i] = li.replace(/^- \[[x]\] /i, "- [ ] ");
51
+            line.addClass("parsedown-task-list-open");
52
+            line.removeClass("parsedown-task-list-close");
53
+            checkbox.prop("checked", false);
54
+        } else if (li.match(/^- \[[ ]\] .*/i)) {
55
+            lines[i] = li.replace(/^- \[[ ]\] /i, "- [x] ");
56
+            line.addClass("parsedown-task-list-close");
57
+            line.removeClass("parsedown-task-list-open");
58
+            checkbox.prop("checked", true);
59
+        }
60
+    }
61
+
62
+    note.content = lines.join("\n");
63
+    note.modified = null;
64
+    note.html = null;
65
+
66
+    NOTES.set(NOTES.fix(note));
67
+
68
+    NOTES.sync();
69
+});
70
+
22 71
 function loadCards(callback) {
23 72
     // Do it twice as a workaround for the stupid sync issue
24 73
     NOTES.sync(function () {
@@ -46,7 +95,10 @@ function loadCards(callback) {
46 95
                     id: note.noteid
47 96
                 });
48 97
             }
49
-            console.log(trayitems);
98
+            $(".notecard .card-content ul li:has(input[type=checkbox])").addClass("parsedown-task-list");
99
+            $(".notecard .card-content ul li:has(input[type=checkbox]:checkbox:not(:checked))").addClass("parsedown-task-list-open");
100
+            $(".notecard .card-content ul li:has(input[type=checkbox]:checkbox:checked)").addClass("parsedown-task-list-close");
101
+            $(".parsedown-task-list input[type=checkbox]").removeAttr("disabled");
50 102
             var noteElements = document.getElementsByClassName("notecard-col");
51 103
             window.shuffleInstance.add(noteElements);
52 104
             window.shuffleInstance.sort({

+ 1
- 1
www/package.json View File

@@ -1,7 +1,7 @@
1 1
 {
2 2
     "name": "com.netsyms.NotePostApp",
3 3
     "displayName": "NotePost",
4
-    "version": "1.0.0",
4
+    "version": "1.1.0",
5 5
     "description": "A cross-platform client app for NotePost.",
6 6
     "author": "Netsyms Technologies",
7 7
     "license": "MPL-2.0",

+ 1
- 1
www/routes.js View File

@@ -109,7 +109,7 @@ var routes = [
109 109
                         },
110 110
                         {
111 111
                             setting: "versions",
112
-                            title: "NotePost app v1.0.0",
112
+                            title: "NotePost app v1.1.0",
113 113
                             text: "Copyright &copy; 2018-2019 Netsyms Technologies.  License: <span style=\"text-decoration: underline;\" onclick=\"openBrowser('https://source.netsyms.com/Apps/NotePostApp?pk_campaign=NotePostApp');\">Mozilla Public License 2.0</span>.",
114 114
                             onclick: ""
115 115
                         },

Loading…
Cancel
Save