Szatuna/js/szatuna.js
2026-02-26 14:35:27 +01:00

49 lines
1.1 KiB
JavaScript

/* Raktárhely szép kiírtás */
function NumberToABC(n) {
const abc = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
if (typeof n === 'string') {
const num = parseInt(n, 10);
if (isNaN(num) || num < 1 || num > 26) return null;
return abc.charAt(num - 1);
}
if (typeof n !== 'number' || n < 1 || n > 26) return null;
return abc.charAt(n - 1);
}
function padWithZero(str) {
if (str.length === 2) return str;
return str.toString().padStart(2, '0');
}
/* Menu elemek */
function fitMenuTexts() {
const buttons = document.querySelectorAll('.menubtn');
let minFontSize = 14;
buttons.forEach(btn => {
const p = btn.querySelector('p');
if (!p) return;
const availableWidth = btn.clientWidth - 10 - 36 - 15 - 10;
if (availableWidth <= 0) return;
p.style.whiteSpace = 'nowrap';
let fontSize = 14;
p.style.fontSize = fontSize + 'px';
while (p.scrollWidth > availableWidth && fontSize > 0.1) {
fontSize -= 0.1;
p.style.fontSize = fontSize + 'px';
}
if (fontSize < minFontSize) minFontSize = fontSize;
});
buttons.forEach(btn => {
const p = btn.querySelector('p');
if (p) p.style.fontSize = minFontSize + 'px';
});
}
fitMenuTexts();