logo

blog

My website can't be that messy, right? git clone https://hacktivis.me/git/blog.git
commit: 4e1e6dc3a3fd0861a37eaa8d6380b433efbe3bff
parent f1290fa92e158560113a972ac945d98e29c09d41
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Thu,  9 Feb 2023 11:21:52 +0100

notes/font-test: Use a separated JS file

Diffstat:

ALICENSES/MIT.txt9+++++++++
ALICENSES/X11.txt13+++++++++++++
Anotes/font-test.js53+++++++++++++++++++++++++++++++++++++++++++++++++++++
Mnotes/font-test.xhtml50++++----------------------------------------------
4 files changed, 79 insertions(+), 46 deletions(-)

diff --git a/LICENSES/MIT.txt b/LICENSES/MIT.txt @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) <year> <copyright holders> + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/LICENSES/X11.txt b/LICENSES/X11.txt @@ -0,0 +1,13 @@ +X11 License + +Copyright (C) 1996 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from the X Consortium. + +X Window System is a trademark of X Consortium, Inc. diff --git a/notes/font-test.js b/notes/font-test.js @@ -0,0 +1,53 @@ +// Copyright 2023 Haelwenn (lanodan) Monnier <contact+blog@hacktivis.me> +// SPDX-License-Identifier: MIT + +'use strict'; + +const main = document.getElementsByTagName("main")[0]; + +main.style.fontSynthesis = 'none'; + +var fontfamilies = ""; +[ + "system-ui", "serif", "sans-serif", "monospace", "cursive", "fantasy", "ui-serif", "ui-sans-serif", "ui-monospace", "ui-rounded", "math", "emoji", "fangsong" +].forEach(function(e) {fontfamilies += `\t\t<option>${e}</option>\n`}); + +var fontweights = ""; +[ + "100", "200", "300", "400", "500", "600", "700", "800", "900", "950" +].forEach(function(e) {fontweights += `\t\t<option>${e}</option>\n`}); + +var fontstyles = ""; +[ + "normal", "italic", "oblique", "oblique -14deg", "oblique 90deg", "oblique -90deg" +].forEach(function(e) {fontstyles += `\t\t<option>${e}</option>\n`}); + +document.getElementById('fontsel').innerHTML = ` + <label>Family: + <input id="fontsel_in" type="text" list="fontfamilies"/> + <datalist id="fontfamilies">${fontfamilies}</datalist> + </label> + <label>Weight (<span id="fontsel_weight_val">400</span>): + <input id="fontsel_weight" type="range" max="1000" min="1" step="50" value="400" list="fontweights"/> + <datalist id="fontweights">${fontweights}</datalist> + </label> + <label>Style: + <input id="fontsel_style" type="text" list="fontstyles"/> + <datalist id="fontstyles">${fontstyles}</datalist> + </label> +`; + +document.getElementById('fontsel_in').addEventListener('change', (e) => { + main.style.fontFamily = e.target.value; +}); + +main.style.fontWeight = 400; // Normal + +document.getElementById('fontsel_weight').addEventListener('change', (e) => { + main.style.fontWeight = e.target.value; + document.getElementById('fontsel_weight_val').innerText = main.style.fontWeight; +}); + +document.getElementById('fontsel_style').addEventListener('change', (e) => { + main.style.fontStyle = e.target.value; +}); diff --git a/notes/font-test.xhtml b/notes/font-test.xhtml @@ -4,56 +4,13 @@ <meta charset="utf-8"/> <title>Font Test Page</title> <meta name="color-scheme" content="light dark"/> - <style>/*<![CDATA[*/ - :root { color-scheme: light dark; } - /* https://github.com/whatwg/html/issues/5426 */ - @media (prefers-color-scheme: dark) { - a { color: violet; } - }/*]]>*/ - </style> </head> <body> <h1>Font Test Page</h1> - <section id="needsjs" style="display:none;"> - <label> - Font-Family - <input - type="text" list="font-families" - onchange="document.getElementById('main').style.fontFamily = this.value" - /> - <datalist id="font-families"> - <option value="system-ui">system-ui</option> - <option value="serif">Serif</option> - <option value="sans-serif">Sans-Serif</option> - <option value="monospace">Monospace</option> - <option value="cursive">Cursive</option> - <option value="fantasy">Fantasy</option> - <option value="ui-serif">ui-serif</option> - <option value="ui-sans-serif">ui-sans-serif</option> - <option value="ui-monospace">ui-monospace</option> - <option value="ui-rounded">ui-rounded</option> - <option value="math">math</option> - <option value="emoji">emoji</option> - <option value="fangsong">fangsong (Chinese)</option> - </datalist> - </label> - <label> - Font-Style - <select onchange="document.getElementById('main').style.fontStyle = this.value"> - <option value="normal">normal</option> - <option value="italic">italic</option> - <option value="oblique">oblique</option> - </select> - </label> + <section id="fontsel"> + <small>Enable JavaScript to get font family and style selectors.</small> </section> - <small id="nojs"> - Enable JavaScript to get font family and style selectors. - </small> - <script> - document.getElementById('needsjs').style = ''; - document.getElementById('nojs').style = 'display:none;'; - </script> - <main id="main"> + <main contenteditable="true" spellcheck="false"> <h2>Pangrams</h2> <p>Thanks <a href="https://camtsmith.com/articles/2016-11/pangrams">Everything you ever wanted to know about pangrams</a> for it's completeness.</p> <p> @@ -128,5 +85,6 @@ <li><a href="https://en.wikipedia.org/wiki/Help:Multilingual_support#Scripts">Help:Multilingual support - Wikipedia</a></li> </ul> </main> + <!-- Needs to be at end of document --><script src="./font-test.js"></script> </body> </html>