diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2012-09-05 18:10:05 +0200 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2012-09-05 18:11:29 +0200 |
commit | 86abd7b40d3370f98ba401811eaa9f1904947cbb (patch) | |
tree | 6acfe240d26a44e3b2efc4cd2a34ad72263b785e /js/items.js | |
parent | 747077e85e11c61b31823117f58567cbfd82841e (diff) |
cleanup, moving feeds now sets the unread count correctly
Diffstat (limited to 'js/items.js')
-rw-r--r-- | js/items.js | 164 |
1 files changed, 68 insertions, 96 deletions
diff --git a/js/items.js b/js/items.js index 27b6d754d..b84f93f67 100644 --- a/js/items.js +++ b/js/items.js @@ -29,8 +29,8 @@ var News = News || {}; var self = this; this._$articleList = $(cssSelector); this._$articleList.scrollTop(0); - this._itemCache = new ItemCache(); this._$articleList.children('ul').children('.feed_item:eq(0)').addClass('viewed'); + this._itemCache = new ItemCache(); this._setScrollBottom(); $(window).resize(function(){ @@ -38,7 +38,6 @@ var News = News || {}; }); // mark items whose title was hid under the top edge as read - // when the bottom is reached, mark all items as read this._scrollTimeoutMiliSecs = 100; this._markReadTimeoutMiliSecs = 1000; this._isScrolling = false; @@ -59,7 +58,6 @@ var News = News || {}; }, self._markReadTimeoutMiliSecs); } }); - // mark item with current class self._markCurrentlyViewed(); } }); @@ -74,11 +72,8 @@ var News = News || {}; Items.prototype._markItemAsReadTimeout = function(item) { var itemId = parseInt($(item).data('id')); var itemOffset = $(item).position().top; - var boxHeight = this._$articleList.height(); - var scrollHeight = this._$articleList.prop('scrollHeight'); - var scrolled = this._$articleList.scrollTop() + boxHeight; var item = this._itemCache.getItem(itemId); - if(itemOffset < 0 || scrolled >= scrollHeight){ + if(itemOffset < 0){ if(!item.isLocked()){ // lock item to prevent massive request when scrolling item.setLocked(true); @@ -391,7 +386,9 @@ var News = News || {}; item.setViewed(true); } if(News.Objects.Menu.isShowAll() || !item.isRead()){ - $html.append(item.getHtml()); + var $itemHtml = item.getHtml(); + $itemHtml.removeClass('keep_unread'); + $html.append($itemHtml); } } return $html; @@ -407,7 +404,6 @@ var News = News || {}; var Item = function(html){ this._starred = false; this._$html = $(html); - this._bindItemEventListeners(); this._id = parseInt(this._$html.data('id')); this._feedId = parseInt(this._$html.data('feedid')); this._read = this._$html.hasClass('read'); @@ -416,20 +412,10 @@ var News = News || {}; var $stamp = this._$html.find('.timestamp'); this._timestamp = parseInt($stamp.html()); $stamp.remove(); + this._bindItemEventListeners(); } /** - * Returns the html code for the element - * @return the html for the item - */ - Item.prototype.render = function() { - // remove kept unread - this._$html.removeClass('keep_unread'); - return this._$html[0]; - }; - - /** - * Returns the id of an item * @return the id of the item */ Item.prototype.getId = function() { @@ -438,7 +424,6 @@ var News = News || {}; /** - * Returns the feedid of an item * @return the feeid of the item */ Item.prototype.getFeedId = function() { @@ -446,7 +431,6 @@ var News = News || {}; }; /** - * Returns the html of an item * @return the jquery html of the item */ Item.prototype.getHtml = function() { @@ -461,15 +445,13 @@ var News = News || {}; }; /** - * Returns true if an item is important * @return true if starred, otherwise false */ Item.prototype.isImportant = function() { return this._important; }; - /** - * Returns true if an item is starred + /** * @return true if starred, otherwise false */ Item.prototype.isRead = function() { @@ -477,7 +459,6 @@ var News = News || {}; }; /** - * Locks the class for mark read request * @param locked true will lock, false unlock */ Item.prototype.setLocked = function(locked) { @@ -485,8 +466,7 @@ var News = News || {}; }; /** - * Adds the viewed class to the item - * @param viewed true will add the class, false remove + * @param viewed true will add the viewed class, false remove */ Item.prototype.setViewed = function(viewed) { if(viewed){ @@ -497,7 +477,6 @@ var News = News || {}; }; /** - * Returns true if locked, otherwise false * @return true if locked, otherwise false */ Item.prototype.isLocked = function() { @@ -512,68 +491,6 @@ var News = News || {}; }; /** - * Binds listeners on the feed item - */ - Item.prototype._bindItemEventListeners = function() { - var self = this; - - // single hover on item should mark it as read too - this._$html.find('.item_title a').click(function(){ - var $item = $(this).parent().parent('.feed_item'); - var itemId = $item.data('id'); - self.setRead(true); - }); - - // single hover on item should mark it as read too - this._$html.find('.body').click(function(){ - var $item = $(this).parent('.feed_item'); - var itemId = $item.data('id'); - self.setRead(true); - }); - - // mark or unmark as important - 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 - this._$html.find('.keep_unread').click(function(){ - var $item = $(this).parent().parent().parent('.feed_item'); - var itemId = $item.data('id'); - self._toggleKeepUnread(); - }); - - - - this._$html.find('time.timeago').timeago(); - }; - - /** - * Toggles the keep unread state - */ - Item.prototype._toggleKeepUnread = function() { - var checkBox = this._$html.find('.keep_unread input[type=checkbox]'); - if(this._isKeptUnread()){ - this._$html.removeClass('keep_unread'); - checkBox.prop("checked", false); - } else { - this.setRead(false); - checkBox.prop("checked", true); - this._$html.addClass('keep_unread'); - } - }; - - /** - * @return true if kept unread - */ - Item.prototype._isKeptUnread = function() { - return this._$html.hasClass('keep_unread'); - }; - - - /** * Marks the item as read only locally without telling the server */ Item.prototype.setReadLocally = function() { @@ -589,12 +506,11 @@ var News = News || {}; var status; var self = this; - // if we already have the status, do nothing if(read === this._read){ this.setLocked(false); return; } - // check if the keep unread flag was set + if(read && this._isKeptUnread()){ this.setLocked(false); return; @@ -625,7 +541,6 @@ var News = News || {}; News.Objects.Menu.incrementUnreadCount(News.MenuNodeType.Feed, self._feedId); } } else { - // roll back on error if(read){ self._$html.removeClass('read'); } else { @@ -637,6 +552,65 @@ var News = News || {}; }); }; + /** + * Binds listeners on the feed item + */ + Item.prototype._bindItemEventListeners = function() { + var self = this; + + // single hover on item should mark it as read too + this._$html.find('.item_title a').click(function(){ + var $item = $(this).parent().parent('.feed_item'); + var itemId = $item.data('id'); + self.setRead(true); + }); + + // single hover on item should mark it as read too + this._$html.find('.body').click(function(){ + var $item = $(this).parent('.feed_item'); + var itemId = $item.data('id'); + self.setRead(true); + }); + + // mark or unmark as important + 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 + this._$html.find('.keep_unread').click(function(){ + var $item = $(this).parent().parent().parent('.feed_item'); + var itemId = $item.data('id'); + self._toggleKeepUnread(); + }); + + this._$html.find('time.timeago').timeago(); + }; + + /** + * Toggles the keep unread state + */ + Item.prototype._toggleKeepUnread = function() { + var checkBox = this._$html.find('.keep_unread input[type=checkbox]'); + if(this._isKeptUnread()){ + this._$html.removeClass('keep_unread'); + checkBox.prop("checked", false); + } else { + this.setRead(false); + checkBox.prop("checked", true); + this._$html.addClass('keep_unread'); + } + }; + + /** + * @return true if kept unread + */ + Item.prototype._isKeptUnread = function() { + return this._$html.hasClass('keep_unread'); + }; + /** * Toggles the important state @@ -682,6 +656,4 @@ var News = News || {}; }); }; - - })(); |