User:Monster Domosed/common.js: Difference between revisionsGive feedback
No edit summary |
No edit summary |
||
| Line 21: | Line 21: | ||
/* ---- config ---- */ | /* ---- config ---- */ | ||
var imageUrl = el.dataset.image || '', | var imageUrl = el.dataset.image || '', | ||
image2dUrl = el.dataset.imageFlat || '', | image2dUrl = el.dataset.imageFlat || '', | ||
icon2dUrl = el.dataset.iconFlat || '', | icon2dUrl = el.dataset.iconFlat || '', | ||
icon3dUrl = el.dataset.iconStereo || '', | icon3dUrl = el.dataset.iconStereo || '', | ||
iconRotUrl = el.dataset.iconRotate || '', | iconRotUrl = el.dataset.iconRotate || '', | ||
fw = +el.dataset.frameWidth || 300, | fw = +el.dataset.frameWidth || 300, | ||
fh = +el.dataset.frameHeight || 400, | fh = +el.dataset.frameHeight || 400, | ||
| Line 78: | Line 78: | ||
/* ============================================================ | /* ============================================================ | ||
MODE TOGGLE | MODE TOGGLE — single button, swaps icon on click | ||
============================================================ */ | ============================================================ */ | ||
var | var toggleBtn = null, | ||
iconImg2d = null, | |||
iconImg3d = null; | |||
if (image2dUrl) { | if (image2dUrl) { | ||
toggleBtn = document.createElement('span'); | |||
toggleBtn.className = 'rm-mode-toggle'; | |||
toggleBtn.setAttribute('role', 'button'); | |||
toggleBtn.setAttribute('tabindex', '0'); | |||
toggleBtn.title = 'Switch to 2D'; | |||
// | // Create both icon images, show only one at a time | ||
if (icon2dUrl) { | if (icon2dUrl) { | ||
iconImg2d = makeImg(icon2dUrl, '2D', 'rm-mode-icon rm-icon-2d'); | |||
} | } | ||
if (icon3dUrl) { | |||
iconImg3d = makeImg(icon3dUrl, '3D', 'rm-mode-icon rm-icon-3d'); | |||
iconImg3d.style.display = 'none'; // hidden initially (3D is active, show 2D icon) | |||
} | } | ||
// 3D | // In 3D mode → show 2D icon (to switch TO 2D) | ||
// In 2D mode → show 3D icon (to switch TO 3D) | |||
if (iconImg2d) toggleBtn.appendChild(iconImg2d); | |||
if (iconImg3d) toggleBtn.appendChild(iconImg3d); | |||
// Text fallback if no icons | |||
if (icon3dUrl) { | if (!icon2dUrl && !icon3dUrl) { | ||
toggleBtn.textContent = '2D'; | |||
} | } | ||
el.appendChild(toggleBtn); | |||
el.appendChild( | |||
} | } | ||
/* ============================================================ | /* ============================================================ | ||
ROTATION ICON (bottom-right | ROTATION ICON (bottom-right) | ||
============================================================ */ | ============================================================ */ | ||
if (iconRotUrl) { | if (iconRotUrl) { | ||
| Line 152: | Line 150: | ||
} | } | ||
if ( | // Swap the visible icon | ||
if (iconImg2d && iconImg3d) { | |||
// 2D mode active → show 3D icon (to switch back) | |||
// 3D mode active → show 2D icon (to switch to 2D) | |||
iconImg2d.style.display = is2D ? 'none' : ''; | |||
iconImg3d.style.display = is2D ? '' : 'none'; | |||
} | |||
// Update title | |||
if (toggleBtn) { | |||
toggleBtn.title = is2D ? 'Switch to 3D' : 'Switch to 2D'; | |||
// Text fallback | |||
if (!icon2dUrl && !icon3dUrl) { | |||
toggleBtn.textContent = is2D ? '3D' : '2D'; | |||
} | |||
} | } | ||
} | } | ||
if ( | if (toggleBtn) { | ||
toggleBtn.addEventListener('click', function () { | |||
setMode(is2D ? '3d' : '2d'); | |||
}); | |||
} | |||
/* ============================================================ | /* ============================================================ | ||