Merge pull request #385 from ZogStriP/highlight-first-of-loaded-topics
highlight the first of the newly loaded topics when scrolling
This commit is contained in:
commit
c5c1ddfa83
|
@ -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 New Issue