mirror of
https://github.com/discourse/discourse.git
synced 2025-06-05 23:44:48 +08:00
FIX: Progress wasn't docking properly
This commit is contained in:
@ -64,6 +64,15 @@ Discourse.PostStream = Em.Object.extend({
|
|||||||
|
|
||||||
firstPostNotLoaded: Em.computed.not('firstPostLoaded'),
|
firstPostNotLoaded: Em.computed.not('firstPostLoaded'),
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the id of the last post in the set
|
||||||
|
|
||||||
|
@property lastPostId
|
||||||
|
**/
|
||||||
|
lastPostId: function() {
|
||||||
|
return _.last(this.get('stream'));
|
||||||
|
}.property('stream.@each'),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Have we loaded the last post in the stream?
|
Have we loaded the last post in the stream?
|
||||||
|
|
||||||
@ -71,8 +80,8 @@ Discourse.PostStream = Em.Object.extend({
|
|||||||
**/
|
**/
|
||||||
lastPostLoaded: function() {
|
lastPostLoaded: function() {
|
||||||
if (!this.get('hasLoadedData')) { return false; }
|
if (!this.get('hasLoadedData')) { return false; }
|
||||||
return !!this.get('posts').findProperty('id', _.last(this.get('stream')));
|
return !!this.get('posts').findProperty('id', this.get('lastPostId'));
|
||||||
}.property('hasLoadedData', 'posts.[]', 'stream.@each'),
|
}.property('hasLoadedData', 'posts.[]', 'lastPostId'),
|
||||||
|
|
||||||
lastPostNotLoaded: Em.computed.not('lastPostLoaded'),
|
lastPostNotLoaded: Em.computed.not('lastPostLoaded'),
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<section class="topic-area" id='topic' data-topic-id='{{unbound id}}'>
|
<section class="topic-area" id='topic' data-topic-id='{{unbound id}}'>
|
||||||
<div class='posts-wrapper'>
|
<div class='posts-wrapper'>
|
||||||
<div id='topic-progress-wrapper'>
|
<div id='topic-progress-wrapper' {{bindAttr class="dockedCounter:docked"}}>
|
||||||
<nav id='topic-progress' title="{{i18n topic.progress.title}}" {{bindAttr class="hideProgress:hidden"}}>
|
<nav id='topic-progress' title="{{i18n topic.progress.title}}" {{bindAttr class="hideProgress:hidden"}}>
|
||||||
<button id='jump-top' title="{{i18n topic.progress.jump_top}}" {{bindAttr disabled="jumpTopDisabled"}} {{action jumpTop}}><i class="icon-circle-arrow-up"></i></button>
|
<button id='jump-top' title="{{i18n topic.progress.jump_top}}" {{bindAttr disabled="jumpTopDisabled"}} {{action jumpTop}}><i class="icon-circle-arrow-up"></i></button>
|
||||||
<div class='nums'>
|
<div class='nums'>
|
||||||
|
@ -162,9 +162,7 @@ Discourse.TopicView = Discourse.View.extend(Discourse.Scrolling, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
resetExamineDockCache: function() {
|
resetExamineDockCache: function() {
|
||||||
this.docAt = null;
|
this.set('docAt', false);
|
||||||
this.dockedTitle = false;
|
|
||||||
this.dockedCounter = false;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
updateDock: function(postView) {
|
updateDock: function(postView) {
|
||||||
@ -239,37 +237,25 @@ Discourse.TopicView = Discourse.View.extend(Discourse.Scrolling, {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var offset = window.pageYOffset || $('html').scrollTop();
|
var offset = window.pageYOffset || $('html').scrollTop();
|
||||||
var firstLoaded = topic.get('postStream.firstPostLoaded');
|
if (!this.get('docAt')) {
|
||||||
if (!this.docAt) {
|
|
||||||
var title = $('#topic-title');
|
var title = $('#topic-title');
|
||||||
if (title && title.length === 1) {
|
if (title && title.length === 1) {
|
||||||
this.docAt = title.offset().top;
|
this.set('docAt', title.offset().top);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var headerController = this.get('controller.controllers.header');
|
var headerController = this.get('controller.controllers.header');
|
||||||
if (this.docAt) {
|
if (this.get('docAt')) {
|
||||||
headerController.set('showExtraInfo', offset >= this.docAt || !firstLoaded);
|
headerController.set('showExtraInfo', offset >= this.get('docAt') || topic.get('postStream.firstPostNotLoaded'));
|
||||||
} else {
|
} else {
|
||||||
headerController.set('showExtraInfo', !firstLoaded);
|
headerController.set('showExtraInfo', topic.get('postStream.firstPostNotLoaded'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// there is a whole bunch of caching we could add here
|
// Dock the counter if necessary
|
||||||
var $lastPost = $('.last-post');
|
var $lastPost = $('article[data-post-id=' + topic.get('postStream.lastPostId') + "]");
|
||||||
var lastPostOffset = $lastPost.offset();
|
var lastPostOffset = $lastPost.offset();
|
||||||
if (!lastPostOffset) return;
|
if (!lastPostOffset) { return; }
|
||||||
|
this.set('controller.dockedCounter', (offset >= (lastPostOffset.top + $lastPost.height()) - $(window).height()));
|
||||||
if (offset >= (lastPostOffset.top + $lastPost.height()) - $(window).height()) {
|
|
||||||
if (!this.dockedCounter) {
|
|
||||||
$('#topic-progress-wrapper').addClass('docked');
|
|
||||||
this.dockedCounter = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (this.dockedCounter) {
|
|
||||||
$('#topic-progress-wrapper').removeClass('docked');
|
|
||||||
this.dockedCounter = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
topicTrackingState: function() {
|
topicTrackingState: function() {
|
||||||
|
@ -22,6 +22,8 @@ test('defaults', function() {
|
|||||||
test('appending posts', function() {
|
test('appending posts', function() {
|
||||||
var postStream = buildStream(4567, [1, 3, 4]);
|
var postStream = buildStream(4567, [1, 3, 4]);
|
||||||
|
|
||||||
|
equal(postStream.get('lastPostId'), 4, "the last post id is 4");
|
||||||
|
|
||||||
ok(!postStream.get('hasPosts'), "there are no posts by default");
|
ok(!postStream.get('hasPosts'), "there are no posts by default");
|
||||||
ok(!postStream.get('firstPostLoaded'), "the first post is not loaded");
|
ok(!postStream.get('firstPostLoaded'), "the first post is not loaded");
|
||||||
ok(!postStream.get('lastPostLoaded'), "the last post is not loaded");
|
ok(!postStream.get('lastPostLoaded'), "the last post is not loaded");
|
||||||
@ -29,7 +31,6 @@ test('appending posts', function() {
|
|||||||
|
|
||||||
postStream.appendPost(Discourse.Post.create({id: 2, post_number: 2}));
|
postStream.appendPost(Discourse.Post.create({id: 2, post_number: 2}));
|
||||||
ok(!postStream.get('firstPostLoaded'), "the first post is still not loaded");
|
ok(!postStream.get('firstPostLoaded'), "the first post is still not loaded");
|
||||||
ok(!postStream.get('lastPostLoaded'), "the last post is still not loaded");
|
|
||||||
equal(postStream.get('posts.length'), 1, "it has one post in the stream");
|
equal(postStream.get('posts.length'), 1, "it has one post in the stream");
|
||||||
|
|
||||||
postStream.appendPost(Discourse.Post.create({id: 4, post_number: 4}));
|
postStream.appendPost(Discourse.Post.create({id: 4, post_number: 4}));
|
||||||
|
Reference in New Issue
Block a user