Difference between revisions of "MediaWiki:Common.js"
Jump to navigation
Jump to search
Jemaleddin (talk | contribs) |
Jemaleddin (talk | contribs) |
||
Line 1: | Line 1: | ||
/* Any JavaScript here will be loaded for all users on every page load. */ | /* Any JavaScript here will be loaded for all users on every page load. */ | ||
$(document).ready(function() { | $(document).ready(function() { | ||
const editLinks = document.querySelectorAll('.mw-editsection a'); // Select edit links | |||
const headings = document.querySelectorAll('h2'); // Select H2 headings | const headings = document.querySelectorAll('h2'); // Select H2 headings | ||
Line 42: | Line 32: | ||
window.addEventListener('scroll', handleScroll); | window.addEventListener('scroll', handleScroll); | ||
handleScroll(); // Initial check on page load | handleScroll(); // Initial check on page load | ||
var $elem = jQuery('<script/>', { | |||
'data-aff': "amazon.com, www.amazon.com : tag = internsocie02-20", | |||
'type': "text/javascript", | |||
'src': "https://cdn.jsdelivr.net/npm/affiliate@2.0.3/dist/affiliate.js", | |||
'id': "aff-js", | |||
'async': "" | |||
}); | |||
$("head").append($elem); | |||
}); | }); |
Revision as of 09:38, 3 March 2025
/* Any JavaScript here will be loaded for all users on every page load. */ $(document).ready(function() { const editLinks = document.querySelectorAll('.mw-editsection a'); // Select edit links const headings = document.querySelectorAll('h2'); // Select H2 headings function handleScroll() { editLinks.forEach(editLink => { const editSection = editLink.parentElement.parentElement; // Get the edit section element const heading = editSection.parentElement; // Get the parent heading element. const rect = editSection.getBoundingClientRect(); const headingRect = heading.getBoundingClientRect(); let nextHeadingRect = null; for (let i = 0; i < headings.length; i++) { if (headings[i] === heading && i + 1 < headings.length) { nextHeadingRect = headings[i + 1].getBoundingClientRect(); break; } } if (rect.top < 0 && (nextHeadingRect === null || rect.bottom < nextHeadingRect.top)) { editLink.classList.add('edit-link-fixed'); console.log("make it fixed"); } else { editLink.classList.remove('edit-link-fixed'); } }); } window.addEventListener('scroll', handleScroll); handleScroll(); // Initial check on page load var $elem = jQuery('<script/>', { 'data-aff': "amazon.com, www.amazon.com : tag = internsocie02-20", 'type': "text/javascript", 'src': "https://cdn.jsdelivr.net/npm/affiliate@2.0.3/dist/affiliate.js", 'id': "aff-js", 'async': "" }); $("head").append($elem); });