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:
parent
61ff04d68b
commit
7d6984a915
1 changed files with 26 additions and 1 deletions
|
@ -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')
|
||||||
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue