MediaWiki:Gadget-dark-mode-toggle.js: Difference between revisions

Content deleted Content added
sync requested update from User:Nardog/dark-mode-toggle.js
Remove mw.uri
 
(11 intermediate revisions by 5 users not shown)
Line 34:
 
function vectorStickyCallback() {
makePortletLink('p-personal-sticky-header', 'pt-darkmode-sticky-header', '#pt-watchlist-sticky-header');
mw.hook('vector.page_title_scroll').remove(vectorStickyCallback);
if (document.getElementById('pt-darkmode-sticky-header')) return;
makePortletLink('p-personal-sticky-header', 'pt-darkmode-sticky-header', '#pt-watchlist-sticky-header');
}
 
Line 59 ⟶ 60:
toggleMode();
});
 
// Work around lack of icon in Vector 2022
if (mw.config.get('skin') === 'vector-2022') {
$('#' + portletId + ' span:only-child')
.before($('<span>').addClass('mw-ui-icon mw-ui-icon-vector-gadget-pt-darkmode'));
}
}
 
Line 73 ⟶ 68:
case 'vector-2022':
case 'minerva':
labelSelector = '#pt-darkmode span:not(.mw-ui-icon:empty), #pt-darkmode-sticky-header span:not(.mw-ui-icon:empty)';
break;
default:
Line 89 ⟶ 84:
var $gadgetsLink = $('link[rel="stylesheet"][href^="' + scriptPath + '?"][href*="ext.gadget."]');
if ($gadgetsLink.length) {
var uriurl = new mw.UriURL($gadgetsLink.prop('href'));
if (isOn) {
uriurl.querysearchParams.set('modules', url.searchParams.get('modules') += ',dark-mode');
} else {
if (uriurl.querysearchParams.get('modules') === 'ext.gadget.dark-mode') {
// dark-mode is the only module in this link
$gadgetsLink.remove();
return;
}
uriurl.querysearchParams.set('modules', = uriurl.querysearchParams.get('modules')
.replace('ext.gadget.dark-mode,', 'ext.gadget.') // dark-mode is first in the gadget list
.replace(/,dark-mode(,|$)/, '$1')); // dark-mode is in middle or end of the list
}
$gadgetsLink.prop('href', uriurl.getRelativePath()pathname + url.search);
} else {
// No gadget-containing styles are enabled
Line 157 ⟶ 152:
 
 
$.when($.ready, mw.loader.using(['mediawiki.util', 'mediawiki.api', 'mediawiki.Uri', 'mediawiki.storage'])).then(function () {
setHtmlClass();
setThemeColor();