MediaWiki:Common.js: Difference between revisions

Content deleted Content added
No edit summary
Tag: Reverted
No edit summary
 
(24 intermediate revisions by the same user not shown)
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// (window1.matchMedia('( REMOVED the "min-width: 768px)')" check.matches) return;Now runs everywhere.
 
// Only run on normalpages contentwhere pagesit 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 });
})();
 
/* ForceScript thefor wrapperInline toExpandable handle layoutTemplate */
$(function() {
.quiet-btn-wrapper {
$('.inline-expand-trigger').on('click', function() {
display: inline-block !important;
// 1. Toggle the content visibility
padding: 0 !important;
$(this).next('.inline-expand-content').toggle();
}
 
// 2. Toggle the arrow icon
/* Target the link inside with Maximum Priority */
const currentText = $(this).text();
/* We use #mw-content-text to overpower default wiki styles */
$(this).text(
#mw-content-text .quiet-btn-wrapper a,
currentText.includes('▸') ? currentText.replace('▸', '◂') : currentText.replace('◂', '▸')
.quiet-btn-wrapper a,
);
.quiet-btn-wrapper a.external {
});
});
/* 1. FORCE THE BOX SHAPE */
display: inline-block !important;
min-height: 32px !important;
padding: 6px 12px !important;
box-sizing: border-box !important;
border-radius: 2px !important;
border: 1px solid transparent !important;
/* 2. FORCE THE COLORS (Overrides the Blue Link) */
background-color: #f8f9fa !important;
color: #202122 !important;
text-decoration: none !important;
background-image: none !important; /* Removes external link icon */
/* 3. FONTS */
font-family: sans-serif !important;
font-size: 14px !important; /* 0.875rem */
font-weight: 700 !important;
line-height: 1.4 !important;
}
 
$(document).ready(function() {
/* HOVER EFFECT */
// Check if the button already exists to prevent duplicates
#mw-content-text .quiet-btn-wrapper a:hover,
if ($('#custom-email-btn').length === 0) {
.quiet-btn-wrapper a:hover {
background-color: #eaecf0 !important;
// Create the email button element
color: #202122 !important;
var emailBtn = $('<a>', {
text-decoration: none !important;
id: 'custom-email-btn',
}
href: 'mailto:services@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.");
/* DO NOT ADD CODE BELOW THIS LINE */
});
});