MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
/* | /* ── Verse Actions ─────────────────────────────────────────────────────── */ | ||
( function () { | |||
'use strict'; | |||
/* ========================= | /* ========================= | ||
COPY FUNCTION + TOOLTIP | COPY FUNCTION + TOOLTIP | ||
========================= */ | ========================= */ | ||
function copyText(text, $btn) { | function copyText(text, $btn) { | ||
function showTooltip() { | |||
// Remove any existing tip on this button first | |||
$btn.find('.copy-tooltip').remove(); | |||
var $tip = $('<span class="copy-tooltip">Copied ✓</span>'); | var $tip = $('<span class="copy-tooltip">Copied ✓</span>'); | ||
$btn.append($tip); | $btn.css('position', 'relative').append($tip); | ||
// Trigger animation on next frame so transition fires | |||
requestAnimationFrame(function () { | |||
requestAnimationFrame(function () { | |||
$tip.addClass('copy-tooltip-visible'); | |||
}); | |||
}); | |||
setTimeout(function () { | setTimeout(function () { | ||
$tip. | $tip.removeClass('copy-tooltip-visible'); | ||
}, | // Remove after fade-out transition completes | ||
setTimeout(function () { $tip.remove(); }, 400); | |||
}, 1400); | |||
} | } | ||
| Line 91: | Line 38: | ||
} | } | ||
} | } | ||
// ── Commentary toggle handler ───────────────────────────────────────── | |||
function handleCommentary( btn ) { | |||
var verseId = btn.getAttribute( 'data-verse' ); | |||
if ( !verseId ) return; | |||
var block = document.getElementById( verseId ); | |||
if ( !block ) return; | |||
// Toggle visibility of all commentary panels inside this verse block | |||
var panels = block.querySelectorAll( '.commentary-block' ); | |||
panels.forEach( function ( panel ) { | |||
var isHidden = panel.style.display === 'none' || !panel.style.display; | |||
panel.style.display = isHidden ? '' : 'none'; | |||
} ); | |||
btn.classList.toggle( 'verse-action-active' ); | |||
} | |||
// ── Single delegated listener on the document ───────────────────────── | |||
document.addEventListener( 'click', function ( e ) { | |||
var btn = e.target.closest( '.verse-action-btn' ); | |||
if ( !btn ) return; | |||
if ( btn.classList.contains( 'verse-action-copy' ) ) { | |||
handleCopy( btn ); | |||
} else if ( btn.classList.contains( 'verse-action-commentary' ) ) { | |||
handleCommentary( btn ); | |||
} | |||
} ); | |||
}() ); | |||
Revision as of 08:53, 26 March 2026
/* ── Verse Actions ─────────────────────────────────────────────────────── */
( function () {
'use strict';
/* =========================
COPY FUNCTION + TOOLTIP
========================= */
function copyText(text, $btn) {
function showTooltip() {
// Remove any existing tip on this button first
$btn.find('.copy-tooltip').remove();
var $tip = $('<span class="copy-tooltip">Copied ✓</span>');
$btn.css('position', 'relative').append($tip);
// Trigger animation on next frame so transition fires
requestAnimationFrame(function () {
requestAnimationFrame(function () {
$tip.addClass('copy-tooltip-visible');
});
});
setTimeout(function () {
$tip.removeClass('copy-tooltip-visible');
// Remove after fade-out transition completes
setTimeout(function () { $tip.remove(); }, 400);
}, 1400);
}
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(text).then(showTooltip);
} else {
var $temp = $('<textarea>').val(text).appendTo('body');
$temp[0].select();
document.execCommand('copy');
$temp.remove();
showTooltip();
}
}
// ── Commentary toggle handler ─────────────────────────────────────────
function handleCommentary( btn ) {
var verseId = btn.getAttribute( 'data-verse' );
if ( !verseId ) return;
var block = document.getElementById( verseId );
if ( !block ) return;
// Toggle visibility of all commentary panels inside this verse block
var panels = block.querySelectorAll( '.commentary-block' );
panels.forEach( function ( panel ) {
var isHidden = panel.style.display === 'none' || !panel.style.display;
panel.style.display = isHidden ? '' : 'none';
} );
btn.classList.toggle( 'verse-action-active' );
}
// ── Single delegated listener on the document ─────────────────────────
document.addEventListener( 'click', function ( e ) {
var btn = e.target.closest( '.verse-action-btn' );
if ( !btn ) return;
if ( btn.classList.contains( 'verse-action-copy' ) ) {
handleCopy( btn );
} else if ( btn.classList.contains( 'verse-action-commentary' ) ) {
handleCommentary( btn );
}
} );
}() );