fix: locale bug; didn't reverse on remove

This commit is contained in:
Strix 2023-12-24 03:17:39 +01:00
parent 32458c7fd4
commit 4dd1cf209b
No known key found for this signature in database
GPG key ID: 5F35B3B8537287A7
3 changed files with 10 additions and 6 deletions

View file

@ -1,6 +1,8 @@
// [x-copy-query="<query selector>"] // [x-copy-query="<query selector>"]
// [x-inner-text] - will use innerText // [x-inner-text] - will use innerText
(() => { (() => {
// TODO: make copy work with checksums because not uuid will not always cut it.
function updateCopy() { function updateCopy() {
document.querySelectorAll("[x-copy-query]:not([x1-copy-uuid])") document.querySelectorAll("[x-copy-query]:not([x1-copy-uuid])")
.forEach(e => { .forEach(e => {

View file

@ -11,9 +11,9 @@
function updateLocale() { function updateLocale() {
document.querySelectorAll("[x-locale-key]:not([x1-locale-uuid])") document.querySelectorAll("[x-locale-key]:not([x1-locale-uuid])")
.forEach(e => { .forEach(e => {
let uuid = new Date().getTime().toString(36); let uuid = (Math.random() + new Date().getTime()).toString(36);
e.setAttribute("x1-locale-uuid", uuid); e.setAttribute("x1-locale-uuid", uuid);
backupElements[uuid] = e.cloneNode(); backupElements[uuid] = e.outerHTML;
e.innerHTML = getValueFromPath(locale, e.getAttribute("x-locale-key")); e.innerHTML = getValueFromPath(locale, e.getAttribute("x-locale-key"));
}) })
} }
@ -28,7 +28,7 @@
window.x0?.registerModuleRemoveHook("locale", (s) => { window.x0?.registerModuleRemoveHook("locale", (s) => {
Object.keys(s) Object.keys(s)
.forEach(uuid => { .forEach(uuid => {
document.querySelector(`[x1-locale-uuid="${uuid}"]`).outerHTML = s[uuid].outerHTML; document.querySelector(`[x1-locale-uuid="${uuid}"]`).outerHTML = s[uuid];
}) })
}) })
})() })()

View file

@ -7,7 +7,10 @@
> >
<body> <body>
<button onclick="window.x0.update()">Update x0</button> <button onclick="window.x0.update()">Update x0</button>
<input type="text" name="text" id="text"> <button onclick="window.location.reload()">Reload page</button>
<input type="text" onfocus="this.value = document.querySelector('html').getAttribute('x0-mods')" onchange="document.querySelector('html').setAttribute('x0-mods', this.value); document.querySelector('#status').innerHTML='updated x0-mods'; window.x0.update(); setInterval(() => document.querySelector('#status').innerHTML = '', 500)">
<span id="status"></span>
<h1 x-locale-key="main.greeting"></h1> <h1 x-locale-key="main.greeting"></h1>
<div> <div>
<h2 x-locale-key="copy-section.header"></h2> <h2 x-locale-key="copy-section.header"></h2>
@ -19,9 +22,8 @@
</div> </div>
<div> <div>
<h2 x-locale-key="http-section.header"></h2> <h2 x-locale-key="http-section.header"></h2>
<pre x-inner-text x-get="./test.html" x-get-refresh=5000></> <pre x-inner-text x-get="./test.html" x-get-refresh=1000>
</div> </div>
</body> </body>
<script src="./x0.js"></script> <script src="./x0.js"></script>