Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
And subsite change detection
Browse files Browse the repository at this point in the history
lekoala authored Mar 17, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 21240a7 commit eaf8608
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions client/javascript/LeftAndMain_Subsites.js
Original file line number Diff line number Diff line change
@@ -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());

0 comments on commit eaf8608

Please sign in to comment.