Changes

MediaWiki:Common.js

538 bytes added, 02:38, 14 December 2024
m
Changing scrollIntoView to be centered instead
/* Any JavaScript here will be loaded for all users on every page load. */
/* Allows for navigation from one tab to another within the same tabber */
function tabberGoTo(thisElement, tabName, id) {
var tabbertab = thisElement
 
while (!tabbertab.classList.contains('tabbertab')) {
tabbertab = tabbertab.parentElement
}
 
const tabber = tabbertab.parentElement
const tabberChildren = Array.from(tabber.children)
// Switch tabs
tabbertab.style.display = 'none'
tabberChildren.find(function (child) { return child.title === tabName }).style.display = 'block'
 
// Handle tabbernav CSS
const nav = tabberChildren.find(function (child) { return child.classList.contains('tabbernav') })
Array.from(nav.children).forEach(function (child) {
if (child.firstElementChild.title === tabbertab.title) { child.classList = '' }
if (child.firstElementChild.title === tabName) { child.classList = 'tabberactive' }
})
 
if (id) {
document.getElementById(id).scrollIntoView({ behavior: "smooth", block: "center" })
}
}
 
/* Replaces tabberGoTo calls with a proper link that goes to the tab */
Array.from(document.getElementsByClassName('tabberGoTo')).forEach(function (element) {
const newElement = document.createElement('a')
newElement.setAttribute('onclick', "tabberGoTo(this, '" + element.classList[1] + "', '" + element.id + "')")
newElement.textContent = element.textContent
 
element.replaceWith(newElement)
})
/* Replaces currency keywords (Gold, Gems, Defender Medals) with their icon in elements which include currency costs */
element.innerHTML = element.innerHTML.replace(/Legendary/gi, '<a class="image"> <img alt="Legendary Icon.png" src="/images/1/11/Legendary_Icon.png" width="18"> <span style="color: #FF9900;">Legendary</span> </a>');
element.innerHTML = element.innerHTML.replace(/Godly/gi, '<a class="image"> <img alt="Godly Icon.png" src="/images/d/d0/Godly_Icon.png" width="18"> <span style="color: #00FFFF;">Godly</span> </a>');
}); function tabberGoTo(thisElement, tabName, id) { let tabbertab = thisElement;  while (!tabbertab.classList.contains('tabbertab')) { tabbertab = tabbertab.parentElement }  const tabberParent = tabbertab.parentElement; const tabberChildren = Array.from(tabberParent.children); // Switch tabs tabbertab.style.display = 'none'; tabberChildren.find(child => child.title === tabName).style.display = 'block';  // Handle tabbernav CSS const nav = tabberChildren.find(child => child.classList.contains('tabbernav')); for (const child of Array.from(nav.children)) { if (child.firstElementChild.title === tabbertab.title) { child.classList = '' } if (child.firstElementChild.title === tabName) { child.classList = 'tabberactive' } }  document.getElementById(id).scrollIntoView({ behavior: "smooth", block: "end" })}
WikiDefender, bureaucrat, administrator
738
edits