Skip to content

Commit

Permalink
Fix for splash control with multiple maps (origo-map#1622)
Browse files Browse the repository at this point in the history
  • Loading branch information
jokd authored Oct 31, 2022
1 parent 71afbab commit 95e4d8d
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/controls/splash.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const Splash = function Splash(options = {}) {
let hideButton;
let modal;
let component;
let contentKey;
let visibilityKey;

let {
title,
Expand All @@ -30,16 +32,16 @@ const Splash = function Splash(options = {}) {
};

const clearLocalStorage = function clearLocalStorage() {
localStorage.removeItem('splashVisibility');
localStorage.removeItem('splashContent');
localStorage.removeItem(visibilityKey);
localStorage.removeItem(contentKey);
};

const setLocalStorage = function setLocalStorage() {
const newContent = localStorage.getItem('splashContent') !== content;
if (localStorage.getItem('splashVisibility') !== 'false' || newContent) {
localStorage.setItem('splashContent', content);
const newContent = localStorage.getItem(contentKey) !== content;
if (localStorage.getItem(visibilityKey) !== 'false' || content) {
localStorage.setItem(contentKey, content);
if (newContent) {
localStorage.setItem('splashVisibility', 'true');
localStorage.setItem(visibilityKey, 'true');
}
}
};
Expand All @@ -55,7 +57,7 @@ const Splash = function Splash(options = {}) {
clearLocalStorage();
}

if (localStorage.getItem('splashVisibility') !== 'false') {
if (localStorage.getItem(visibilityKey) !== 'false') {
modal = Modal({
title,
content,
Expand Down Expand Up @@ -86,7 +88,7 @@ const Splash = function Splash(options = {}) {
const proceed = window.confirm(confirmText);
if (proceed) {
modal.closeModal();
localStorage.setItem('splashVisibility', false);
localStorage.setItem(visibilityKey, false);
}
}
});
Expand All @@ -96,6 +98,8 @@ const Splash = function Splash(options = {}) {
component = this;
viewer = evt.target;
target = viewer.getId();
contentKey = `splashContent;${window.location.pathname};${viewer.getMapName().split('.')[0]}`;
visibilityKey = `splashVisibility;${window.location.pathname};${viewer.getMapName().split('.')[0]}`;
if (!title) title = defaultTitle;
if (!content) content = defaultContent;

Expand Down

0 comments on commit 95e4d8d

Please sign in to comment.