summaryrefslogtreecommitdiffstats
path: root/js
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2012-08-31 23:02:51 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2012-09-01 00:31:39 +0200
commitd23e81a85a2c91696ffb752324f8c9911401dbfe (patch)
tree7a5e5ed92f0c0829748af998a61144978ac38ed3 /js
parent62deb561f12ee034435d3ba61353fc2fa8f87d1c (diff)
empty itemcache on view change
Diffstat (limited to 'js')
-rw-r--r--js/items.js37
-rw-r--r--js/main.js3
-rw-r--r--js/menu.js11
3 files changed, 34 insertions, 17 deletions
diff --git a/js/items.js b/js/items.js
index 3d86d97e3..f1e8e1240 100644
--- a/js/items.js
+++ b/js/items.js
@@ -51,6 +51,8 @@ var t = t || function(app, string){ return string; }; // mock translation for lo
}
})
});
+
+ this._itemCache.populate(this._$articleList.children('ul'));
}
/**
@@ -108,6 +110,13 @@ var t = t || function(app, string){ return string; }; // mock translation for lo
};
/**
+ * Empties the item cache
+ */
+ Items.prototype.emptyItemCache = function() {
+ this._itemCache.empty();
+ };
+
+ /**
* Returns the most recent id of a feed from the cache
* @param type the type (MenuNodeType)
* @param id the id
@@ -186,6 +195,14 @@ var t = t || function(app, string){ return string; }; // mock translation for lo
};
/**
+ * Empties the cache
+ */
+ ItemCache.prototype.empty = function() {
+ this._items = {};
+ this._feeds = {};
+ };
+
+ /**
* Returns all the ids of feeds for a type sorted by id ascending
* @param type the type (MenuNodeType)
* @param id the id
@@ -329,7 +346,7 @@ var t = t || function(app, string){ return string; }; // mock translation for lo
var self = this;
// single hover on item should mark it as read too
- $('#feed_items h1.item_title a').click(function(){
+ this._$html.find('#h1.item_title a').click(function(){
var $item = $(this).parent().parent('.feed_item');
var itemId = $item.data('id');
var handler = new News.ItemStatusHandler(itemId);
@@ -337,7 +354,7 @@ var t = t || function(app, string){ return string; }; // mock translation for lo
});
// single hover on item should mark it as read too
- $('#feed_items .body').click(function(){
+ this._$html.find('.body').click(function(){
var $item = $(this).parent('.feed_item');
var itemId = $item.data('id');
var handler = new News.ItemStatusHandler(itemId);
@@ -345,34 +362,28 @@ var t = t || function(app, string){ return string; }; // mock translation for lo
});
// mark or unmark as important
- $('#feed_items li.star').click(function(){
+ this._$html.find('li.star').click(function(){
var $item = $(this).parent().parent().parent('.feed_item');
var itemId = $item.data('id');
self._toggleImportant(itemId);
});
// toggle logic for the keep unread handler
- $('#feed_items .keep_unread').click(function(){
+ this._$html.find('.keep_unread').click(function(){
var $item = $(this).parent().parent().parent('.feed_item');
var itemId = $item.data('id');
var handler = new News.ItemStatusHandler(itemId);
handler.toggleKeepUnread();
});
- $('#feed_items .keep_unread input[type=checkbox]').click(function(){
+
+ this._$html.find('.keep_unread input[type=checkbox]').click(function(){
var $item = $(this).parent().parent().parent().parent('.feed_item');
var itemId = $item.data('id');
var handler = new News.ItemStatusHandler(itemId);
handler.toggleKeepUnread();
});
- // bind the mark all as read button
- $('#mark_all_as_read').unbind();
- $('#mark_all_as_read').click(function(){
- var feedId = News.Feed.activeFeedId;
- News.Feed.setAllItemsRead(feedId);
- });
-
- $("time.timeago").timeago();
+ this._$html.find('time.timeago').timeago();
};
})();
diff --git a/js/main.js b/js/main.js
index a6e4a9a81..740e429cb 100644
--- a/js/main.js
+++ b/js/main.js
@@ -19,7 +19,8 @@ $(document).ready(function(){
// global object array for accessing instances
News.Objects = {};
- News.Objects.Menu = new News.Menu(menuUpdateIntervalMiliseconds);
+ News.Objects.Items = new News.Items('#feed_items');
+ News.Objects.Menu = new News.Menu(menuUpdateIntervalMiliseconds, News.Objects.Items);
News.Objects.Menu.bindOn('#feeds > ul');
/* first run script begins */
diff --git a/js/menu.js b/js/menu.js
index 3cd42a70c..1bf535091 100644
--- a/js/menu.js
+++ b/js/menu.js
@@ -21,7 +21,8 @@ We create a new instance of the menu. Then we need to bind it on an ul which con
all the items:
var updateIntervalMiliseconds = 2000;
- var menu = new News.Menu(updateIntervalMiliseconds);
+ var items = new News.Items('#feed_items');
+ var menu = new News.Menu(updateIntervalMiliseconds, items);
menu.bindOn('#feeds ul');
Updating nodes (you dont have to set all values in data):
@@ -115,8 +116,9 @@ var News = News || {};
/**
* This is the basic menu used to construct and maintain the menu
* @param updateIntervalMiliseconds how often the menu should refresh
+ * @param items the items object
*/
- Menu = function(updateIntervalMiliseconds){
+ Menu = function(updateIntervalMiliseconds, items){
var self = this;
this._updateInterval = updateIntervalMiliseconds;
@@ -124,7 +126,7 @@ var News = News || {};
self._updateUnreadCountAll();
}, self._updateInterval);
- this._items = new News.Items('#feed_items');
+ this._items = items;
this._showAll = $('#view').hasClass('show_all');
this._unreadCount = {
@@ -263,6 +265,9 @@ var News = News || {};
Menu.prototype.setShowAll = function(showAll){
this._showAll = showAll;
this.triggerHideRead();
+ // needed because we have items that are older
+ // but not yet cached. We cache by remembering the newest item id
+ this._items.emptyItemCache();
this.load(this._activeFeedType, this._activeFeedId);
};