mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-24 08:09:13 -05:00
highlight the first of the newly loaded topics when scrolling
This commit is contained in:
parent
a0949ca992
commit
002776808f
2 changed files with 15 additions and 12 deletions
|
@ -17,16 +17,22 @@ Discourse.TopicList = Discourse.Model.extend({
|
||||||
Discourse.URL.replaceState("/" + (this.get('filter')) + "/more");
|
Discourse.URL.replaceState("/" + (this.get('filter')) + "/more");
|
||||||
$.ajax(moreUrl, {
|
$.ajax(moreUrl, {
|
||||||
success: function(result) {
|
success: function(result) {
|
||||||
var newTopics, topicIds, topics;
|
var newTopics, topicIds, topics, topicsAdded = 0;
|
||||||
if (result) {
|
if (result) {
|
||||||
|
// the new topics loaded from the server
|
||||||
newTopics = Discourse.TopicList.topicsFrom(result);
|
newTopics = Discourse.TopicList.topicsFrom(result);
|
||||||
|
// the current topics
|
||||||
topics = _this.get('topics');
|
topics = _this.get('topics');
|
||||||
|
// keeps track of the ids of the current topics
|
||||||
topicIds = [];
|
topicIds = [];
|
||||||
topics.each(function(t) {
|
topics.each(function(t) {
|
||||||
topicIds[t.get('id')] = true;
|
topicIds[t.get('id')] = true;
|
||||||
});
|
});
|
||||||
|
// add new topics to the list of current topics if not already present
|
||||||
newTopics.each(function(t) {
|
newTopics.each(function(t) {
|
||||||
if (!topicIds[t.get('id')]) {
|
if (!topicIds[t.get('id')]) {
|
||||||
|
// highlight the first of the new topics so we can get a visual feedback
|
||||||
|
t.set('highlight', topicsAdded++ === 0);
|
||||||
return topics.pushObject(t);
|
return topics.pushObject(t);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -43,13 +49,11 @@ Discourse.TopicList = Discourse.Model.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
insert: function(json) {
|
insert: function(json) {
|
||||||
var newTopic;
|
var newTopic = Discourse.TopicList.decodeTopic(json);
|
||||||
newTopic = Discourse.TopicList.decodeTopic(json);
|
// new Topics are always unseen
|
||||||
/* New Topics are always unseen
|
|
||||||
*/
|
|
||||||
|
|
||||||
newTopic.set('unseen', true);
|
newTopic.set('unseen', true);
|
||||||
newTopic.set('highlightAfterInsert', true);
|
// and highlighted on the topics list view
|
||||||
|
newTopic.set('highlight', true);
|
||||||
return this.get('inserted').unshiftObject(newTopic);
|
return this.get('inserted').unshiftObject(newTopic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,16 +33,15 @@ Discourse.TopicListItemView = Discourse.View.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
didInsertElement: function() {
|
didInsertElement: function() {
|
||||||
|
// highligth the last topic viewed
|
||||||
if (Discourse.get('transient.lastTopicIdViewed') === this.get('content.id')) {
|
if (Discourse.get('transient.lastTopicIdViewed') === this.get('content.id')) {
|
||||||
Discourse.set('transient.lastTopicIdViewed', null);
|
Discourse.set('transient.lastTopicIdViewed', null);
|
||||||
this.highlight();
|
this.highlight();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (this.get('content.highlightAfterInsert')) {
|
// highlight new topics that have been loaded from the server or the one we just created
|
||||||
return this.highlight();
|
else if (this.get('content.highlight')) {
|
||||||
|
this.highlight();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue