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><a href="/blog.html">blog</a></li>
|
||||||
<li>
|
<li>
|
||||||
<label for="styleswitcher">change de style :</label>
|
<label for="styleswitcher">change de style :</label>
|
||||||
<select id="styleswitcher" name="styleswitcher">
|
<select id="styleswitcher"></select>
|
||||||
<option>Default</option>
|
|
||||||
<option>No-CSS</option>
|
|
||||||
<option>Darkmagenta</option>
|
|
||||||
</select>
|
|
||||||
<script>initStyleSelectElement()</script>
|
<script>initStyleSelectElement()</script>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -18,11 +18,7 @@
|
||||||
<li><a href="/blog.html">blog</a></li>
|
<li><a href="/blog.html">blog</a></li>
|
||||||
<li>
|
<li>
|
||||||
<label for="styleswitcher">change de style :</label>
|
<label for="styleswitcher">change de style :</label>
|
||||||
<select id="styleswitcher" name="styleswitcher">
|
<select id="styleswitcher"></select>
|
||||||
<option>Default</option>
|
|
||||||
<option>No-CSS</option>
|
|
||||||
<option>Darkmagenta</option>
|
|
||||||
</select>
|
|
||||||
<script>initStyleSelectElement()</script>
|
<script>initStyleSelectElement()</script>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -18,11 +18,7 @@
|
||||||
<li><a href="/blog.html">blog</a></li>
|
<li><a href="/blog.html">blog</a></li>
|
||||||
<li>
|
<li>
|
||||||
<label for="styleswitcher">change de style :</label>
|
<label for="styleswitcher">change de style :</label>
|
||||||
<select id="styleswitcher" name="styleswitcher">
|
<select id="styleswitcher"></select>
|
||||||
<option>Default</option>
|
|
||||||
<option>No-CSS</option>
|
|
||||||
<option>Darkmagenta</option>
|
|
||||||
</select>
|
|
||||||
<script>initStyleSelectElement()</script>
|
<script>initStyleSelectElement()</script>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</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",
|
const styles = { "Default" : "/css/default.css",
|
||||||
"No-CSS" : "/css/no-css.css",
|
"No-CSS" : "/css/no-css.css",
|
||||||
"Darkmagenta" : "/css/darkmagenta.css",
|
"Darkmagenta" : "/css/darkmagenta.css",
|
||||||
|
@ -27,6 +31,17 @@ function initStyle () {
|
||||||
|
|
||||||
function initStyleSelectElement () {
|
function initStyleSelectElement () {
|
||||||
const styleSelectElement = document.getElementById("styleswitcher");
|
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.value = sessionStorage.getItem("currentStyle");
|
||||||
|
|
||||||
styleSelectElement.addEventListener("change", (event) => {setStyle(event.target.value)});
|
styleSelectElement.addEventListener("change", (event) => {setStyle(event.target.value)});
|
||||||
|
|
|
@ -18,11 +18,7 @@
|
||||||
<li><a href="/blog.html">blog</a></li>
|
<li><a href="/blog.html">blog</a></li>
|
||||||
<li>
|
<li>
|
||||||
<label for="styleswitcher">change de style :</label>
|
<label for="styleswitcher">change de style :</label>
|
||||||
<select id="styleswitcher" name="styleswitcher">
|
<select id="styleswitcher"></select>
|
||||||
<option>Default</option>
|
|
||||||
<option>No-CSS</option>
|
|
||||||
<option>Darkmagenta</option>
|
|
||||||
</select>
|
|
||||||
<script>initStyleSelectElement()</script>
|
<script>initStyleSelectElement()</script>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
Loading…
Add table
Reference in a new issue