From d8165d7cee84c1568678c7acde6f91af63908169 Mon Sep 17 00:00:00 2001 From: cpradio Date: Sat, 6 Aug 2016 11:18:10 -0400 Subject: [PATCH 1/2] FEATURE: Allow keyboard shortcuts for topic list to start from last viewed topic --- .../javascripts/discourse/components/topic-list-item.js.es6 | 5 +++-- .../javascripts/discourse/lib/keyboard-shortcuts.js.es6 | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/discourse/components/topic-list-item.js.es6 b/app/assets/javascripts/discourse/components/topic-list-item.js.es6 index 28c00c4345..765154cb31 100644 --- a/app/assets/javascripts/discourse/components/topic-list-item.js.es6 +++ b/app/assets/javascripts/discourse/components/topic-list-item.js.es6 @@ -113,11 +113,12 @@ export default Ember.Component.extend(StringBuffer, { } }, - highlight() { + highlight(isLastViewedTopic = false) { const $topic = this.$(); const originalCol = $topic.css('backgroundColor'); $topic .addClass('highlighted') + .attr('data-islastviewedtopic', isLastViewedTopic) .stop() .animate({ backgroundColor: originalCol }, 2500, 'swing', function() { $topic.removeClass('highlighted'); @@ -128,7 +129,7 @@ export default Ember.Component.extend(StringBuffer, { // highlight the last topic viewed if (this.session.get('lastTopicIdViewed') === this.get('topic.id')) { this.session.set('lastTopicIdViewed', null); - this.highlight(); + this.highlight(true); } else if (this.get('topic.highlight')) { // highlight new topics that have been loaded from the server or the one we just created this.set('topic.highlight', false); diff --git a/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6 b/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6 index 70af9c9526..5701e4b735 100644 --- a/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6 +++ b/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6 @@ -277,7 +277,9 @@ export default { return; } - const $selected = $articles.filter('.selected'); + const $selected = ($articles.filter('.selected').length !== 0) + ? $articles.filter('.selected') + : $articles.filter('[data-islastviewedtopic=true]'); let index = $articles.index($selected); if ($selected.length !== 0) { //boundries check From 754e3b2287b806a97123037ce2e52bc82c3c88b7 Mon Sep 17 00:00:00 2001 From: cpradio Date: Mon, 8 Aug 2016 15:15:27 -0400 Subject: [PATCH 2/2] Convert boolean to opts object --- .../javascripts/discourse/components/topic-list-item.js.es6 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/discourse/components/topic-list-item.js.es6 b/app/assets/javascripts/discourse/components/topic-list-item.js.es6 index 765154cb31..4d2facadf1 100644 --- a/app/assets/javascripts/discourse/components/topic-list-item.js.es6 +++ b/app/assets/javascripts/discourse/components/topic-list-item.js.es6 @@ -113,12 +113,12 @@ export default Ember.Component.extend(StringBuffer, { } }, - highlight(isLastViewedTopic = false) { + highlight(opts = { isLastViewedTopic: false }) { const $topic = this.$(); const originalCol = $topic.css('backgroundColor'); $topic .addClass('highlighted') - .attr('data-islastviewedtopic', isLastViewedTopic) + .attr('data-islastviewedtopic', opts.isLastViewedTopic) .stop() .animate({ backgroundColor: originalCol }, 2500, 'swing', function() { $topic.removeClass('highlighted'); @@ -129,7 +129,7 @@ export default Ember.Component.extend(StringBuffer, { // highlight the last topic viewed if (this.session.get('lastTopicIdViewed') === this.get('topic.id')) { this.session.set('lastTopicIdViewed', null); - this.highlight(true); + this.highlight({ isLastViewedTopic: true }); } else if (this.get('topic.highlight')) { // highlight new topics that have been loaded from the server or the one we just created this.set('topic.highlight', false);