- {{ $action := .RelPermalink }}
-
@@ -44,12 +39,15 @@
Einheitentyp:
@@ -181,6 +178,6 @@
{{ end }}
{{ define "headscripts" }}
-
-
+
+
{{ end }}
diff --git a/hugo/layouts/partials/units-data.html b/hugo/layouts/partials/units-data.html
deleted file mode 100644
index c1f1cf9..0000000
--- a/hugo/layouts/partials/units-data.html
+++ /dev/null
@@ -1,20 +0,0 @@
-{{ $filteredData := dict }}
-{{ range $k, $v := hugo.Data }}
- {{ $catData := $v }}
- {{ if and (eq $v.slug "waehrungen") $v.units }}
- {{ $units := partial "available-units.html"
- (dict "category" "waehrungen" "units" $v.units) }}
- {{ $catData = dict
- "conversion_engine" $v.conversion_engine
- "name" $v.name
- "slug" $v.slug
- "units" $units
- }}
- {{ end }}
- {{ $filteredData = merge $filteredData (dict $k $catData) }}
-{{ end }}
-
-
diff --git a/hugo/static/js/converter.js b/hugo/static/js/converter.js
index 2826aa9..b4c5f7f 100644
--- a/hugo/static/js/converter.js
+++ b/hugo/static/js/converter.js
@@ -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