MediaWiki:Vector.js: Difference between revisions
Jump to navigation
Jump to search
Created page with "→All JavaScript here will be loaded for users of the Vector skin: →*************************: →Interface Modification *: →*************************: →JavaScript Load Class (REQUIRED BY DEFAULT VECTOR.CSS): $(function () { document.body.classList.add('has-vector-mobile-menu'); }); →Search Toggle Button: $(function () { var buttonClass = 'button-toggle button-toggle-search'; var expandedClass = 'search--expanded'; let searchButton = document.crea..." |
No edit summary |
||
| Line 10: | Line 10: | ||
}); | }); | ||
/* Adapt standard Vector's structure for the imported stylesheet. */ | |||
$(function () { | |||
if (!document.body.classList.contains('skin-vector-legacy')) return; | |||
var content = document.getElementById('content'); | |||
var navigation = document.getElementById('mw-navigation'); | |||
if (!content || !navigation) return; | |||
if (!content.parentElement.classList.contains('content-wrapper')) { | |||
var wrapper = document.createElement('div'); | |||
wrapper.className = 'content-wrapper'; | |||
content.before(wrapper); | |||
wrapper.append(navigation, content); | |||
} | |||
if (!content.querySelector('.content-body')) { | |||
$(content).wrapInner('<div class="content-body"></div>'); | |||
} | |||
}); | |||
/* Search Toggle Button */ | /* Search Toggle Button */ | ||
Revision as of 23:43, 9 October 2026
/* All JavaScript here will be loaded for users of the Vector skin */
/***************************/
/* Interface Modification **/
/***************************/
/* JavaScript Load Class (REQUIRED BY DEFAULT VECTOR.CSS) */
$(function () {
document.body.classList.add('has-vector-mobile-menu');
});
/* Adapt standard Vector's structure for the imported stylesheet. */
$(function () {
if (!document.body.classList.contains('skin-vector-legacy')) return;
var content = document.getElementById('content');
var navigation = document.getElementById('mw-navigation');
if (!content || !navigation) return;
if (!content.parentElement.classList.contains('content-wrapper')) {
var wrapper = document.createElement('div');
wrapper.className = 'content-wrapper';
content.before(wrapper);
wrapper.append(navigation, content);
}
if (!content.querySelector('.content-body')) {
$(content).wrapInner('<div class="content-body"></div>');
}
});
/* Search Toggle Button */
$(function () {
var buttonClass = 'button-toggle button-toggle-search';
var expandedClass = 'search--expanded';
let searchButton = document.createElement('button');
let sidebar = document.getElementById('mw-navigation');
searchButton.className = buttonClass;
searchButton.addEventListener('click', function () {
searchButton.classList.toggle(expandedClass);
sidebar.classList.toggle(expandedClass);
});
sidebar.prepend(searchButton);
});
/* Mobile Sidebar Toggle Button */
$(function () {
var buttonClass = 'button-toggle button-toggle-sidebar-mobile';
var expandedClass = 'sidebar-mobile--expanded';
let mobileSidebarButton = document.createElement('button');
let sidebar = document.getElementById('mw-navigation');
mobileSidebarButton.className = buttonClass;
mobileSidebarButton.addEventListener('click', function () {
mobileSidebarButton.classList.toggle(expandedClass);
sidebar.classList.toggle(expandedClass);
});
sidebar.prepend(mobileSidebarButton);
});
/* Sidebar Toggle Button */
$(function () {
var buttonClass = 'button-toggle button-toggle-sidebar';
var expandedClass = 'sidebar--collapsed';
let sidebarButton = document.createElement('button');
let sidebar = document.getElementById('mw-navigation');
sidebarButton.className = buttonClass;
sidebarButton.addEventListener('click', function () {
sidebarButton.classList.toggle(expandedClass);
sidebar.classList.toggle(expandedClass);
});
sidebar.prepend(sidebarButton);
});
/* Sidebar Box Content Collaspible Toggles */
$(function() {
// configure sections (by header string) to initially collapse for all users by default
var initiallyCollapsedIDs = []; /* e.g. ['Character_Classes', 'Items', 'External_Links'] */
// add the p- onto ids for ease of use, if not present
initiallyCollapsedIDs.forEach(function(id, index) {
if(!id.startsWith('p-')) {initiallyCollapsedIDs[index] = 'p-' + id;}
});
var $portals = $("#mw-panel .vector-menu-portal");
var setup = function() {
$portals.each(function(index, el) {
if(window.innerWidth < 721) {return;}
var $el = $(el);
var $id = $el.attr("id");
if(!$id) {return;}
// check if this portal should be collapsed - portal is set to be initially collapsed and user has not indicated wanting it open || user has indicated wanting this portal collapsed
if(
(initiallyCollapsedIDs.includes($id) && localStorage.getItem('sidebar_c_'+$id) != "n") || (localStorage.getItem('sidebar_c_'+$id) === "y")
) {$el.addClass('collapsed').find('.vector-menu-content').slideUp(0);}
});
};
setup();
$(window).on('resize', setup);
$portals.on("click", "h3", function(event) {
if(window.innerWidth < 721) {return;}
var $el = $(this).parent();
var $id = $el.attr("id");
if(!$id) {return;}
$el.toggleClass('collapsed');
if($el.hasClass('collapsed')) { // more consistent between class and slide status
localStorage.setItem('sidebar_c_'+$id, "y");
$el.find('.vector-menu-content').slideUp('fast');
}
else {
localStorage.setItem('sidebar_c_'+$id, "n");
$el.find('.vector-menu-content').slideDown('fast');
}
});
});
/* Header Dropdown Menu Purge Cache Link */
$(function() {
if (mw.config.get('wgNamespaceNumber') === -1 ) {return;} // disable on special pages
var url = new URL(window.location.href);
url.searchParams.set('action', 'purge');
var button = mw.util.addPortletLink('p-cactions', url.href, 'Purge cache', 'ca-gadget-purgecache', 'Purge the server cache for this page', '1');
button.addEventListener('click', (function(event) {
event.preventDefault();
var api = new mw.Api();
api.post({
action: 'purge',
titles: mw.config.get('wgPageName'),
forcerecursivelinkupdate: true
}).then(function() {
window.location.reload(true);
}).fail(function(code) {
mw.notify('Page purge unsuccessful. Error code: $1'.replace('$1', code));
});
}));
console.log('purge loaded');
});