diff --git a/Changelog.md b/Changelog.md index 90acddad7..27017207b 100644 --- a/Changelog.md +++ b/Changelog.md @@ -123,6 +123,7 @@ and on a pod that received that data. * Guard against passing nil into person\_image\_tag [#6286](https://github.com/diaspora/diaspora/pull/6286) * Prevent Handlebars from messing up indentation of pre tags [#6339](https://github.com/diaspora/diaspora/pull/6339) * Fix pagination design on notifications page [#6364](https://github.com/diaspora/diaspora/pull/6364) +* Improve handling of j/k hotkeys [#6462](https://github.com/diaspora/diaspora/pull/6462) ## Features diff --git a/app/assets/javascripts/app/app.js b/app/assets/javascripts/app/app.js index 683341821..d01071c62 100644 --- a/app/assets/javascripts/app/app.js +++ b/app/assets/javascripts/app/app.js @@ -94,10 +94,18 @@ var app = { // there's probably a better way to do this... $(document).on("click", "a[rel=backbone]", function(evt){ + if (!(app.stream && /^\/(?:stream|activity|aspects|public|mentions|likes)/.test(app.stream.basePath()))) { + // We aren't on a regular stream page + return; + } + evt.preventDefault(); var link = $(this); - - $(".stream_title").text(link.text()); + if(link.data("stream-title") && link.data("stream-title").length) { + $(".stream_title").text(link.data("stream-title")); + } else { + $(".stream_title").text(link.text()); + } app.router.navigate(link.attr("href").substring(1) ,true); }); }, diff --git a/app/assets/javascripts/app/router.js b/app/assets/javascripts/app/router.js index ee19dbd68..72eb15155 100644 --- a/app/assets/javascripts/app/router.js +++ b/app/assets/javascripts/app/router.js @@ -107,6 +107,7 @@ app.Router = Backbone.Router.extend({ app.stream.fetch(); app.page = new app.views.Stream({model : app.stream}); app.publisher = app.publisher || new app.views.Publisher({collection : app.stream.items}); + app.shortcuts = app.shortcuts || new app.views.StreamShortcuts({el: $(document)}); var streamFacesView = new app.views.StreamFaces({collection : app.stream.items}); diff --git a/app/assets/javascripts/app/views/stream/shortcuts.js b/app/assets/javascripts/app/views/stream/shortcuts.js index 70c473b7e..b09c6e753 100644 --- a/app/assets/javascripts/app/views/stream/shortcuts.js +++ b/app/assets/javascripts/app/views/stream/shortcuts.js @@ -1,21 +1,11 @@ // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later -app.views.StreamShortcuts = { - +app.views.StreamShortcuts = Backbone.View.extend({ _headerSize: 50, - - setupShortcuts : function() { - $(document).on('keydown', _.bind(this._onHotkeyDown, this)); - $(document).on('keyup', _.bind(this._onHotkeyUp, this)); - - this.on('hotkey:gotoNext', this.gotoNext, this); - this.on('hotkey:gotoPrev', this.gotoPrev, this); - this.on('hotkey:likeSelected', this.likeSelected, this); - this.on('hotkey:commentSelected', this.commentSelected, this); - this.on('hotkey:reshareSelected', this.reshareSelected, this); - this.on('hotkey:expandSelected', this.expandSelected, this); - this.on('hotkey:openFirstLinkSelected', this.openFirstLinkSelected, this); + events: { + "keydown": "_onHotkeyDown", + "keyup": "_onHotkeyUp" }, _onHotkeyDown: function(event) { @@ -28,10 +18,10 @@ app.views.StreamShortcuts = { // trigger the events based on what key was pressed switch (String.fromCharCode( event.which ).toLowerCase()) { case "j": - this.trigger('hotkey:gotoNext'); + this.gotoNext(); break; case "k": - this.trigger('hotkey:gotoPrev'); + this.gotoPrev(); break; default: } @@ -47,19 +37,19 @@ app.views.StreamShortcuts = { // trigger the events based on what key was pressed switch (String.fromCharCode( event.which ).toLowerCase()) { case "c": - this.trigger('hotkey:commentSelected'); + this.commentSelected(); break; case "l": - this.trigger('hotkey:likeSelected'); + this.likeSelected(); break; case "r": - this.trigger('hotkey:reshareSelected'); + this.reshareSelected(); break; case "m": - this.trigger('hotkey:expandSelected'); + this.expandSelected(); break; case "o": - this.trigger('hotkey:openFirstLinkSelected'); + this.openFirstLinkSelected(); break; default: } @@ -132,6 +122,5 @@ app.views.StreamShortcuts = { //add the selection and selected-class to new post element.className+=" shortcut_selected highlighted"; }, -}; +}); // @license-end - diff --git a/app/assets/javascripts/app/views/stream_view.js b/app/assets/javascripts/app/views/stream_view.js index 6ee1fbbe9..5bec76756 100644 --- a/app/assets/javascripts/app/views/stream_view.js +++ b/app/assets/javascripts/app/views/stream_view.js @@ -1,9 +1,6 @@ // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later -//= require ./stream/shortcuts - -app.views.Stream = app.views.InfScroll.extend(_.extend( - app.views.StreamShortcuts, { +app.views.Stream = app.views.InfScroll.extend({ initialize: function() { this.stream = this.model; @@ -13,7 +10,6 @@ app.views.Stream = app.views.InfScroll.extend(_.extend( this.setupNSFW(); this.setupInfiniteScroll(); - this.setupShortcuts(); this.markNavSelected(); }, @@ -32,5 +28,5 @@ app.views.Stream = app.views.InfScroll.extend(_.extend( streamSelection.find("[data-stream]").removeClass("selected"); streamSelection.find("[data-stream='" + activeStream + "']").addClass("selected"); } -})); +}); // @license-end diff --git a/app/assets/templates/header_tpl.jst.hbs b/app/assets/templates/header_tpl.jst.hbs index 9ff49a104..72e178b89 100644 --- a/app/assets/templates/header_tpl.jst.hbs +++ b/app/assets/templates/header_tpl.jst.hbs @@ -9,7 +9,7 @@ - + {{ podname }}