mirror of
https://github.com/flarum/core.git
synced 2025-07-30 21:20:24 +02:00
Improve global back button. Goes back to previous interface.
It’s not quite like the browser’s back button because it doesn’t necessarily go back to the last URL; rather, it goes back to the last interface. So if you go into a discussion, then go to a different discussion via the side pane, the back button will still take you back to the index (not the previous discussion).
This commit is contained in:
@@ -14,7 +14,41 @@ export default Ember.Controller.extend({
|
||||
searchQuery: '',
|
||||
searchActive: false,
|
||||
|
||||
history: null,
|
||||
|
||||
init: function() {
|
||||
this._super();
|
||||
this.set('history', []);
|
||||
this.pushHistory('index', '/');
|
||||
},
|
||||
|
||||
pushHistory: function(name, url) {
|
||||
var url = url || this.get('target.url');
|
||||
var last = this.get('history').get('lastObject');
|
||||
if (last && last.name === name) {
|
||||
last.url = url;
|
||||
} else {
|
||||
this.get('history').pushObject({name: name, url: url});
|
||||
}
|
||||
},
|
||||
|
||||
popHistory: function(name) {
|
||||
var last = this.get('history').get('lastObject');
|
||||
if (last && last.name === name) {
|
||||
this.get('history').popObject();
|
||||
}
|
||||
},
|
||||
|
||||
canGoBack: Ember.computed('history.length', function() {
|
||||
return this.get('history.length') > 1;
|
||||
}),
|
||||
|
||||
actions: {
|
||||
goBack: function() {
|
||||
this.get('history').popObject();
|
||||
var history = this.get('history').get('lastObject');
|
||||
this.transitionToRoute.call(this, history.url);
|
||||
},
|
||||
search: function(query) {
|
||||
this.transitionToRoute('index', {queryParams: {searchQuery: query, sort: query ? 'relevance' : 'recent'}});
|
||||
},
|
||||
|
@@ -32,10 +32,6 @@ export default Ember.Controller.extend(UseComposer, Paneable, {
|
||||
},
|
||||
|
||||
actions: {
|
||||
transitionFromBackButton: function() {
|
||||
this.transitionToRoute('index');
|
||||
},
|
||||
|
||||
loadMore: function() {
|
||||
this.get('index').send('loadMore');
|
||||
},
|
||||
|
Reference in New Issue
Block a user