MediaWiki:Common.js: Difference between revisions

Content deleted Content added
No edit summary
Tag: Reverted
No edit summary
 
(7 intermediate revisions by the same user not shown)
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;
}, 200100);
if (history.replaceState) {
history.replaceState(null, '', window.location.pathname + window.location.search);
}
return;
}
// === NEW LOGIC END ===
 
var target = document.getElementById(targetId);
closeOverlay();
Line 306 ⟶ 331:
});
 
/* DOOpen NOTAXA ADDBRAIN CODEAI BELOWAssistant THISwhen LINEclicking 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 ($footeraiButton.length > 0) {
$closeBtnaiButton.htmltrigger(iconSvg'click');
})return;
}
// Method 2: Try the extension's trigger class
var $footertrigger = $('.ext-aiassistant-footertrigger, .ext-aiassistant');
if ($('#ai-assistant-close-mobile')trigger.length ===> 0) {
$trigger.first().trigger('click');
// Icon SVGreturn;
}
 
console.log("AXA BRAIN Assistant button not found on this page.");
/* ======================================================= */
});
/* MOBILE AI ASSISTANT: INJECT CLOSE BUTTON IN FOOTER */
/* ======================================================= */
$(function() {
// Only run on mobile devices
if (window.innerWidth > 768) return;
 
var checkFooter = setInterval(function() {
var $footer = $('.ext-aiassistant-footer');
if ($footer.length) {
clearInterval(checkFooter);
if ($('#ai-assistant-close-mobile').length === 0) {
var $closeBtn = $('<button>', {
id: 'ai-assistant-close-mobile',
class: 'cdx-button cdx-button--weight-quiet cdx-button--icon-only', // Removed "primary" class to remove default blue
title: 'Close Assistant',
click: function() {
// 1. Hide the panel
$('.ext-aiassistant-panel').hide();
// 2. SHOW THE CHAT ICON AGAIN
$('.ext-aiassistant-trigger').show();
}
});
 
// Icon SVG
var iconSvg = '<span class="cdx-icon cdx-icon--medium"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20"><path d="M4.34 2.93l12.73 12.73-1.41 1.41L2.93 4.35z"/><path d="M17.07 4.34L4.34 17.07l-1.41-1.41L15.66 2.93z" fill="currentColor"/></svg></span>';
$closeBtn.html(iconSvg);
 
$footer.prepend($closeBtn);
}
}
}, 200);
});