Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
feat(Report): Add support for persisting settings to browser storage (#…
Browse files Browse the repository at this point in the history
…61)

Co-authored-by: jkuester <[email protected]>
  • Loading branch information
jkuester and jkuester authored Sep 14, 2020
1 parent 840066a commit fd5c4c9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion features/support/world.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CustomWorld {
setOutput(output) {
this.output = output;
if (this.output.length > 0) {
this.window = new JSDOM(this.output, { runScripts: 'dangerously', pretendToBeVisual: true }).window;
this.window = new JSDOM(this.output, { url: 'https://localhost/', runScripts: 'dangerously', pretendToBeVisual: true }).window;
this.outputHTML = this.window.document;
} else {
this.window = null;
Expand Down
23 changes: 22 additions & 1 deletion src/templates/scripts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* globals window, document */
const persistentSettingsEnabled = typeof (Storage) !== 'undefined';
let pauseScrollActions = false;

const toggleSettingsDrawer = () => {
Expand Down Expand Up @@ -121,6 +122,14 @@ const toggleParentDirectoryButtons = (element) => {
}
};

const tagsCheckboxClicked = () => {
toggleTagDisplay();
if (persistentSettingsEnabled) {
const { localStorage } = window;
localStorage.cfDisplayTags = localStorage.cfDisplayTags != null && localStorage.cfDisplayTags === 'true' ? 'false' : 'true';
}
};

const init = () => {
// Add listeners for directory buttons
Array.from(document.getElementsByClassName('directory-button')).forEach((directoryButton) => {
Expand Down Expand Up @@ -167,7 +176,7 @@ const init = () => {
}
const tagsCheckbox = document.getElementById('tagsCheckbox');
if (tagsCheckbox) {
tagsCheckbox.addEventListener('click', toggleTagDisplay);
tagsCheckbox.addEventListener('click', tagsCheckboxClicked);
}

// Open the first feature.
Expand All @@ -180,6 +189,18 @@ const init = () => {
toggleFunctionAccordion(firstFeatureButton);
toggleDisplayedFeature(firstFeatureButton);
}

// Initialize the settings
if (persistentSettingsEnabled) {
// Display the tags if necessary
const { localStorage } = window;
if (localStorage.cfDisplayTags != null && localStorage.cfDisplayTags === 'true') {
toggleTagDisplay();
if (tagsCheckbox) {
tagsCheckbox.checked = 'true';
}
}
}
};

init();

0 comments on commit fd5c4c9

Please sign in to comment.