From d3bec564a9b243a12294ab37edfbdbea1716b0ba Mon Sep 17 00:00:00 2001 From: Dayowe Date: Mon, 9 Jun 2025 10:01:29 +0200 Subject: [PATCH] Scale option --- dog-food-calculator-widget.js | 28 ++++++++++++++++++++++++---- iframe.html | 28 ++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/dog-food-calculator-widget.js b/dog-food-calculator-widget.js index 02432a5..dbf27e3 100644 --- a/dog-food-calculator-widget.js +++ b/dog-food-calculator-widget.js @@ -7,12 +7,12 @@ * *
* - * Advanced Usage with theme option: + * Advanced Usage with theme and scale options: * - *
+ *
* * Or with JavaScript: - * new DogCalorieCalculatorWidget(container, { theme: 'light' }); // 'light', 'dark', 'system' + * new DogCalorieCalculatorWidget(container, { theme: 'light', scale: 1.2 }); // theme: 'light', 'dark', 'system' | scale: 0.5-2.0 */ (function() { @@ -1111,6 +1111,7 @@ this.currentMER = 0; this.isImperial = false; this.theme = options.theme || 'system'; // 'light', 'dark', 'system' + this.scale = options.scale || 1.0; // 0.5 to 2.0 this.init(); } @@ -1118,6 +1119,7 @@ this.injectStyles(); this.injectHTML(); this.applyTheme(); + this.applyScale(); this.bindEvents(); this.updateUnitLabels(); } @@ -1182,6 +1184,23 @@ } } + applyScale() { + const widget = this.container.querySelector('.dog-calc-widget'); + if (!widget) return; + + // Clamp scale between 0.5 and 2.0 for usability + const clampedScale = Math.max(0.5, Math.min(2.0, this.scale)); + + if (clampedScale !== 1.0) { + widget.style.transform = `scale(${clampedScale})`; + widget.style.transformOrigin = 'top center'; + + // Adjust container to account for scaling + const actualHeight = widget.offsetHeight * clampedScale; + widget.style.marginBottom = `${(clampedScale - 1) * widget.offsetHeight}px`; + } + } + bindEvents() { const weightInput = this.container.querySelector('#weight'); const dogTypeSelect = this.container.querySelector('#dogType'); @@ -1675,7 +1694,8 @@ containers.forEach(container => { if (!container.dataset.initialized) { const theme = container.dataset.theme || 'system'; - new DogCalorieCalculatorWidget(container, { theme }); + const scale = parseFloat(container.dataset.scale) || 1.0; + new DogCalorieCalculatorWidget(container, { theme, scale }); container.dataset.initialized = 'true'; } }); diff --git a/iframe.html b/iframe.html index f360362..86a9a0f 100644 --- a/iframe.html +++ b/iframe.html @@ -1094,11 +1094,13 @@ this.currentMER = 0; this.isImperial = false; this.theme = this.getThemeFromURL() || 'system'; + this.scale = this.getScaleFromURL() || 1.0; this.init(); } init() { this.applyTheme(); + this.applyScale(); this.bindEvents(); this.updateUnitLabels(); this.setupIframeResize(); @@ -1114,12 +1116,38 @@ return ['light', 'dark', 'system'].includes(theme) ? theme : null; } + getScaleFromURL() { + const urlParams = new URLSearchParams(window.location.search); + const scale = parseFloat(urlParams.get('scale')); + return (!isNaN(scale) && scale >= 0.5 && scale <= 2.0) ? scale : null; + } + applyTheme() { const container = document.getElementById('dogCalculator'); container.classList.remove('theme-light', 'theme-dark', 'theme-system'); container.classList.add('theme-' + this.theme); } + applyScale() { + const container = document.getElementById('dogCalculator'); + if (!container) return; + + // Clamp scale between 0.5 and 2.0 for usability + const clampedScale = Math.max(0.5, Math.min(2.0, this.scale)); + + if (clampedScale !== 1.0) { + container.style.transform = `scale(${clampedScale})`; + container.style.transformOrigin = 'top center'; + + // Adjust container to account for scaling + setTimeout(() => { + const actualHeight = container.offsetHeight * clampedScale; + container.style.marginBottom = `${(clampedScale - 1) * container.offsetHeight}px`; + this.sendHeightToParent(); + }, 100); + } + } + bindEvents() { const weightInput = document.getElementById('weight'); const dogTypeSelect = document.getElementById('dogType');