Ця сторінка повністю захищена, оскільки містить текст інтерфейсу цієї вікі.

MediaWiki:Gadget-fixedWidthToggle.js

Матеріал з Minecraft Wiki
Перейти до навігації Перейти до пошуку
Іншими мовами

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

Google Chrome, Firefox, Microsoft Edge, and Safari: Hold down the Shift key and click the Reload toolbar button.
For details and instructions about other browsers, see Wikipedia:Bypass your cache.

$(function() {
	var isDefaultEnabled = mw.user.options.get('gadget-fixedWidth'),
	cookieOptions = {
		prefix: '',
		expires: 365 * 86400
	},
	portletLink = mw.util.addPortletLink(
		'p-personal',
		'',
		'',
		( isDefaultEnabled ? 'pt-fw-disable' : 'pt-fw-enable' ),
		'Перемикач фіксованої ширини',
		null,
		$('#pt-dm-toggle, #pt-userpage, #pt-anonuserpage, #pt-createaccount')[0]
	);
	
	if ( mw.user.isAnon() ) {
		var useFixedWidth = mw.cookie.get('fixedWidth', cookieOptions.prefix, isDefaultEnabled && 'true') === 'true';
		if ( useFixedWidth != isDefaultEnabled ) { // bool != int
			toggleFixedWidth(isDefaultEnabled);
		}
	}
	
	$(portletLink).find('a').click(function(e) {
		e.preventDefault();
		
		var isEnabled = mw.user.options.get('gadget-fixedWidth');
		if ( mw.user.isAnon() ) {
			mw.cookie.set('fixedWidth', isEnabled ? 'false' : 'true', cookieOptions);
		}
		else {
			new mw.Api().saveOption('gadget-fixedWidth', isEnabled ? 0 : 1).fail(function() {
				mw.notify('Не вдалося зберегти налаштування фіксованої ширини.', {
					title: 'Перемикач фіксованої ширини',
					type: 'warn',
					tag: 'fixedWidthToggle'
				});
			});
		}
		toggleFixedWidth(isEnabled);
	});
	
	function toggleFixedWidth(isEnabled) {
		if ( isEnabled ) {
			mw.user.options.set('gadget-fixedWidth', 0);
			document.documentElement.style.setProperty('--fixed-width', '100vw');
			portletLink.id = 'pt-fw-enable';
		}
		else {
			mw.user.options.set('gadget-fixedWidth', 1);
			document.documentElement.style.setProperty('--fixed-width', '');
			mw.loader.using(['ext.gadget.fixedWidth']).then(function() {
				portletLink.id = 'pt-fw-disable';
			});
		}
	}
});