MediaWiki:Common.js: Difference between revisions
Appearance
Jemaleddin (talk | contribs) mNo edit summary |
Jemaleddin (talk | contribs) No edit summary |
||
| Line 9: | Line 9: | ||
}); | }); | ||
$("head").append($elem); | $("head").append($elem); | ||
}); | |||
document.addEventListener('DOMContentLoaded', 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'); | |||
} else { | |||
editLink.classList.remove('edit-link-fixed'); | |||
} | |||
}); | |||
} | |||
window.addEventListener('scroll', handleScroll); | |||
handleScroll(); // Initial check on page load | |||
}); | }); | ||
Revision as of 08:32, 3 March 2025
/* Any JavaScript here will be loaded for all users on every page load. */
$(document).ready(function() {
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);
});
document.addEventListener('DOMContentLoaded', 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');
} else {
editLink.classList.remove('edit-link-fixed');
}
});
}
window.addEventListener('scroll', handleScroll);
handleScroll(); // Initial check on page load
});