diff --git a/media/js/newsblur/reader/reader.js b/media/js/newsblur/reader/reader.js index f13677027..1c9ee4f34 100644 --- a/media/js/newsblur/reader/reader.js +++ b/media/js/newsblur/reader/reader.js @@ -2276,6 +2276,9 @@ } if (feed) { + if (NEWSBLUR.app.story_unread_counter) { + NEWSBLUR.app.story_unread_counter.destroy(); + } NEWSBLUR.app.story_unread_counter = new NEWSBLUR.Views.UnreadCount({ model: feed }).render(); @@ -2287,6 +2290,9 @@ } else { collection = folder.folder_view.collection; } + if (NEWSBLUR.app.story_unread_counter) { + NEWSBLUR.app.story_unread_counter.destroy(); + } NEWSBLUR.app.story_unread_counter = new NEWSBLUR.Views.UnreadCount({ collection: collection }).render(); @@ -4945,6 +4951,14 @@ self.open_feed_intelligence_modal(1, feed_id, false); } }); + $.targetIs(e, { tagSelector: '.NB-menu-manage-story-train' }, function($t, $p){ + e.preventDefault(); + if (!$t.hasClass('NB-disabled')) { + var feed_id = $t.parents('.NB-menu-manage').data('feed_id'); + var story_id = $t.parents('.NB-menu-manage').data('story_id'); + self.open_story_trainer(story_id, feed_id); + } + }); $.targetIs(e, { tagSelector: '.NB-menu-manage-feed-recommend' }, function($t, $p){ e.preventDefault(); var feed_id = $t.parents('.NB-menu-manage').data('feed_id'); diff --git a/media/js/newsblur/views/feed_title_view.js b/media/js/newsblur/views/feed_title_view.js index 9dae08034..a71f30818 100644 --- a/media/js/newsblur/views/feed_title_view.js +++ b/media/js/newsblur/views/feed_title_view.js @@ -171,6 +171,9 @@ NEWSBLUR.Views.FeedTitleView = Backbone.View.extend({ }, render_counts: function() { + if (this.counts_view) { + this.counts_view.destroy(); + } this.counts_view = new NEWSBLUR.Views.UnreadCount({model: this.model}).render(); this.$('.feed_counts').html(this.counts_view.el); if (this.options.type == 'story') { diff --git a/media/js/newsblur/views/folder_view.js b/media/js/newsblur/views/folder_view.js index 4be9a55fc..615c14831 100644 --- a/media/js/newsblur/views/folder_view.js +++ b/media/js/newsblur/views/folder_view.js @@ -217,6 +217,9 @@ NEWSBLUR.Views.Folder = Backbone.View.extend({ }); } + if (this.folder_count) { + this.folder_count.destroy(); + } this.folder_count = new NEWSBLUR.Views.UnreadCount({ collection: this.collection }).render(); diff --git a/media/js/newsblur/views/sidebar.js b/media/js/newsblur/views/sidebar.js index 771580592..fc04a9d53 100644 --- a/media/js/newsblur/views/sidebar.js +++ b/media/js/newsblur/views/sidebar.js @@ -60,9 +60,13 @@ NEWSBLUR.Views.Sidebar = Backbone.View.extend({ show_counts: function(options) { var $header = NEWSBLUR.reader.$s.$river_blurblogs_header; - var $counts = new NEWSBLUR.Views.UnreadCount({ + if (this.unread_count) { + this.unread_count.destroy(); + } + this.unread_count = new NEWSBLUR.Views.UnreadCount({ collection: NEWSBLUR.assets.social_feeds - }).render().$el; + }).render(); + var $counts = this.unread_count.$el; if (this.options.feedbar) { this.$('.NB-story-title-indicator-count').html($counts.clone()); diff --git a/media/js/newsblur/views/story_comments_view.js b/media/js/newsblur/views/story_comments_view.js index 2f1ede47a..3dddac195 100644 --- a/media/js/newsblur/views/story_comments_view.js +++ b/media/js/newsblur/views/story_comments_view.js @@ -24,6 +24,10 @@ NEWSBLUR.Views.StoryCommentsView = Backbone.View.extend({ return this; }, + destroy: function() { + this.remove(); + }, + render_teaser: function() { if (!this.model.get('share_count')) return; diff --git a/media/js/newsblur/views/story_detail_view.js b/media/js/newsblur/views/story_detail_view.js index a1d283e67..1e22a65ff 100644 --- a/media/js/newsblur/views/story_detail_view.js +++ b/media/js/newsblur/views/story_detail_view.js @@ -252,7 +252,8 @@ NEWSBLUR.Views.StoryDetailView = Backbone.View.extend({ var $original_comments = this.$('.NB-feed-story-comments-container,.NB-feed-story-comments'); var $original_shares = this.$('.NB-feed-story-shares-container,.NB-feed-story-shares'); if (this.model.get("comment_count") || this.model.get("share_count")) { - var $comments = new NEWSBLUR.Views.StoryCommentsView({model: this.model}).render().el; + this.comments_view = new NEWSBLUR.Views.StoryCommentsView({model: this.model}).render(); + var $comments = this.comments_view.el; $original_comments.replaceWith($comments); var $shares = $('.NB-story-comments-shares-teaser-wrapper', $comments); $original_shares.replaceWith($shares); @@ -263,9 +264,13 @@ NEWSBLUR.Views.StoryDetailView = Backbone.View.extend({ }, destroy: function() { + // console.log(["destroy story detail", this.model.get('story_title')]); clearTimeout(this.truncate_delay_function); this.images_to_load = null; this.model.unbind(null, null, this); + if (this.collection) this.collection.unbind(null, null, this); + // this.sideoptions_view.destroy(); + if (this.comments_view) this.comments_view.destroy(); delete this.model.inline_story_detail_view; this.remove(); }, diff --git a/media/js/newsblur/views/story_title_view.js b/media/js/newsblur/views/story_title_view.js index 7cd2ebc9b..e681879c2 100644 --- a/media/js/newsblur/views/story_title_view.js +++ b/media/js/newsblur/views/story_title_view.js @@ -88,6 +88,19 @@ NEWSBLUR.Views.StoryTitleView = Backbone.View.extend({ } }, + destroy: function() { + // console.log(["destroy story title", this.model.get('story_title')]); + if (this.text_view) { + this.text_view.destroy(); + } + if (this.story_detail) { + this.story_detail.destroy(); + } + this.model.unbind(null, null, this); + this.collection.unbind(null, null, this); + this.remove(); + }, + destroy_inline_story_detail: function() { if (this.story_detail) { this.story_detail.destroy(); diff --git a/media/js/newsblur/views/story_titles_view.js b/media/js/newsblur/views/story_titles_view.js index 7e43fce34..6e4f8967d 100644 --- a/media/js/newsblur/views/story_titles_view.js +++ b/media/js/newsblur/views/story_titles_view.js @@ -16,6 +16,7 @@ NEWSBLUR.Views.StoryTitlesView = Backbone.View.extend({ this.collection.bind('no_more_stories', this.check_premium_river, this); this.collection.bind('no_more_stories', this.check_premium_search, this); NEWSBLUR.reader.$s.$story_titles.scroll(this.scroll); + this.stories = []; }, // ========== @@ -23,13 +24,18 @@ NEWSBLUR.Views.StoryTitlesView = Backbone.View.extend({ // ========== render: function() { + this.clear(); NEWSBLUR.reader.$s.$story_titles.scrollTop(0); var collection = this.collection; - var $stories = this.collection.map(function(story) { + var stories = this.collection.map(function(story) { return new NEWSBLUR.Views.StoryTitleView({ model: story, collection: collection - }).render().el; + }).render(); + }); + this.stories = stories; + var $stories = _.map(stories, function(story) { + return story.el; }); this.$el.html($stories); this.end_loading(); @@ -39,19 +45,27 @@ NEWSBLUR.Views.StoryTitlesView = Backbone.View.extend({ add: function(options) { var collection = this.collection; if (options.added) { - var $stories = _.compact(_.map(this.collection.models.slice(-1 * options.added), function(story) { + var stories = _.compact(_.map(this.collection.models.slice(-1 * options.added), function(story) { if (story.story_title_view) return; return new NEWSBLUR.Views.StoryTitleView({ model: story, collection: collection - }).render().el; + }).render(); })); + this.stories = this.stories.concat(stories); + var $stories = _.map(stories, function(story) { + return story.el; + }); this.$el.append($stories); } this.end_loading(); this.fill_out(); }, - + + clear: function() { + _.invoke(this.stories, 'destroy'); + }, + append_river_premium_only_notification: function() { var $notice = $.make('div', { className: 'NB-feed-story-premium-only' }, [ $.make('div', { className: 'NB-feed-story-premium-only-text'}, [ diff --git a/media/js/newsblur/views/unread_count_view.js b/media/js/newsblur/views/unread_count_view.js index 3ba19dc18..f4403a480 100644 --- a/media/js/newsblur/views/unread_count_view.js +++ b/media/js/newsblur/views/unread_count_view.js @@ -48,6 +48,15 @@ NEWSBLUR.Views.UnreadCount = Backbone.View.extend({ return this; }, + destroy: function() { + if (this.model) { + this.model.unbind(null, null, this); + } else if (this.collection) { + this.collection.unbind(null, null, this); + } + this.remove(); + }, + template: _.template('\