This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/initializers/1_init_message_bus.js
Régis Hanol a24e1f152d BUGFIX: clicking cancel should not reload the page
when assets have changed.
2014-01-19 20:55:46 +01:00

29 lines
898 B
JavaScript

/**
Initialize the message bus to receive messages.
**/
Discourse.addInitializer(function() {
// We don't use the message bus in testing
if (Discourse.testing) { return; }
Discourse.MessageBus.alwaysLongPoll = Discourse.Environment === "development";
Discourse.MessageBus.start();
Discourse.MessageBus.subscribe("/global/asset-version", function(version){
Discourse.set("assetVersion",version);
if(Discourse.get("requiresRefresh")) {
// since we can do this transparently for people browsing the forum
// hold back the message a couple of hours
setTimeout(function() {
bootbox.confirm(I18n.lookup("assets_changed_confirm"), function(result){
if (result) {
document.location.reload();
}
});
}, 1000 * 60 * 120);
}
});
Discourse.KeyValueStore.init("discourse_", Discourse.MessageBus);
}, true);