From f4fe27e26c5fafc12a4c3501cf49f9514f0e3c96 Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Wed, 12 Oct 2016 13:08:53 +0800 Subject: [PATCH 1/3] Update to make history refresh have better UX and keep the beginning and end of the pagination visible --- public/js/cover.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/public/js/cover.js b/public/js/cover.js index 25434ed..df2173b 100644 --- a/public/js/cover.js +++ b/public/js/cover.js @@ -21,7 +21,9 @@ var options = { ', page: 18, plugins: [ - ListPagination({}) + ListPagination({ + outerWindow: 1 + }) ] }; var historyList = new List('history', options); @@ -305,6 +307,8 @@ $(".ui-refresh-history").click(function () { var lastKeyword = $('.search').val(); $('.search').val(''); historyList.search(); + $('#history-list').slideUp('fast'); + $('.pagination').slideUp('fast'); resetCheckAuth(); historyList.clear(); @@ -315,6 +319,8 @@ $(".ui-refresh-history").click(function () { historyList.search(lastKeyword); $('.search').val(lastKeyword); checkHistoryList(); + $('#history-list').slideDown('fast'); + $('.pagination').slideDown('fast'); }); }); From f5d471106c35f5ebb3aa28ccd73bd32dac6d79d9 Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Wed, 12 Oct 2016 13:14:46 +0800 Subject: [PATCH 2/3] Fix history list not parse and bind events properly on change pagination --- public/js/cover.js | 174 +++++++++++++++++++++++++-------------------- 1 file changed, 95 insertions(+), 79 deletions(-) diff --git a/public/js/cover.js b/public/js/cover.js index df2173b..3f9d787 100644 --- a/public/js/cover.js +++ b/public/js/cover.js @@ -112,94 +112,110 @@ function parseHistoryCallback(list, notehistory) { } } }); + // parse filter tags var filtertags = []; - $(".item").each(function (key, value) { - var a = $(this).closest("a"); - var pin = $(this).find(".ui-history-pin"); - var id = a.siblings("span").html(); - var tagsEl = $(this).find(".tags"); - var item = historyList.get('id', id); - if (item.length > 0 && item[0]) { - var values = item[0].values(); - //parse pinned - if (values.pinned) { - pin.addClass('active'); - } else { - pin.removeClass('active'); - } - //parse link to element a - a.attr('href', serverurl + '/' + values.id); - //parse tags - if (values.tags) { - var tags = values.tags; - if (tags.length > 0) { - var labels = []; - for (var j = 0; j < tags.length; j++) { - //push info filtertags if not found - var found = false; - if (filtertags.indexOf(tags[j]) != -1) - found = true; - if (!found) - filtertags.push(tags[j]); - //push into the item label - labels.push("" + tags[j] + ""); - } - tagsEl.html(labels.join(' ')); - } + for (var i = 0, l = list.items.length; i < l; i++) { + var tags = list.items[i]._values.tags; + if (tags && tags.length > 0) { + for (var j = 0; j < tags.length; j++) { + //push info filtertags if not found + var found = false; + if (filtertags.indexOf(tags[j]) != -1) + found = true; + if (!found) + filtertags.push(tags[j]); } } - }); - $(".ui-history-close").click(function (e) { - e.preventDefault(); - var id = $(this).closest("a").siblings("span").html(); - var value = list.get('id', id)[0].values(); - $('.ui-delete-modal-msg').text('Do you really want to delete below history?'); - $('.ui-delete-modal-item').html(' ' + value.text + '
' + value.time); - clearHistory = false; - deleteId = id; - }); - $(".ui-history-pin").click(function (e) { - e.preventDefault(); - var $this = $(this); - var id = $this.closest("a").siblings("span").html(); - var item = list.get('id', id)[0]; - var values = item.values(); - var pinned = values.pinned; - if (!values.pinned) { - pinned = true; - item._values.pinned = true; - } else { - pinned = false; - item._values.pinned = false; - } - checkIfAuth(function () { - postHistoryToServer(id, { - pinned: pinned - }, function (err, result) { - if (!err) { - if (pinned) - $this.addClass('active'); - else - $this.removeClass('active'); - } - }); - }, function () { - getHistory(function (notehistory) { - for(var i = 0; i < notehistory.length; i++) { - if (notehistory[i].id == id) { - notehistory[i].pinned = pinned; - break; - } + } + buildTagsFilter(filtertags); +} + +// update items whenever list updated +historyList.on('updated', function (e) { + for (var i = 0, l = e.items.length; i < l; i++) { + var item = e.items[i]; + if (item.visible()) { + var itemEl = $(item.elm); + var values = item._values; + var a = itemEl.find("a"); + var pin = itemEl.find(".ui-history-pin"); + var tagsEl = itemEl.find(".tags"); + //parse link to element a + a.attr('href', serverurl + '/' + values.id); + //parse pinned + if (values.pinned) { + pin.addClass('active'); + } else { + pin.removeClass('active'); + } + //parse tags + var tags = values.tags; + if (tags && tags.length > 0 && tagsEl.children().length <= 0) { + var labels = []; + for (var j = 0; j < tags.length; j++) { + //push into the item label + labels.push("" + tags[j] + ""); } - saveHistory(notehistory); + tagsEl.html(labels.join(' ')); + } + } + } + $(".ui-history-close").off('click'); + $(".ui-history-close").on('click', historyCloseClick); + $(".ui-history-pin").off('click'); + $(".ui-history-pin").on('click', historyPinClick); +}); + +function historyCloseClick(e) { + e.preventDefault(); + var id = $(this).closest("a").siblings("span").html(); + var value = historyList.get('id', id)[0]._values; + $('.ui-delete-modal-msg').text('Do you really want to delete below history?'); + $('.ui-delete-modal-item').html(' ' + value.text + '
' + value.time); + clearHistory = false; + deleteId = id; +} + +function historyPinClick(e) { + e.preventDefault(); + var $this = $(this); + var id = $this.closest("a").siblings("span").html(); + var item = historyList.get('id', id)[0]; + var values = item._values; + var pinned = values.pinned; + if (!values.pinned) { + pinned = true; + item._values.pinned = true; + } else { + pinned = false; + item._values.pinned = false; + } + checkIfAuth(function () { + postHistoryToServer(id, { + pinned: pinned + }, function (err, result) { + if (!err) { if (pinned) $this.addClass('active'); else $this.removeClass('active'); - }); - }) + } + }); + }, function () { + getHistory(function (notehistory) { + for(var i = 0; i < notehistory.length; i++) { + if (notehistory[i].id == id) { + notehistory[i].pinned = pinned; + break; + } + } + saveHistory(notehistory); + if (pinned) + $this.addClass('active'); + else + $this.removeClass('active'); + }); }); - buildTagsFilter(filtertags); } //auto update item fromNow every minutes From 07673f07262a3e742b06d886b23a2969a6abe58a Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Wed, 12 Oct 2016 13:14:59 +0800 Subject: [PATCH 3/3] Fix note extract tags might get encoded HTML entity --- lib/models/note.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/models/note.js b/lib/models/note.js index 7fdc564..05ed04c 100644 --- a/lib/models/note.js +++ b/lib/models/note.js @@ -285,7 +285,7 @@ module.exports = function (sequelize, DataTypes) { if (/^tags/gmi.test($(value).text())) { var codes = $(value).find("code"); for (var i = 0; i < codes.length; i++) { - var text = $(codes[i]).html().trim(); + var text = S($(codes[i]).text().trim()).stripTags().s; if (text) rawtags.push(text); } }