Génère la liste des options du styleswitcher dynamiquement
This commit is contained in:
parent
eb449ccdbb
commit
46b99e0f17
5 changed files with 19 additions and 20 deletions
|
@ -18,11 +18,7 @@
|
|||
<li><a href="/blog.html">blog</a></li>
|
||||
<li>
|
||||
<label for="styleswitcher">change de style :</label>
|
||||
<select id="styleswitcher" name="styleswitcher">
|
||||
<option>Default</option>
|
||||
<option>No-CSS</option>
|
||||
<option>Darkmagenta</option>
|
||||
</select>
|
||||
<select id="styleswitcher"></select>
|
||||
<script>initStyleSelectElement()</script>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
|
@ -18,11 +18,7 @@
|
|||
<li><a href="/blog.html">blog</a></li>
|
||||
<li>
|
||||
<label for="styleswitcher">change de style :</label>
|
||||
<select id="styleswitcher" name="styleswitcher">
|
||||
<option>Default</option>
|
||||
<option>No-CSS</option>
|
||||
<option>Darkmagenta</option>
|
||||
</select>
|
||||
<select id="styleswitcher"></select>
|
||||
<script>initStyleSelectElement()</script>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
|
@ -18,11 +18,7 @@
|
|||
<li><a href="/blog.html">blog</a></li>
|
||||
<li>
|
||||
<label for="styleswitcher">change de style :</label>
|
||||
<select id="styleswitcher" name="styleswitcher">
|
||||
<option>Default</option>
|
||||
<option>No-CSS</option>
|
||||
<option>Darkmagenta</option>
|
||||
</select>
|
||||
<select id="styleswitcher"></select>
|
||||
<script>initStyleSelectElement()</script>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
/*
|
||||
* On enregistre ici la liste des feuilles de style disponibles.
|
||||
* Il doit toujours y avoir une feuille "Default".
|
||||
*/
|
||||
const styles = { "Default" : "/css/default.css",
|
||||
"No-CSS" : "/css/no-css.css",
|
||||
"Darkmagenta" : "/css/darkmagenta.css",
|
||||
|
@ -27,6 +31,17 @@ function initStyle () {
|
|||
|
||||
function initStyleSelectElement () {
|
||||
const styleSelectElement = document.getElementById("styleswitcher");
|
||||
|
||||
/* On génère ici la liste des options du <select> dynamiquement. Ca permet
|
||||
* de n'avoir à éditer que le script JavaScript pour ajouter de nouveaux
|
||||
* style, plutôt que toutes les pages HTML. */
|
||||
for (const styleName in styles) {
|
||||
styleOption = document.createElement("option");
|
||||
styleOption.value = styleName;
|
||||
styleOption.textContent = styleName;
|
||||
styleSelectElement.add(styleOption);
|
||||
}
|
||||
|
||||
styleSelectElement.value = sessionStorage.getItem("currentStyle");
|
||||
|
||||
styleSelectElement.addEventListener("change", (event) => {setStyle(event.target.value)});
|
||||
|
|
|
@ -18,11 +18,7 @@
|
|||
<li><a href="/blog.html">blog</a></li>
|
||||
<li>
|
||||
<label for="styleswitcher">change de style :</label>
|
||||
<select id="styleswitcher" name="styleswitcher">
|
||||
<option>Default</option>
|
||||
<option>No-CSS</option>
|
||||
<option>Darkmagenta</option>
|
||||
</select>
|
||||
<select id="styleswitcher"></select>
|
||||
<script>initStyleSelectElement()</script>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
Loading…
Add table
Reference in a new issue