MediaWiki:Common.js

From bg3.wiki
Revision as of 15:49, 18 April 2024 by Taylan (talk | contribs)
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */

/*
(function () {
	var notice = document.getElementById("bg3wiki-downtime-notice");
	if (notice && new Date().getMonth() + 1 == 9) {
		notice.style.display = 'block';
	}
})();
*/

// Show "up to date" notice on top-right of pages.
// See Template:Up_to_date
/*
(function () {
	if (document.getElementById("bg3wiki-legacy-content-notice")) {
		return;
	}
	var siteNotice = document.getElementById("siteNotice");
	if (!siteNotice) {
		return;
	}
    var uptodateNotice = document.getElementById("bg3wiki-uptodate-notice");
    if (uptodateNotice) {
    	siteNotice.style.float = "right";
    	siteNotice.innerHTML = uptodateNotice.innerHTML;
    	uptodateNotice.remove();
    	return;
    }
})();
*/

// Related to centering the content; fix for popups.
(function () {
	var body = document.getElementsByTagName("body")[0];
	var callback = function(mutList, _obs) {
		var nodes = mutList[0].addedNodes;
		if (nodes.length == 0 || nodes[0].classList == undefined) {
			return;
		}
		var node = nodes[0];
		if (node.classList.contains("mwe-popups")) {
			var bodyStyle = window.getComputedStyle(body);
			var bodyLeft = bodyStyle.getPropertyValue("margin-left");
			node.style.left = "calc("+ node.style.left + " - "+ bodyLeft + ")";
		}
	};
	var observer = new MutationObserver(callback);
	observer.observe(body, { childList: true });
})();

// Fancify the Discord link on the left-side panel
/*
(function() {
	var a = document.querySelector("#n-Discord > a");
	if (!a) return;
	
	var s = a.style;
	s.backgroundColor = "#5865f2";
	s.color = "white";
	s.fontWeight = "bold";
	s.display = "flex";
	s.alignItems = "center";
	s.width = "65%";
	s.borderRadius = "10px";
	s.marginLeft = "-8px";
	s.paddingLeft = "8px";
	s.paddingTop = "3px";
	s.paddingBottom = "2px";
	
	var logo = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
	a.insertBefore(logo, a.childNodes[0]);
	logo.setAttribute('viewBox', '0 0 34 34');
	logo.style.display = "inline";
	logo.style.width = "20px";
	logo.style.marginRight = "5px";
	
	var path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
	logo.appendChild(path);
	path.setAttribute('fill', '#fff');
	// Sorry about this monstrosity.
	path.setAttribute('d', 'M26.0015 6.9529C24.0021 6.03845 21.8787 5.37198 19.6623 5C19.3833 5.48048 19.0733 6.13144 18.8563 6.64292C16.4989 6.30193 14.1585 6.30193 11.8336 6.64292C11.6166 6.13144 11.2911 5.48048 11.0276 5C8.79575 5.37198 6.67235 6.03845 4.6869 6.9529C0.672601 12.8736 -0.41235 18.6548 0.130124 24.3585C2.79599 26.2959 5.36889 27.4739 7.89682 28.2489C8.51679 27.4119 9.07477 26.5129 9.55525 25.5675C8.64079 25.2265 7.77283 24.808 6.93587 24.312C7.15286 24.1571 7.36986 23.9866 7.57135 23.8161C12.6241 26.1255 18.0969 26.1255 23.0876 23.8161C23.3046 23.9866 23.5061 24.1571 23.7231 24.312C22.8861 24.808 22.0182 25.2265 21.1037 25.5675C21.5842 26.5129 22.1422 27.4119 22.7621 28.2489C25.2885 27.4739 27.8769 26.2959 30.5288 24.3585C31.1952 17.7559 29.4733 12.0212 26.0015 6.9529ZM10.2527 20.8402C8.73376 20.8402 7.49382 19.4608 7.49382 17.7714C7.49382 16.082 8.70276 14.7025 10.2527 14.7025C11.7871 14.7025 13.0425 16.082 13.0115 17.7714C13.0115 19.4608 11.7871 20.8402 10.2527 20.8402ZM20.4373 20.8402C18.9183 20.8402 17.6768 19.4608 17.6768 17.7714C17.6768 16.082 18.8873 14.7025 20.4373 14.7025C21.9717 14.7025 23.2271 16.082 23.1961 17.7714C23.1961 19.4608 21.9872 20.8402 20.4373 20.8402Z');
})();
*/

/**
 * Add support to mw-collapsible for autocollapse, innercollapse and outercollapse
 *
 * Maintainers: TheDJ. See https://en.wikipedia.org/wiki/MediaWiki:Common.js for more information.
 */
function mwCollapsibleSetup( $collapsibleContent ) {
	var $element,
		$toggle,
		autoCollapseThreshold = 2;
	$.each( $collapsibleContent, function ( index, element ) {
		$element = $( element );
		if ( $element.hasClass( 'collapsible' ) ) {
			$element.find( 'tr:first > th:first' ).prepend( $element.find( 'tr:first > * > .mw-collapsible-toggle' ) );
		}
		if ( $collapsibleContent.length >= autoCollapseThreshold && $element.hasClass( 'autocollapse' ) ) {
			$element.data( 'mw-collapsible' ).collapse();
		} else if ( $element.hasClass( 'innercollapse' ) ) {
			if ( $element.parents( '.outercollapse' ).length > 0 ) {
				$element.data( 'mw-collapsible' ).collapse();
			}
		}
		// because of colored backgrounds, style the link in the text color
		// to ensure accessible contrast
		$toggle = $element.find( '.mw-collapsible-toggle' );
		if ( $toggle.length ) {
			// Make the toggle inherit text color (Updated for T333357 2023-04-29)
			if ( $toggle.parent()[ 0 ].style.color ) {
				$toggle.css( 'color', 'inherit' );
				$toggle.find( '.mw-collapsible-text' ).css( 'color', 'inherit' );
			}
		}
	} );
}

mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup );