MediaWiki:Common.js: Difference between revisions
Content deleted Content added
No edit summary Tag: Manual revert |
No edit summary Tag: Manual revert |
||
| (24 intermediate revisions by the same user not shown) | |||
Line 26:
/**
* @source https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
* @rev 6
*/
Line 124:
// CapSach — Sticky TOC overlay (UNRESTRICTED: Works on iPad/Desktop/Mobile)
(function () {
// 1. REMOVED the "min-width: 768px" check. Now runs everywhere.
Line 220:
// Force button display immediately
btn.style.display = 'flex';
btn.addEventListener('click', openOverlay);
Line 234:
// Navigate and try to ensure mobile-collapsed sections are visible
// Navigate and try to ensure mobile-collapsed sections are visible
list.addEventListener('click', function (e) {
var a = e.target.closest('a');
Line 240 ⟶ 241:
var targetId = a.getAttribute('href').slice(1);
// === NEW LOGIC START: Scroll to Top for "Contents" ===
// If the user clicks the "Contents" header (id="mw-toc-heading"), scroll to top (0,0)
// === FIXED CODE ===
if (targetId === 'mw-toc-heading') {
closeOverlay();
// Delay scroll to let iOS Safari process the overflow change
setTimeout(function() {
try {
window.scrollTo({ top: 0, behavior: 'smooth' });
} catch (e) {
window.scrollTo(0, 0);
}
// Fallback for older iOS Safari
document.documentElement.scrollTop = 0;
document.body.scrollTop = 0;
}, 100);
if (history.replaceState) {
history.replaceState(null, '', window.location.pathname + window.location.search);
}
return;
}
// === NEW LOGIC END ===
var target = document.getElementById(targetId);
closeOverlay();
Line 289 ⟶ 314:
});
$(document).ready(function() {
// Check if the button already exists to prevent duplicates
if ($('#custom-email-btn').length === 0) {
// Create the email button element
var emailBtn = $('<a>', {
id: 'custom-email-btn',
href: 'mailto:bananabot@axabrain.com',
// Simple accessible title
title: 'Contact AXA BRAIN Services'
});
// Add it to the body of the page
$('body').append(emailBtn);
}
});
/* Open AXA BRAIN AI Assistant when clicking the logo */
$(document).ready(function() {
$('.fullscreen-logo').css('cursor', 'pointer').click(function(e) {
e.preventDefault();
// Method 1: Click the AI Assistant floating icon
var $aiButton = $('img[src*="ai-icon.png"]').closest('div, button, a');
if ($aiButton.length > 0) {
$aiButton.trigger('click');
return;
}
// Method 2: Try the extension's trigger class
var $trigger = $('.ext-aiassistant-trigger, .ext-aiassistant');
if ($trigger.length > 0) {
$trigger.first().trigger('click');
return;
}
console.log("AXA BRAIN Assistant button not found on this page.");
});
});
/* Inline footnotes ({{footnote}}). We render the note OURSELVES, appended to
<body> (the ROOT stacking context), so a table's sticky column can never
cover it and it behaves identically across browsers. The native title=""
tooltip is unreliable + unstyled, so we move it to data-fn (the bot still
reads the hidden .ed-fn-body span) and show:
- PHONE (no hover): tap a cue -> full-width banner at the top; tap to dismiss.
- DESKTOP (hover): hover a cue -> a small popover beside the cue.
If this script never runs, the title="" stays and the native tooltip is the
graceful fallback. */
(function () {
var cues = document.querySelectorAll('.ed-fn');
if (!cues.length) { return; }
// Suppress the native tooltip; keep the note text in data-fn.
Array.prototype.forEach.call(cues, function (el) {
if (el.hasAttribute('title')) {
el.setAttribute('data-fn', el.getAttribute('title'));
el.removeAttribute('title');
}
});
var box = null, activeCue = null;
function noteOf(el) { return el.getAttribute('data-fn') || ''; }
function cueOf(e) {
var t = e.target;
return (t && t.closest) ? t.closest('.ed-fn') : null;
}
function close() {
if (box) { box.remove(); box = null; }
activeCue = null;
document.removeEventListener('click', onAway, true);
}
function onAway(e) {
if (!cueOf(e)) { close(); }
}
var touch = window.matchMedia && window.matchMedia('(hover: none)').matches;
if (touch) {
// Phone: full-width banner pinned to the top; the next tap anywhere dismisses.
document.addEventListener('click', function (e) {
var cue = cueOf(e);
if (!cue) { return; }
e.preventDefault();
var txt = noteOf(cue);
if (!txt) { return; }
e.stopPropagation();
close();
box = document.createElement('div');
box.className = 'ed-fn-banner';
box.textContent = txt;
document.body.appendChild(box);
setTimeout(function () {
document.addEventListener('click', onAway, true);
}, 0);
}, false);
} else {
// Desktop: a styled popover beside the cue while hovering it.
document.addEventListener('mouseover', function (e) {
var cue = cueOf(e);
if (!cue || cue === activeCue) { return; }
var txt = noteOf(cue);
if (!txt) { return; }
close();
activeCue = cue;
box = document.createElement('div');
box.className = 'ed-fn-popover';
box.textContent = txt;
document.body.appendChild(box);
var r = cue.getBoundingClientRect();
var left = Math.max(8, Math.min(r.left, window.innerWidth - box.offsetWidth - 8));
var top = r.top - box.offsetHeight - 8; // above the cue...
if (top < 8) { top = r.bottom + 8; } // ...or below if no room
box.style.left = left + 'px';
box.style.top = top + 'px';
});
document.addEventListener('mouseout', function (e) {
if (!activeCue) { return; }
var to = e.relatedTarget;
if (to && to.closest && to.closest('.ed-fn') === activeCue) { return; }
close();
});
window.addEventListener('scroll', function () { if (box) { close(); } }, true);
}
})();
| |||