-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
(function() { | ||
// Función para establecer un dato en LocalStorage | ||
function setLocalStorageItem(key, value) { | ||
localStorage.setItem(key, JSON.stringify(value)); | ||
} | ||
|
||
// Función para obtener un dato de LocalStorage | ||
function getLocalStorageItem(key) { | ||
const item = localStorage.getItem(key); | ||
return item ? JSON.parse(item) : null; | ||
} | ||
|
||
// Make every section collapsable and adds a button next to each section to collapse it using fa-compress | ||
// and fa-expand icons | ||
// Each section is identified by document.querySelector("#modulos") | ||
// Where each div inside "#modulos" has an h1 which is the title of the section. We want to collapse everything except the title | ||
function makeCollapsable() { | ||
const modulos = document.querySelector("#modulos"); | ||
modulos.querySelectorAll("div > h1").forEach(section => { | ||
const content = section.nextElementSibling; | ||
section.style.cursor = "pointer"; | ||
section.innerHTML += " <i class='fas fa-compress'></i>"; | ||
section.addEventListener("click", () => { | ||
content.style.display = content.style.display === "none" ? "block" : "none"; | ||
// Save state to local storage | ||
saveCollapsableState(); | ||
}); | ||
}); | ||
} | ||
|
||
|
||
// Save every collapsable state in LocalStorage | ||
function saveCollapsableState() { | ||
const modulos = document.querySelector("#modulos"); | ||
const state = {}; | ||
modulos.querySelectorAll("div > h1").forEach(section => { | ||
const content = section.nextElementSibling; | ||
state[section.innerText] = content.style.display; | ||
}); | ||
setLocalStorageItem("collapsableState", state); | ||
} | ||
|
||
// Load every collapsable state from LocalStorage | ||
function loadCollapsableState() { | ||
const modulos = document.querySelector("#modulos"); | ||
const state = getLocalStorageItem("collapsableState"); | ||
if (!state) {return} | ||
modulos.querySelectorAll("div > h1").forEach(section => { | ||
const content = section.nextElementSibling; | ||
content.style.display = state[section.innerText]; | ||
}); | ||
} | ||
|
||
// Verificar si la configuración de easyCopyCourseDetails está activada | ||
const collapsableMenusConfig = JSON.parse(localStorage.getItem("settings")).features.collapsableMenus | ||
if (getLocalStorageItem("settings")) { | ||
if (!collapsableMenusConfig) {return} | ||
} | ||
|
||
// Call the functions | ||
makeCollapsable(); | ||
loadCollapsableState(); | ||
window.addEventListener("beforeunload", saveCollapsableState); | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters