From 64beddce8af8c44c98cae54e58f2d08ac745f48f Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Mon, 14 Jan 2019 18:40:42 -0700 Subject: [PATCH] Add color picker, improve refresh behavior --- www/js/NotePostNotes.class.js | 4 +- www/js/Notes.class.js | 3 +- www/js/home.js | 77 ++++++++++++++++++++++++++++++++++- www/pages/home.html | 33 ++++++++++++++- www/routes.js | 33 ++++++++++++++- 5 files changed, 141 insertions(+), 9 deletions(-) diff --git a/www/js/NotePostNotes.class.js b/www/js/NotePostNotes.class.js index 065ced1..fcf95c1 100644 --- a/www/js/NotePostNotes.class.js +++ b/www/js/NotePostNotes.class.js @@ -116,6 +116,8 @@ class NotePostNotes extends Notes { } }); } + + /** * Sync notes with the NotePost server, resolving conflicts in the process. * @@ -123,8 +125,6 @@ class NotePostNotes extends Notes { * @param {function} error * @returns {undefined} */ - - sync(success, error) { super.sync(); var self = this; diff --git a/www/js/Notes.class.js b/www/js/Notes.class.js index 60cf3fa..db206b0 100644 --- a/www/js/Notes.class.js +++ b/www/js/Notes.class.js @@ -112,8 +112,7 @@ class Notes { if (typeof note.html !== 'string') { note.html = marked(note.content); - } // Save - + } return note; } diff --git a/www/js/home.js b/www/js/home.js index e3f50d2..01a8fa2 100644 --- a/www/js/home.js +++ b/www/js/home.js @@ -6,9 +6,43 @@ $(".view-main").on("ptr:refresh", ".ptr-content", function () { - restartApplication(); + loadCards(function () { + app.ptr.done(); + }); }); +function loadCards(callback) { + // Do it twice as a workaround for the stupid sync issue + NOTES.sync(function () { + NOTES.sync(function (notes) { + for (i in window.shuffleInstance.items) { + window.shuffleInstance.remove(window.shuffleInstance.items[i]); + } + $(".notecard-col").remove(); + for (n in notes) { + var note = notes[n]; + $("#notecards-bin").append('
' + + '
' + + '' + + '
' + note.html + '
' + + '
' + + '
'); + } + var noteElements = document.getElementsByClassName("notecard-col"); + window.shuffleInstance.add(noteElements); + if (typeof callback == 'function') { + callback(); + } + }, function () { + restartApplication(); + }); + }, function () { + restartApplication(); + }); +} + function editNote(id) { var note = NOTES.get(id); router.navigate("/editnote", { @@ -32,16 +66,29 @@ function makeList(id) { function deleteNote(id) { app.dialog.confirm('Are you sure?', 'Delete Note', function () { NOTES.del(id, function () { - app.ptr.refresh(); + window.shuffleInstance.remove(document.getElementById("notecard-" + id)); }); }); } +function colorNote(id) { + $("#colorpicker").data("noteid", id); + var colorpicker = app.popup.create({ + el: $("#colorpicker") + }); + colorpicker.open(); +} + $("#app").on("click", ".edit-note-btn", function () { editNote($(this).data("note")); app.popover.close(); }); +$("#app").on("click", ".color-note-btn", function () { + colorNote($(this).data("note")); + app.popover.close(); +}); + $("#app").on("click", ".favorite-note-btn", function () { favoriteNote($(this).data("note")); app.popover.close(); @@ -57,6 +104,23 @@ $("#app").on("click", ".delete-note-btn", function () { app.popover.close(); }); +$("#app").on("click", "#colorpicker .colorpicker-color", function () { + var color = $(this).data("color"); + var noteid = $("#colorpicker").data("noteid"); + var note = NOTES.get(noteid); + app.popup.close(); + note.color = color; + // Set them to null, they'll be fixed in fix() + note.modified = null; + note.textcolor = null; + note2 = NOTES.fix(note); + NOTES.set(note2); + $("#notecard-" + noteid).data("bg", note2.color); + $("#notecard-" + noteid).data("fg", note2.textcolor); + $("#notecard-" + noteid).css("background-color", "#" + note2.color); + $("#notecard-" + noteid).css("color", "#" + note2.textcolor); +}); + function openNoteActionMenu(notecard) { var noteid = notecard.data("id"); if (window.innerWidth < 768) { @@ -70,6 +134,14 @@ function openNoteActionMenu(notecard) { editNote(noteid); } }, + { + text: "Color", + icon: '', + onClick: function () { + colorNote(noteid); + } + }, + // { // text: "Favorite", // icon: '', @@ -104,6 +176,7 @@ function openNoteActionMenu(notecard) { '
' + '
+ {{#if offline}}
@@ -39,7 +41,7 @@
{{/if}} {{#each notecards}} -
+
+ +
\ No newline at end of file diff --git a/www/routes.js b/www/routes.js index 72e6906..671cd43 100644 --- a/www/routes.js +++ b/www/routes.js @@ -16,7 +16,38 @@ var routes = [ }; var context = { showrefreshbtn: (platform_type != "cordova"), - offline: OFFLINE + offline: OFFLINE, + colors: [ + // Pastel colors + "EF9A9A", // red + "FFCC80", // orange + "FFF59D", // yellow + "E6EE9C", // lime + "A5D6A7", // green + "80CBC4", // teal + "81D4FA", // light blue + "90CAF9", // blue + "B39DDB", // purple + "F48FB1", // pink + // Bright colors + "F44336", // red + "FF9800", // orange + "FFEB3B", // yellow + "8BC34A", // light green + "4CAF50", // green + "009688", // teal + "03A9F4", // light blue + "2196F3", // blue + "673AB7", // purple + "E91E63", // pink + // Other colors + "FFFFFF", // white + "E0E0E0", // pastel gray + "9E9E9E", // gray + "BCAAA4", // pastel brown + "795548", // brown + "000000" // black + ] }; NOTES.sync(function (notes) { context["notecards"] = notes;