summaryrefslogtreecommitdiff
path: root/public/js/cover.js
diff options
context:
space:
mode:
authorWu Cheng-Han2015-10-22 17:09:55 +0800
committerWu Cheng-Han2015-10-22 17:09:55 +0800
commit2cfcae6db2ae306a14a23317b40ad04924ff7ec6 (patch)
tree7e64d91b8af28a3bcc0f78504e490c741ed28b2a /public/js/cover.js
parent5ed395122d3862b1e5ed84784b4205d30a407849 (diff)
Support pinning note in history
Diffstat (limited to '')
-rw-r--r--public/js/cover.js61
1 files changed, 57 insertions, 4 deletions
diff --git a/public/js/cover.js b/public/js/cover.js
index 567d6422..f2f3ae91 100644
--- a/public/js/cover.js
+++ b/public/js/cover.js
@@ -1,9 +1,10 @@
var options = {
- valueNames: ['id', 'text', 'timestamp', 'fromNow', 'time', 'tags'],
+ valueNames: ['id', 'text', 'timestamp', 'fromNow', 'time', 'tags', 'pinned'],
item: '<li class="col-xs-12 col-sm-6 col-md-6 col-lg-4">\
<span class="id" style="display:none;"></span>\
<a href="#">\
<div class="item">\
+ <div class="ui-history-pin fa fa-thumb-tack fa-fw"></div>\
<div class="ui-history-close fa fa-close fa-fw" data-toggle="modal" data-target=".delete-modal"></div>\
<div class="content">\
<h4 class="text"></h4>\
@@ -83,17 +84,41 @@ function checkHistoryList() {
function parseHistoryCallback(list, notehistory) {
checkHistoryList();
- list.sort('timestamp', {
- order: "desc"
- });
+ //sort by pinned then timestamp
+ list.sort('', {
+ sortFunction: function (a, b) {
+ var notea = a.values();
+ var noteb = b.values();
+ if (notea.pinned && !noteb.pinned) {
+ return -1;
+ } else if (!notea.pinned && noteb.pinned) {
+ return 1;
+ } else {
+ if (notea.timestamp > noteb.timestamp) {
+ return -1;
+ } else if (notea.timestamp < noteb.timestamp) {
+ return 1;
+ } else {
+ return 0;
+ }
+ }
+ }
+ });
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', '/' + values.id);
//parse tags
@@ -125,6 +150,34 @@ function parseHistoryCallback(list, notehistory) {
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;
+ }
+ 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);
}