2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-06 10:50:21 +08:00

Make the back button less awkward when leaving a topic.

This commit is contained in:
Robin Ward 2014-02-28 14:26:17 -05:00
parent 61ff04d68b
commit 7d6984a915

View file

@ -34,6 +34,7 @@ $.parseParams = function(query) {
return params; return params;
}; };
var popstateCallbacks = [];
/** /**
`Ember.DiscourseLocation` implements the location API using the browser's `Ember.DiscourseLocation` implements the location API using the browser's
@ -222,7 +223,9 @@ Ember.DiscourseLocation = Ember.Object.extend({
popstateFired = true; popstateFired = true;
if (self.getURL() === self._previousURL) { return; } 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); 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')
});