HACK: hold back on loading more topics for a bit while we are repositioning the page for Safari

This commit is contained in:
Sam 2013-08-20 11:25:01 +10:00
parent 341a28402d
commit d43bd55e5b
1 changed files with 19 additions and 9 deletions

View File

@ -228,16 +228,22 @@ Discourse.TopicView = Discourse.View.extend(Discourse.Scrolling, {
var info = Discourse.Eyeline.analyze(rows); var info = Discourse.Eyeline.analyze(rows);
if(!info) { return; } if(!info) { return; }
// are we scrolling upwards?
if(info.top === 0 || info.onScreen[0] === 0 || info.bottom === 0) { // We disable scrolling of the topic while performing initial positioning
var $body = $('body'); // This code needs to be refactored, the pipline for positioning posts is wack
var $elem = $(rows[0]); // Be sure to test on safari as well when playing with this
var distToElement = $body.scrollTop() - $elem.position().top; if(!Discourse.TopicView.disableScroll) {
this.get('postStream').prependMore().then(function() { // are we scrolling upwards?
Em.run.next(function () { if(info.top === 0 || info.onScreen[0] === 0 || info.bottom === 0) {
$('html, body').scrollTop($elem.position().top + distToElement); var $body = $('body');
var $elem = $(rows[0]);
var distToElement = $body.scrollTop() - $elem.position().top;
this.get('postStream').prependMore().then(function() {
Em.run.next(function () {
$('html, body').scrollTop($elem.position().top + distToElement);
});
}); });
}); }
} }
// are we scrolling down? // are we scrolling down?
@ -247,6 +253,7 @@ Discourse.TopicView = Discourse.View.extend(Discourse.Scrolling, {
this.get('postStream').appendMore(); this.get('postStream').appendMore();
} }
// update dock // update dock
this.updateDock(Ember.View.views[rows[info.bottom].id]); this.updateDock(Ember.View.views[rows[info.bottom].id]);
@ -352,6 +359,7 @@ Discourse.TopicView.reopenClass({
// Scroll to a given post, if in the DOM. Returns whether it was in the DOM or not. // Scroll to a given post, if in the DOM. Returns whether it was in the DOM or not.
jumpToPost: function(topicId, postNumber, avoidScrollIfPossible) { jumpToPost: function(topicId, postNumber, avoidScrollIfPossible) {
this.disableScroll = true;
Em.run.scheduleOnce('afterRender', function() { Em.run.scheduleOnce('afterRender', function() {
var rows = $('.topic-post.ready'); var rows = $('.topic-post.ready');
@ -428,6 +436,8 @@ Discourse.TopicView.reopenClass({
$contents.removeClass('highlighted'); $contents.removeClass('highlighted');
}); });
} }
setTimeout(function(){Discourse.TopicView.disableScroll = false;}, 500);
} }
}); });
} }