Skip to content

Commit

Permalink
Method to Store Content shown
Browse files Browse the repository at this point in the history
Additionally added a feature that adds an event listener and saves the current language to the users local storage, if not defiend previously.

If it is defined it loads the selected language from this example Cpp or Csharp.

Which will be asked each time a refresh is called or page is reloaded.

Additionally Pressing the Button either cpp or Csharp will rewrite the Language Preference and store it to locally.

Note:

This Requires that the JavaScript would be made globally not for each instance where possible.

Make sure that only specified buttons are called so make cases if there are less or more languages.

" in the future figure out where to store these as all in the same file would be an overkill potentially ".
  • Loading branch information
VerzatileDev committed Dec 29, 2023
1 parent 1e26e23 commit 6a6a299
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions docs/Concepts/OOP.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,17 @@ has_children: false
<button onclick="showContent('csharp')">C#</button>

<script>
function setLanguagePreference(language) {
localStorage.setItem('languagePreference', language);
}

function getLanguagePreference() {
return localStorage.getItem('languagePreference');
}

function showContent(language) {
setLanguagePreference(language);

if (language === 'cpp') {
document.getElementById('cppContent').style.display = 'block';
document.getElementById('csharpContent').style.display = 'none';
Expand All @@ -34,4 +44,11 @@ has_children: false
document.getElementById('csharpContent').style.display = 'block';
}
}

document.addEventListener('DOMContentLoaded', function () {
var savedLanguage = getLanguagePreference();
if (savedLanguage) {
showContent(savedLanguage);
}
});
</script>

0 comments on commit 6a6a299

Please sign in to comment.