Skip to content

Commit

Permalink
Task #27 Adding 'no bookmarks' message.
Browse files Browse the repository at this point in the history
  • Loading branch information
jesgs authored and ardathksheyna committed Jul 23, 2017
1 parent 00e22b9 commit 4c5d082
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions assets/js/bookmark.js
@@ -1,5 +1,7 @@
(function ($) {

/**
* @todo Add l10n/i18n support
*/
$(function() {
var $bookmark = $('#bookmark-comic'),
$bookmarkComicHistory = $('#bookmark-comic-history');
Expand Down Expand Up @@ -93,13 +95,7 @@
var self = this,
revBookmarkHistory = JSON.parse(self.storage.getItem(self.BOOKMARK_HISTORY));

if (revBookmarkHistory.length == 0) {
// No bookmarks available
return;
}

var bookmarkHistory = revBookmarkHistory.reverse(),
$historyModal = $('<div id="bookmark-history-modal"><div id="bookmark-history-content"></div><p>[<a href="#" id="bookmark-history-close">close</a>]</p></div>')
var $historyModal = $('<div id="bookmark-history-modal"><div id="bookmark-history-content"></div><p>[<a href="#" id="bookmark-history-close">close</a>]</p></div>')
.css({
'width': '300px',
'z-index' : 9999,
Expand All @@ -111,34 +107,39 @@
'margin-left' : '-150px'
});

$historyModal.find('#bookmark-history-content').html(function(){
var htmlString = "<table>";
$historyModal.find('#bookmark-history-content').html(function(){
if (revBookmarkHistory.length == 0) {
return '<p>No bookmark history available.</p>';
}

var htmlString = "<table>",
bookmarkHistory = revBookmarkHistory.reverse();

htmlString = "<thead><tr><td>Title</td><td>Date</td></tr></thead>";
htmlString = "<thead><tr><td>Title</td><td>Date</td></tr></thead>";

for (var i = 0; i < bookmarkHistory.length; i++) {
var columns = [],
bookmark = JSON.parse(bookmarkHistory[i]),
d = new Date(bookmark.date),
date = d.getMonth() + '/' + d.getDate() + '/' + d.getFullYear(),
link = "<a href=\"" + bookmark.url + "\">" + bookmark.title + "</a>";
for (var i = 0; i < bookmarkHistory.length; i++) {
var columns = [],
bookmark = JSON.parse(bookmarkHistory[i]),
d = new Date(bookmark.date),
date = d.getMonth() + '/' + d.getDate() + '/' + d.getFullYear(),
link = "<a href=\"" + bookmark.url + "\">" + bookmark.title + "</a>";

columns.push(link, date);
columns.push(link, date);

htmlString += "<tr><td>" + columns.join('</td><td>') + "</td></tr>"
}
htmlString += "<tr><td>" + columns.join('</td><td>') + "</td></tr>"
}

return htmlString + "</table>";
});
return htmlString + "</table>";
});

// append
self.$bookmarkNav.append($historyModal)
// append
self.$bookmarkNav.append($historyModal)

// add event for closing modal
$('#bookmark-history-close').on('click', function(e){
e.preventDefault();
$historyModal.remove();
});
// add event for closing modal
$('#bookmark-history-close').on('click', function(e){
e.preventDefault();
$historyModal.remove();
});
}
};
}(jQuery));

0 comments on commit 4c5d082

Please sign in to comment.