mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
Make the back button less awkward when leaving a topic.
This commit is contained in:
parent
61ff04d68b
commit
7d6984a915
1 changed files with 26 additions and 1 deletions
|
@ -34,6 +34,7 @@ $.parseParams = function(query) {
|
|||
return params;
|
||||
};
|
||||
|
||||
var popstateCallbacks = [];
|
||||
|
||||
/**
|
||||
`Ember.DiscourseLocation` implements the location API using the browser's
|
||||
|
@ -222,7 +223,9 @@ Ember.DiscourseLocation = Ember.Object.extend({
|
|||
popstateFired = true;
|
||||
if (self.getURL() === self._previousURL) { return; }
|
||||
}
|
||||
callback(self.getURL());
|
||||
var url = self.getURL();
|
||||
popstateCallbacks.forEach(function(cb) { cb(url); });
|
||||
callback(url);
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -253,3 +256,25 @@ Ember.DiscourseLocation = Ember.Object.extend({
|
|||
});
|
||||
|
||||
Ember.Location.registerImplementation('discourse_location', Ember.DiscourseLocation);
|
||||
|
||||
/**
|
||||
Since we're using pushState/replaceState let's add extra hooks to cloakedView to
|
||||
eject itself when the popState occurs. This results in better back button
|
||||
behavior.
|
||||
**/
|
||||
Ember.CloakedCollectionView.reopen({
|
||||
_watchForPopState: function() {
|
||||
var self = this,
|
||||
cb = function() {
|
||||
self.cleanUp();
|
||||
self.set('controller.postStream.loaded', false);
|
||||
};
|
||||
this.set('_callback', cb);
|
||||
popstateCallbacks.addObject(cb);
|
||||
}.on('didInsertElement'),
|
||||
|
||||
_disbandWatcher: function() {
|
||||
popstateCallbacks.removeObject(this.get('_callback'));
|
||||
this.set('_callback', null);
|
||||
}.on('willDestroyElement')
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue