MediaWiki:Common.js: Difference between revisions

Content deleted Content added
No edit summary
Tag: Reverted
No edit summary
Tag: Manual revert
 
(33 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 121:
/* End of mw.loader.using callback */
} );
 
// CapSach — Mobile TOC overlay (all skins; phone widths)
// CapSach — Sticky TOC overlay (UNRESTRICTED: Works on iPad/Desktop/Mobile)
(function () {
// Don’t run on very wide screens (tablet/desktop have native TOC)
if (window.matchMedia('(min-width: 768px)').matches) return;
 
// 1. REMOVED the "min-width: 768px" check. Now runs everywhere.
// Only on normal content pages
 
// Only run on pages where it makes sense (Articles/MainPage)
if (window.mw && mw.config && mw.config.get) {
var isArticleisAllowed = !!mw.config.get('wgIsArticle') || mw.config.get('wgIsMainPage');
if (!isArticleisAllowed) return;
}
 
Line 153 ⟶ 154:
});
 
// Show only if there are enough headings to be useful (match core default)
// CHANGED: Lowered requirement to 1 heading so it always shows if there is any structure
if (items.length < 3) return;
if (items.length < 1) return;
 
// Create trigger button (bottom-left; avoids “Back to top” on bottom-right)
Line 217 ⟶ 219:
}
 
// Force button display immediately
btn.style.display = 'flex'; // reveal trigger now that we know we have headings
btn.style.display = 'flex';
btn.addEventListener('click', openOverlay);
 
Line 231 ⟶ 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 237 ⟶ 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 268 ⟶ 296:
});
 
// 2. REMOVED the "resize" event listener that was hiding the button.
// Re-hide on rotation/resize to tablet/desktop
// The button now persists on all screen sizes.
window.addEventListener('resize', function () {
if (window.matchMedia('(min-width: 768px)').matches) {
btn.style.display = 'none';
closeOverlay();
} else {
btn.style.display = 'flex';
}
}, { passive: true });
})();
 
/* Script for Inline Expandable Template */
/* ======================================================= */
$(function() {
/* FLOATING TOC: CLICK TITLE TO SCROLL TO TOP */
$('.inline-expand-trigger').on('click', function() {
/* ======================================================= */
// 1. Toggle the content visibility
$(this).next('.inline-expand-content').toggle();
 
// 2. Toggle the arrow icon
const currentText = $(this).text();
$(this).text(
currentText.includes('▸') ? currentText.replace('▸', '◂') : currentText.replace('◂', '▸')
);
});
});
 
$(document).ready(function() {
// Check if the button already exists to prevent duplicates
// Listen for clicks on the TOC title
if ($(document).on('click', '#cpscustom-tocemail-titlebtn',).length function(=== 0) {
 
// 1. Scroll toCreate the top of theemail pagebutton smoothlyelement
window.scrollTo({var top:emailBtn 0, behavior:= $('smooth<a>', });{
id: 'custom-email-btn',
href: 'mailto:bananabot@axabrain.com',
// 2. OPTIONAL: Uncomment the line below if you also
// want the TOC menu to close// automaticallySimple afteraccessible clicking.title
title: 'Contact AXA BRAIN Services'
// $('#cps-toc-overlay').removeClass('is-open');
});
 
// 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
/* DO NOT ADD CODE BELOW THIS LINE */
<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);
}
})();