Fixing a race condition on images loading in Feed view.

This commit is contained in:
Samuel Clay 2012-06-19 11:20:42 -07:00
parent 6dd33d9c0c
commit cbf96397c1
3 changed files with 16 additions and 26 deletions

View file

@ -1023,20 +1023,9 @@
this.select_story_in_feed();
}
this.flags['story_titles_loaded'] = true;
if (!first_load) {
var stories_count = this.cache['iframe_story_positions_keys'].length;
NEWSBLUR.app.original_tab_view.fetch_story_locations_in_story_frame();
if (this.story_view == 'feed' || this.flags['page_view_showing_feed_view']) {
NEWSBLUR.app.story_list.reset_story_positions();
}
} else {
if (this.story_view == 'page') {
_.delay(_.bind(function() {
NEWSBLUR.app.original_tab_view.prefetch_story_locations_in_story_frame();
}, this), 250);
} else if (this.story_view == 'feed') {
NEWSBLUR.app.story_list.reset_story_positions();
} else if (this.story_view == 'story' && !this.counts['find_next_unread_on_page_of_feed_stories_load']) {
if (first_load) {
if (this.story_view == 'story' &&
!this.counts['find_next_unread_on_page_of_feed_stories_load']) {
this.show_next_story(1);
}
@ -1144,7 +1133,6 @@
}
this.show_story_titles_above_intelligence_level({'animate': false});
this.flags['story_titles_loaded'] = true;
NEWSBLUR.app.story_list.reset_story_positions();
// this.scroll_story_titles_to_show_selected_story_title();
// this.fill_out_story_titles();
}
@ -1224,7 +1212,6 @@
}
// this.scroll_story_titles_to_show_selected_story_title();
// this.fill_out_story_titles();
NEWSBLUR.app.story_list.reset_story_positions();
this.hide_stories_progress_bar();
}
},
@ -1343,7 +1330,6 @@
}
// this.scroll_story_titles_to_show_selected_story_title();
// this.fill_out_story_titles();
NEWSBLUR.app.story_list.reset_story_positions();
this.hide_stories_progress_bar();
if (this.flags['showing_social_feed_in_tryfeed_view']) {

View file

@ -18,6 +18,9 @@ NEWSBLUR.Views.OriginalTabView = Backbone.View.extend({
this.setup_events();
this.collection.bind('change:selected', this.toggle_selected_story, this);
this.collection.bind('reset', this.fetch_story_locations_in_story_frame, this);
this.collection.bind('add', this.fetch_story_locations_in_story_frame, this);
},
setup_events: function() {
@ -215,7 +218,7 @@ NEWSBLUR.Views.OriginalTabView = Backbone.View.extend({
var prefetch_tries_left = 3;
this.cache['prefetch_iteration'] += 1;
NEWSBLUR.log(['Prefetching', !this.flags['iframe_fetching_story_locations'], !this.flags['iframe_story_locations_fetched']]);
NEWSBLUR.log(['Prefetching Original', !this.flags['iframe_fetching_story_locations'], !this.flags['iframe_story_locations_fetched']]);
if (!this.flags['iframe_fetching_story_locations']
&& !this.flags['iframe_story_locations_fetched']) {
// $iframe.unbind('scroll').scroll($.rescope(this.handle_scroll_feed_iframe, this));

View file

@ -186,7 +186,7 @@ NEWSBLUR.Views.StoryListView = Backbone.View.extend({
var self = this;
var stories = NEWSBLUR.assets.stories;
NEWSBLUR.log(['Prefetching', this.flags['feed_view_positions_calculated'], this.flags.feed_view_images_loaded, (_.keys(this.flags.feed_view_images_loaded).length > 0 || this.cache.feed_view_story_positions_keys.length > 0), _.keys(this.flags.feed_view_images_loaded).length,
NEWSBLUR.log(['Prefetching Feed', this.flags['feed_view_positions_calculated'], this.flags.feed_view_images_loaded, (_.keys(this.flags.feed_view_images_loaded).length > 0 || this.cache.feed_view_story_positions_keys.length > 0), _.keys(this.flags.feed_view_images_loaded).length,
_.values(this.flags.feed_view_images_loaded), this.is_feed_loaded_for_location_fetch()]);
if (!NEWSBLUR.assets.stories.size()) return;
@ -199,7 +199,6 @@ NEWSBLUR.Views.StoryListView = Backbone.View.extend({
});
NEWSBLUR.assets.stories.any(_.bind(function(story) {
NEWSBLUR.log(['Pre-fetching', story.get('story_title'), this.flags.feed_view_images_loaded[story.id]]);
this.determine_feed_view_story_position(story);
var $story = story.story_view.$el;
if (!$story || !$story.length || this.flags['feed_view_positions_calculated']) {
@ -275,17 +274,19 @@ NEWSBLUR.Views.StoryListView = Backbone.View.extend({
}
},
reset_story_positions: function() {
reset_story_positions: function(models) {
console.log(["reset_story_positions", models, arguments]);
models = (models && models.length && models) || NEWSBLUR.assets.stories;
this.flags['feed_view_positions_calculated'] = false;
this.flags.feed_view_images_loaded = {};
// this.flags.feed_view_images_loaded = {};
if (this.cache.story_pane_position == null) {
this.cache.story_pane_position = this.$el.offsetParent().offset().top;
}
NEWSBLUR.assets.stories.each(_.bind(function(story) {
var image_count = story.story_view.$('img').length;
models.each(_.bind(function(story) {
var image_count = story.story_view.$('.NB-feed-story-content img').length;
if (!image_count) {
this.flags.feed_view_images_loaded[story.id] = true;
} else {
@ -294,9 +295,9 @@ NEWSBLUR.Views.StoryListView = Backbone.View.extend({
// its position (after its own images are loaded).
this.flags.feed_view_images_loaded[story.id] = false;
(function(story, image_count) {
story.story_view.$('img').load(function() {
story.story_view.$('.NB-feed-story-content img').load(function() {
NEWSBLUR.log(['Loaded image', story.get('story_title'), image_count]);
if (image_count == 1) {
if (image_count <= 1) {
NEWSBLUR.app.story_list.flags.feed_view_images_loaded[story.id] = true;
} else {
image_count--;