Handling complicated interactions during scrolling, mousemove, and switching panes.

This commit is contained in:
Samuel Clay 2012-06-11 18:23:59 -07:00
parent 3ecf5d0380
commit a1ac24f858
4 changed files with 61 additions and 59 deletions

View file

@ -1019,7 +1019,6 @@
'feed_view_images_loaded': {},
'feed_view_positions_calculated': false,
'scrolling_by_selecting_story_title': false,
'switching_to_feed_view': false,
'page_view_showing_feed_view': false,
'feed_view_showing_story_view': false,
'story_titles_loaded': false,
@ -2395,11 +2394,11 @@
this.story_view = view;
}
// this.flags.scrolling_by_selecting_story_title = true;
// clearInterval(this.locks.scrolling);
// this.locks.scrolling = setTimeout(function() {
// self.flags.scrolling_by_selecting_story_title = false;
// }, 1000);
this.flags.scrolling_by_selecting_story_title = true;
clearInterval(this.locks.scrolling);
this.locks.scrolling = setTimeout(function() {
self.flags.scrolling_by_selecting_story_title = false;
}, 550);
if (view == 'page') {
if (this.flags['iframe_prevented_from_loading']) {
NEWSBLUR.app.original_view.load_feed_iframe();
@ -2414,9 +2413,7 @@
'queue': false
});
} else if (view == 'feed') {
if (this.active_story) {
NEWSBLUR.app.story_list.scroll_to_selected_story(this.active_story.story_view, {immediate: true});
}
NEWSBLUR.app.story_list.scroll_to_selected_story(this.active_story, {immediate: true});
$story_pane.animate({
'left': -1 * $feed_iframe.width()
@ -2426,11 +2423,6 @@
'queue': false
});
this.flags['switching_to_feed_view'] = true;
setTimeout(function() {
self.flags['switching_to_feed_view'] = false;
}, 100);
this.show_stories_preference_in_feed_view();
if (!this.flags['feed_view_positions_calculated']) {
// this.prefetch_story_locations_in_feed_view();

View file

@ -168,35 +168,37 @@ NEWSBLUR.Views.OriginalView = Backbone.View.extend({
var $story = this.find_story_in_feed_iframe(story);
options = options || {};
if (!story) return;
if (!NEWSBLUR.assets.preference('animations') ||
NEWSBLUR.reader.story_view == 'feed' ||
NEWSBLUR.reader.story_view == 'story' ||
NEWSBLUR.reader.flags['page_view_showing_feed_view']) options.immediate = true;
// console.log(["Scroll in Original", story.get('story_title'), options]);
if ($story && $story.length) {
NEWSBLUR.reader.flags['scrolling_by_selecting_story_title'] = true;
clearTimeout(NEWSBLUR.reader.locks.scrolling);
if (options.immediate || NEWSBLUR.reader.story_view != 'page') {
$iframe.scrollTo($story, { duration: 0, axis: 'y', offset: -24 }); // Do this at story_view switch
NEWSBLUR.reader.locks.scrolling = setTimeout(function() {
NEWSBLUR.reader.flags['scrolling_by_selecting_story_title'] = false;
}, 100);
} else if (NEWSBLUR.reader.story_view == 'page') {
$iframe.scrollable().stop();
$iframe.scrollTo($story, {
duration: 380,
axis: 'y',
easing: 'easeInOutQuint',
offset: -24,
queue: false,
onAfter: function() {
NEWSBLUR.reader.locks.scrolling = setTimeout(function() {
NEWSBLUR.reader.flags['scrolling_by_selecting_story_title'] = false;
}, 100);
}
});
if (!options.immediate) {
clearTimeout(NEWSBLUR.reader.locks.scrolling);
NEWSBLUR.reader.flags['scrolling_by_selecting_story_title'] = true;
}
$iframe.scrollable().stop();
$iframe.scrollTo($story, {
duration: options.immediate ? 0 : 380,
axis: 'y',
easing: 'easeInOutQuint',
offset: -24,
queue: false,
onAfter: function() {
if (options.immediate) return;
NEWSBLUR.reader.locks.scrolling = setTimeout(function() {
NEWSBLUR.reader.flags['scrolling_by_selecting_story_title'] = false;
}, 100);
}
});
var parent_scroll = $story.parents('.NB-feed-story-view').scrollTop();
var story_offset = $story.offset().top;
@ -531,11 +533,11 @@ NEWSBLUR.Views.OriginalView = Backbone.View.extend({
var positions = this.cache.iframe_story_positions_keys;
var closest = $.closest(from_top, positions);
var story = this.cache.iframe_story_positions[positions[closest]];
// NEWSBLUR.log(['Scroll iframe', from_top, closest, positions[closest], this.cache.iframe_story_positions[positions[closest]]]);
if (!story) return;
// console.log(['Scroll iframe', from_top, closest, positions[closest], this.cache.iframe_story_positions[positions[closest]]]);
// if (!story.get('selected')) {
story.set('selected', true, {selected_in_original: true, immediate: true});
story.set('selected', true, {selected_in_original: true, scroll: true, immediate: true});
// }
if (!this.flags.iframe_scroll_snap_back_prepared) {
this.iframe_scroll = from_top - NEWSBLUR.reader.cache.mouse_position_y;
@ -553,27 +555,30 @@ NEWSBLUR.Views.OriginalView = Backbone.View.extend({
}
var scroll_top = this.$el.contents().scrollTop();
// console.log(["mousemove", scroll_top, e.pageY]);
// console.log(["mousemove", e, scroll_top, e.pageY]);
NEWSBLUR.reader.cache.mouse_position_y = e.pageY - scroll_top;
NEWSBLUR.reader.$s.$mouse_indicator.css('top', NEWSBLUR.reader.cache.mouse_position_y - 8);
// setTimeout(_.bind(function() {
// this.flags['mousemove_timeout'] = false;
// }, this), 40);
if (!this.flags['mousemove_timeout']
&& !NEWSBLUR.reader.flags.scrolling_by_selecting_story_title) {
var from_top = NEWSBLUR.reader.cache.mouse_position_y + scroll_top;
var positions = this.cache.iframe_story_positions_keys;
var closest = $.closest(from_top, positions);
var story = this.cache.iframe_story_positions[positions[closest]];
// console.log(["mousemove", story, from_top, positions[closest], this.cache.iframe_story_positions]);
// this.flags['mousemove_timeout'] = true;
if (!story) return;
if (!story.get('selected')) {
story.set('selected', true, {selected_in_original: true, immediate: true});
// this.flags['mousemove_timeout'] = false;
}
if (this.flags['mousemove_timeout'] ||
NEWSBLUR.reader.flags['scrolling_by_selecting_story_title']) {
return;
}
var from_top = NEWSBLUR.reader.cache.mouse_position_y + scroll_top;
var positions = this.cache.iframe_story_positions_keys;
var closest = $.closest(from_top, positions);
var story = this.cache.iframe_story_positions[positions[closest]];
// console.log(["mousemove", story, from_top, positions[closest], this.cache.iframe_story_positions]);
// this.flags['mousemove_timeout'] = true;
if (!story) return;
if (!story.get('selected')) {
story.set('selected', true, {selected_in_original: true, mouse: true, immediate: true});
// this.flags['mousemove_timeout'] = false;
}
},

View file

@ -52,9 +52,14 @@ NEWSBLUR.Views.StoryListView = Backbone.View.extend({
scroll_to_selected_story: function(story, options) {
options = options || {};
if (!story || !story.story_view) return;
NEWSBLUR.reader.flags.scrolling_by_selecting_story_title = true;
clearTimeout(NEWSBLUR.reader.locks.scrolling);
// console.log(["Scroll in Feed", story.get('story_title'), options]);
if (!options.immediate) {
clearTimeout(NEWSBLUR.reader.locks.scrolling);
NEWSBLUR.reader.flags.scrolling_by_selecting_story_title = true;
}
this.$el.scrollable().stop();
this.$el.scrollTo(story.story_view.$el, {
duration: options.immediate ? 0 : 340,
@ -63,6 +68,8 @@ NEWSBLUR.Views.StoryListView = Backbone.View.extend({
offset: 0, // scroll_offset,
queue: false,
onAfter: function() {
if (options.immediate) return;
NEWSBLUR.reader.locks.scrolling = setTimeout(function() {
NEWSBLUR.reader.flags.scrolling_by_selecting_story_title = false;
}, 100);
@ -213,7 +220,6 @@ NEWSBLUR.Views.StoryListView = Backbone.View.extend({
// NEWSBLUR.log(['handle_scroll_feed_view', this.story_view, this.flags['switching_to_feed_view'], this.flags['scrolling_by_selecting_story_title']]);
if ((this.story_view == 'feed' ||
(this.story_view == 'page' && this.flags['page_view_showing_feed_view'])) &&
!this.flags['switching_to_feed_view'] &&
!this.flags['scrolling_by_selecting_story_title'] &&
!NEWSBLUR.assets.preference('feed_view_single_story')) {
var from_top = this.cache.mouse_position_y + this.$s.$feed_stories.scrollTop();

View file

@ -299,8 +299,7 @@ NEWSBLUR.Views.StoryView = Backbone.View.extend({
mouseenter: function() {
if (this.model.get('selected')) return;
if (NEWSBLUR.reader.flags['switching_to_feed_view'] ||
NEWSBLUR.reader.flags['scrolling_by_selecting_story_title'] ||
if (NEWSBLUR.reader.flags['scrolling_by_selecting_story_title'] ||
NEWSBLUR.assets.preference('feed_view_single_story')) {
return;
}