Skip to content

Commit

Permalink
Merge pull request #919 from City-of-Helsinki/UHF-9682
Browse files Browse the repository at this point in the history
UHF-9682: Add cookie check for siteimprove to be able to see inside accordions
  • Loading branch information
teroelonen authored Mar 11, 2024
2 parents 7cf989a + 3546706 commit fdb8217
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dist/js/accordion.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 22 additions & 2 deletions src/js/accordion/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,25 @@ export default class State {
this.siteAccordionStates[this.page] = this.siteAccordionStates[this.page] === undefined ? {} : this.siteAccordionStates[this.page];
this.pageAccordionStates = this.siteAccordionStates[this.page];
}

// Initialize the cookie check
this.AccordionsOpen = State.isCookieSet('helfi_accordions_open');
}

static isCookieSet = cookieName => {
const cookies = document.cookie;
const cookieArray = cookies.split('; ');

// Loop through the cookies to see if desired one is set.
for (let i = 0; i < cookieArray.length; i++) {
const cookiePair = cookieArray[i].split('=');
if (cookiePair[0] === cookieName) {
return true;
}
}
return false;
};

getStorageKey = () => `${this.site}-accordion`;

saveItemState = (accordionItemId, isOpen) => {
Expand All @@ -29,13 +46,16 @@ export default class State {
};

loadItemState = accordionItemId => {
// Use the cached cookie check result
if (this.AccordionsOpen) {
return true;
}

if (this.site === undefined) {
return false;
}
return this.pageAccordionStates[accordionItemId] === undefined ? false : this.pageAccordionStates[accordionItemId];
};

static getCurrentLanguage = () => window.drupalSettings.path.currentLanguage;

}

0 comments on commit fdb8217

Please sign in to comment.