diff --git a/client/javascript/LeftAndMain_Subsites.js b/client/javascript/LeftAndMain_Subsites.js index 8dd2b24f..2e9c8821 100644 --- a/client/javascript/LeftAndMain_Subsites.js +++ b/client/javascript/LeftAndMain_Subsites.js @@ -3,8 +3,33 @@ (function($) { 'use strict'; $.entwine('ss', function($) { + + /** + * Store current subsite id and ask to reload the page if it detects any change + */ + function detectSubsiteChange(selectedId) { + var sessionKey = "admin_subsite_id"; + try { + localStorage.setItem(sessionKey, selectedId); + + window.addEventListener("storage", function () { + var tabId = localStorage.getItem(sessionKey); + if (tabId && selectedId != tabId) { + var msg = ss.i18n._t("Admin.SUBSITECHANGED", "You've changed subsite in another tab, do you want to reload the page?"); + if (confirm(msg)) { + window.location.reload(); + } + } + }); + } catch (e) { + // Maybe storage is full or not available, disable this feature and ignore error + } + } $('#SubsitesSelect').entwine({ + onmatch: function () { + detectSubsiteChange(this.find("option[selected]").attr("value")); + }, onadd:function(){ this.on('change', function(){ window.location.search=$.query.set('SubsiteID', $(this).val());