Nicht mehr alle Umrechungsdaten in jeder Seite. Hoffentlich auch Fix für Ladereihenfolge der JS Dateien.

This commit is contained in:
2026-05-28 22:48:57 +02:00
parent e16e9e36fd
commit b92168399f
5 changed files with 60 additions and 105 deletions

View File

@@ -1,5 +1,34 @@
'use strict';
/**
* Alpine.js navigation helpers for conversion page.
* Handles navigation via hidden AJAX link.
*/
function navActions() {
return {
navigate(url) {
this.$refs.ajaxLink.href = url;
this.$nextTick(() => this.$refs.ajaxLink.click());
},
navigateWithValue(url) {
const el = document.getElementById('value');
const val = el ? el.value.replace(/,/g, '.') : '1';
this.$refs.ajaxLink.href = url + '?v=' + val;
this.$nextTick(() => this.$refs.ajaxLink.click());
},
navigateWithResult(url) {
const el = document.getElementById('result');
const val = el ? el.value.replace(/,/g, '.') : '';
if (val) {
this.$refs.ajaxLink.href = url + '?v=' + val;
} else {
this.$refs.ajaxLink.href = url;
}
this.$nextTick(() => this.$refs.ajaxLink.click());
}
};
}
/**
* Factory function for Alpine.js converter components.
* @param {string} engine - 'linear', 'intermediate' or 'runtime'
@@ -29,8 +58,9 @@ function createConverter(engine, config) {
this.calculate();
},
async loadRates() {
const pbUrl = document.querySelector('meta[name="pocketbase-url"]')?.content ||
'https://www.alphabreed.com';
const pbUrl = document.querySelector(
'meta[name="pocketbase-url"]')?.content
|| 'https://www.alphabreed.com';
try {
const response = await fetch(
`${pbUrl}/api/collections/currencies/records`);
@@ -77,7 +107,8 @@ function createConverter(engine, config) {
this.result = prettyNumber(rawResult);
const normalizedInputValue = this.inputValue
.replace(/,/g, '.');
if (normalizedInputValue && normalizedInputValue !== '0') {
if (normalizedInputValue
&& normalizedInputValue !== '0') {
history.replaceState(
null, '', '?v=' + normalizedInputValue);
}
@@ -133,8 +164,10 @@ function createConverter(engine, config) {
return;
}
this.result = prettyNumber(rawResult);
const normalizedInputValue = this.inputValue.replace(/,/g, '.');
if (normalizedInputValue && normalizedInputValue !== '0') {
const normalizedInputValue = this.inputValue
.replace(/,/g, '.');
if (normalizedInputValue
&& normalizedInputValue !== '0') {
history.replaceState(
null, '', '?v=' + normalizedInputValue);
}
@@ -145,60 +178,6 @@ function createConverter(engine, config) {
};
}
/**
* Alpine.js component for the conversion form.
* Handles category/from/to dropdowns and swap button.
* @param {object} defaults - Initial values
* @returns {object} Alpine component data
*/
function conversionForm(defaults) {
return {
category: defaults.category,
from: defaults.from,
to: defaults.to,
get actionUrl() {
const search = window.location.search;
return '/' + this.from + '-in-' + this.to + '/'
+ (search || '');
},
swapWithResult() {
const resultEl = document.getElementById('result');
const resultVal = resultEl?.value || '';
if (resultVal) {
history.replaceState(
null, '', '?v=' + resultVal.replace(/,/g, '.'));
}
const temp = this.from;
this.from = this.to;
this.to = temp;
this.$nextTick(() => {
this.$refs.navLink.click();
});
},
onCategoryChange() {
const cat = UNITS_DATA[this.category];
if (!cat || !cat.units) return;
const units = Object.keys(cat.units);
this.from = units[0];
this.to = units[1] || units[0];
this.$nextTick(() => {
this.$refs.navLink.click();
});
},
init() {
this.$watch('category', (val, old) => {
if (val && old && val !== old) {
this.onCategoryChange();
}
});
}
};
}
/**
* Temperature conversion via Celsius intermediate.
* @param {Decimal} value