Anonymous edits have been disabled on the wiki. If you want to contribute please login or create an account.

Difference between revisions of "MediaWiki:Common.js"

From PCGamingWiki, the wiki about fixing PC games
(added system requirements tab handling)
(Change display for tabs from block to inline-block.)
Line 11: Line 11:
  
 
             // Make tab nav visible
 
             // Make tab nav visible
             $('#tabNav').css('display', 'block');
+
             $('#tabNav').css('display', 'inline-block');
  
 
             // hide sysreq table headings
 
             // hide sysreq table headings

Revision as of 03:05, 18 January 2019

function sysreqTabs() {

    // run tab code only if tabNav exists
    if ($('#tabNav')[0]) {

        // store the number of sysreq tables
        var sysreqcount = $('.sysreq').length

        // run tab code only if there are at least two sysreq tables
        if (sysreqcount > 1) {

            // Make tab nav visible
            $('#tabNav').css('display', 'inline-block');

            // hide sysreq table headings
            $('.sysreq_heading').css('display', 'none');

            // remove tabs for missing tables (if not already removed by the template)
            $('.sysreq_Booter')[0] || $('#sysreq_Booter').remove();
            $('.sysreq_DOS')[0] || $('#sysreq_DOS').remove();
            $('.sysreq_Windows')[0] || $('#sysreq_Windows').remove();
            $('.sysreq_Mac_OS')[0] || $('#sysreq_Mac_OS').remove();
            $('.sysreq_OS_X')[0] || $('#sysreq_OS_X').remove();
            $('.sysreq_Linux')[0] || $('#sysreq_Linux').remove();

            // find first tab and apply style
            var firstTab = document.querySelector('.sysreqTab:first-child');
            $(firstTab).addClass('selectedTab');

            // ensure table matching first tab is visible (in case page order does not match OS order expected by tab template)
            $('.sysreq').css('display', 'none');
            $('.' + $(firstTab).attr('id')).css('display', 'block');

            // apply table visibility and tab style changes when tabs are clicked
            $('.sysreqTab').click(function() {
                $('.sysreqTab').removeClass('selectedTab');
                $(this).addClass('selectedTab');
                $('.sysreq').css('display', 'none');
                $('.' + $(this).attr('id')).css('display', 'block');
            })

        // remove tabs table if there are fewer than two sysreq tables
        } else {
            $('#tabNav').remove();
        }
    }
}

$(sysreqTabs);


var customizeToolbar = function() {
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		sections: {
			'templates': {
				type: 'toolbar',
				label: 'Templates',
				groups: {
					templates: {
						'label': 'Templates',
						'tools': {
							'availabilityrow': {
								label: 'Availability row',
								type: 'button',
								icon: '//pcgamingwiki.com/images/6/67/Editor_Icon_-_Availability_Table_Row.svg',
								action: {
									type: 'encapsulate',
									options: {
										pre: "{{Availability/row| ",
										peri: "store",
										post: " | id | DRM | notes | Key | OS }}",
										ownline: true
									}
								}
							},
							'dlc': {
								label: 'DLC',
								type: 'button',
								icon: '//pcgamingwiki.com/images/3/38/Editor_Icon_-_DLCtable.svg',
								action: {
									type: 'encapsulate',
									options: {
										pre: "{{DLC|\n",
										peri: "{{DLC/row| Name | notes | OS }}",
										post: "\n}}",
										ownline: true
									}
								}
							},
							'dlcrow': {
								label: 'DLC Row',
								type: 'button',
								icon: '//pcgamingwiki.com/images/9/9f/Editor_Icon_-_DLCrow.svg',
								action: {
									type: 'encapsulate',
									options: {
										pre: "{{DLC/row| ",
										peri: "Name",
										post: " | notes | OS }}",
										ownline: true
									}
								}
							},
							'gamedataconfig': {
								label: 'Game data row - config',
								type: 'button',
								icon: '//pcgamingwiki.com/images/0/0c/Editor_Icon_-_Game_Data_Row.svg',
								action: {
									type: 'encapsulate',
									options: {
										pre: "{{Game data/config|",
										peri: "System",
										post: "|Path}}",
										ownline: true
									}
								}
							},
							'gamedatasaves': {
								label: 'Game data row - saves',
								type: 'button',
								icon: '//pcgamingwiki.com/images/0/0c/Editor_Icon_-_Game_Data_Row.svg',
								action: {
									type: 'encapsulate',
									options: {
										pre: "{{Game data/saves|",
										peri: "System",
										post: "|Path}}",
										ownline: true
									}
								}
							},
							'cloud': {
								label: 'Cloud syncing',
								type: 'button',
								icon: '//pcgamingwiki.com/images/b/bc/Editor_Icon_-_Cloud_Sync.svg',
								action: {
									type: 'encapsulate',
									options: {
										pre: "===[[Glossary:Save game cloud syncing|Save game cloud syncing]]===\n{{Save game cloud syncing\n|gog galaxy            = \n|gog galaxy notes      = \n|origin                = \n|origin notes          = \n|steam cloud           = \n|steam cloud notes     = \n|uplay                 = \n|uplay notes           = \n|xbox cloud            = \n|xbox cloud notes      = \n}}",
										ownline: true
									}
								}
							},
							'sysreq': {
								label: 'System requirements',
								type: 'button',
								icon: '//pcgamingwiki.com/images/4/4b/Editor_Icon_-_System_Requirements.svg',
								action: {
									type: 'encapsulate',
									options: {
										pre: "{{System requirements\n|OSfamily = ",
										peri: "System",
										post: "\n|minOS    = \n|minCPU   = \n|minRAM   = \n|minHD    = \n|minGPU   = \n\n|recOS    = \n|recCPU   = \n|recRAM   = \n|recHD    = \n|recGPU   = \n}}",
										ownline: true
									}
								}
							},
							'fixbox': {
								label: 'Fixbox',
								type: 'button',
								icon: '//pcgamingwiki.com/images/d/d8/Editor_Icon_-_Fixbox.svg',
								action: {
									type: 'encapsulate',
									options: {
										pre: "{{Fixbox|description=",
										peri: "Name",
										post: "|ref=<ref>Reference</ref>|fix=\n}}",
										ownline: true
									}
								}
							},
							'lang': {
								label: 'Language',
								type: 'button',
								icon: '//pcgamingwiki.com/images/2/22/Editor_Icon_-_Localizations.svg',
								action: {
									type: 'encapsulate',
									options: {
										pre: "{{L10n/switch\n |language  = \n",
										post: " |interface = yes\n |audio     = \n |subtitles = \n |notes     = \n |fan       = \n}}",
										ownline: true
									}
								}
							},
							'vrtable': {
								label: 'VR',
								type: 'button',
								icon: '//pcgamingwiki.com/images/3/3c/Editor_Icon_-_VR.svg',
								action: {
									type: 'encapsulate',
									options: {
										pre: "==VR support==\n{{VR support\n|gg3d name                   = \n|native 3d gg3d award        = \n|nvidia 3d vision gg3d award = \n|tridef 3d gg3d award        = \n|iz3d gg3d award             = \n|native 3d                   = \n|native 3d notes             = \n|nvidia 3d vision            = \n|nvidia 3d vision notes      = \n|tridef 3d                   = \n|tridef 3d notes             = \n|iz3d                        = \n|iz3d notes                  = \n|htc vive                    = \n|htc vive notes              = \n|oculus rift                 = \n|oculus rift notes           = \n|osvr                        = \n|osvr notes                  = \n|windows mixed reality       = \n|windows mixed reality notes = \n|keyboard-mouse              = \n|keyboard-mouse notes        = \n|3rd space gaming vest       = \n|3rd space gaming vest notes = \n|novint falcon               = \n|novint falcon notes         = \n|trackir                     = \n|trackir notes               = \n|tobii eye tracking          = \n|tobii eye tracking notes    = \n|play area seated            = \n|play area seated notes      = \n|play area standing          = \n|play area standing notes    = \n|play area room-scale        = \n|play area room-scale notes  = \n}}",
										ownline: true
									}
								}
							},
							'apitable': {
								label: 'API',
								type: 'button',
								icon: '//pcgamingwiki.com/images/c/cb/Editor_Icon_-_API.svg',
								action: {
									type: 'encapsulate',
									options: {
										pre: "===API===\n{{API\n|direct3d versions      = \n|direct3d notes         = \n|directdraw versions    = \n|directdraw notes       = \n|opengl versions        = \n|opengl notes           = \n|glide versions         = \n|glide notes            = \n|software mode          = \n|software mode notes    = \n|mantle support         = \n|mantle support notes   = \n|metal support          = \n|metal support notes    = \n|vulkan support         = \n|vulkan support notes   = \n|dos modes              = \n|dos modes notes        = \n|shader model versions  = \n|shader model notes     = \n|64-bit executable      = \n|64-bit executable notes= \n}}",
										ownline: true
									}
								}
							},
							'middlewaretable': {
								label: 'Middleware',
								type: 'button',
								icon: '//pcgamingwiki.com/images/c/c2/Editor_Icon_-_Middleware.svg',
								action: {
									type: 'encapsulate',
									options: {
										pre: "===Middleware===\n{{Middleware\n|physics          = \n|physics notes    = \n|audio            = \n|audio notes      = \n|interface        = \n|interface notes  = \n|input            = \n|input notes      = \n|cutscenes        = \n|cutscenes notes  = \n|multiplayer      = \n|multiplayer notes= \n}}",
										ownline: true
									}
								}
							},
							'seesection': {
								label: 'See...',
								type: 'select',
								list: {
									'widescreen': {
										label: 'Widescreen resolution',
										action: {
											type: 'encapsulate',
											options: {
												pre: "See [[#Widescreen resolution|Widescreen resolution]]."
											}
										}
									},
									'multimonitor': {
										label: 'Multi-monitor',
										action: {
											type: 'encapsulate',
											options: {
												pre: "See [[#Multi-monitor|Multi-monitor]]."
											}
										}
									},
									'ultrawidescreen': {
										label: 'Ultra-widescreen',
										action: {
											type: 'encapsulate',
											options: {
												pre: "See [[#Ultra-widescreen|Ultra-widescreen]]."
											}
										}
									},
									'4kultrahd': {
										label: '4K Ultra HD',
										action: {
											type: 'encapsulate',
											options: {
												pre: "See [[#4K Ultra HD|4K Ultra HD]]."
											}
										}
									},
									'fieldofview': {
										label: 'Field of view (FOV)',
										action: {
											type: 'encapsulate',
											options: {
												pre: "See [[#Field of view (FOV)|Field of view (FOV)]]."
											}
										}
									},
									'windowed': {
										label: 'Windowed',
										action: {
											type: 'encapsulate',
											options: {
												pre: "See [[#Windowed|Windowed]]."
											}
										}
									},
									'borderless': {
										label: 'Borderless fullscreen windowed',
										action: {
											type: 'encapsulate',
											options: {
												pre: "See [[#Borderless fullscreen windowed|Borderless fullscreen windowed]]."
											}
										}
									},
									'anisotropic': {
										label: 'Anisotropic filtering (AF)',
										action: {
											type: 'encapsulate',
											options: {
												pre: "See [[#Anisotropic filtering (AF)|Anisotropic filtering (AF)]]."
											}
										}
									},
									'antialiasing': {
										label: 'Anti-aliasing (AA)',
										action: {
											type: 'encapsulate',
											options: {
												pre: "See [[#Anti-aliasing (AA)|Anti-aliasing (AA)]]."
											}
										}
									},
									'vsync': {
										label: 'Vertical sync (Vsync)',
										action: {
											type: 'encapsulate',
											options: {
												pre: "See [[#Vertical sync (Vsync)|Vertical sync (Vsync)]]."
											}
										}
									},
									'oculus': {
										label: 'Oculus Rift',
										action: {
											type: 'encapsulate',
											options: {
												pre: "See [[#Oculus Rift|Oculus Rift]]."
											}
										}
									},
									'highframe': {
										label: 'High frame rate',
										action: {
											type: 'encapsulate',
											options: {
												pre: "See [[#High frame rate|High frame rate]]. "
											}
										}
									},
									'colorblind': {
										label: 'Color blind mode',
										action: {
											type: 'encapsulate',
											options: {
												pre: "See [[#Color blind mode|Color blind mode]]."
											}
										}
									},
									'remapping': {
										label: 'Remapping',
										action: {
											type: 'encapsulate',
											options: {
												pre: "See [[#Remapping|Remapping]]."
											}
										}
									},
									'mouseaccel': {
										label: 'Mouse acceleration',
										action: {
											type: 'encapsulate',
											options: {
												pre: "See [[#Mouse acceleration|Mouse acceleration]]."
											}
										}
									},
									'controllersupport': {
										label: 'Controller support',
										action: {
											type: 'encapsulate',
											options: {
												pre: "See [[#Controller support|Controller support]]."
											}
										}
									},
									'controllerremap': {
										label: 'Controller remapping',
										action: {
											type: 'encapsulate',
											options: {
												pre: "See [[#Controller remapping|Controller remapping]]."
											}
										}
									},
									'touchscreen': {
										label: 'Touchscreen optimised',
										action: {
											type: 'encapsulate',
											options: {
												pre: "See [[#Touchscreen|Touchscreen]]."
											}
										}
									}
								}
							},
							'infoboxdrop': {
								label: 'Infobox row',
								type: 'select',
								list: {
									'infoboxdeveloper': {
										label: 'Developer',
										action: {
											type: 'encapsulate',
											options: {
												pre: "{{Infobox game/row/developer|",
												post: "}}",
												ownline: true
											}
										}
									},
									'infoboxporter': {
										label: 'Porter',
										action: {
											type: 'encapsulate',
											options: {
												pre: "{{Infobox game/row/porter|",
												post: "|OS}}",
												ownline: true
											}
										}
									},
									'infoboxpublisher': {
										label: 'Publisher',
										action: {
											type: 'encapsulate',
											options: {
												pre: "{{Infobox game/row/publisher|",
												post: "}}",
												ownline: true
											}
										}
									},
									'infoboxengine': {
										label: 'Engine',
										action: {
											type: 'encapsulate',
											options: {
												pre: "{{Infobox game/row/engine|",
												post: "}}",
												ownline: true
											}
										}
									},
									'infoboxdatewindows': {
										label: 'Windows release date',
										action: {
											type: 'encapsulate',
											options: {
												pre: "{{Infobox game/row/date|Windows|",
												peri: "Month dd, yyyy",
												post: "}}",
												ownline: true
											}
										}
									},
									'infoboxdateosx': {
										label: 'OS X release date',
										action: {
											type: 'encapsulate',
											options: {
												pre: "{{Infobox game/row/date|OS X|",
												peri: "Month dd, yyyy",
												post: "}}",
												ownline: true
											}
										}
									},
									'infoboxdatelinux': {
										label: 'Linux release date',
										action: {
											type: 'encapsulate',
											options: {
												pre: "{{Infobox game/row/date|Linux|",
												peri: "Month dd, yyyy",
												post: "}}",
												ownline: true
											}
										}
									}
								}
							},
							'filepath': {
								label: 'Path',
								type: 'select',
								list: {
									'pathgame': {
										label: 'Path to game',
										action: {
											type: 'encapsulate',
											options: {
												pre: "{{P|game}}"
											}
										}
									},
									'pathuid': {
										label: 'User ID',
										action: {
											type: 'encapsulate',
											options: {
												pre: "{{P|uid}}"
											}
										}
									},
									'pathhkcu': {
										label: 'HKEY_CURRENT_USER',
										action: {
											type: 'encapsulate',
											options: {
												pre: "{{P|hkcu}}"
											}
										}
									},
									'pathhklm': {
										label: 'HKEY_LOCAL_MACHINE',
										action: {
											type: 'encapsulate',
											options: {
												pre: "{{P|hklm}}"
											}
										}
									},
                                                                        'pathwow64': {
										label: 'Wow6432Node',
										action: {
											type: 'encapsulate',
											options: {
												pre: "{{P|wow64}}"
											}
										}
									},
									'pathuserprofile': {
										label: '%USERPROFILE%',
										action: {
											type: 'encapsulate',
											options: {
												pre: "{{P|userprofile}}"
											}
										}
									},
									'pathappdata': {
										label: '%APPDATA%',
										action: {
											type: 'encapsulate',
											options: {
												pre: "{{P|appdata}}"
											}
										}
									},
									'pathlocalappdata': {
										label: '%LOCALAPPDATA%',
										action: {
											type: 'encapsulate',
											options: {
												pre: "{{P|localappdata}}"
											}
										}
									},
									'pathpublic': {
										label: '%PUBLIC%',
										action: {
											type: 'encapsulate',
											options: {
												pre: "{{P|public}}"
											}
										}
									},
									'pathprogramdata': {
										label: '%PROGRAMDATA%',
										action: {
											type: 'encapsulate',
											options: {
												pre: "{{P|programdata}}"
											}
										}
									},
									'pathwindir': {
										label: '%WINDIR%',
										action: {
											type: 'encapsulate',
											options: {
												pre: "{{P|windir}}"
											}
										}
									},
									'pathsteam': {
										label: 'Steam folder',
										action: {
											type: 'encapsulate',
											options: {
												pre: "{{P|steam}}"
											}
										}
									},
									'pathuplay': {
										label: 'Uplay folder',
										action: {
											type: 'encapsulate',
											options: {
												pre: "{{P|uplay}}"
											}
										}
									},
									'pathosxhome': {
										label: 'OS X Home folder',
										action: {
											type: 'encapsulate',
											options: {
												pre: "{{P|osxhome}}"
											}
										}
									},
									'pathlinuxhome': {
										label: 'Linux Home folder',
										action: {
											type: 'encapsulate',
											options: {
												pre: "{{P|linuxhome}}"
											}
										}
									},
									'pathlinuxxdgdatahome': {
										label: 'Linux XDG data home',
										action: {
											type: 'encapsulate',
											options: {
												pre: "{{P|xdgdatahome}}"
											}
										}
									},
									'pathxdgconfighome': {
										label: 'Linux XDG config home',
										action: {
											type: 'encapsulate',
											options: {
												pre: "{{P|xdgconfighome}}"
											}
										}
									},
								}
							},
							'reftemplates': {
								label: 'Reference templates',
								type: 'select',
								list: {
									'pathgame': {
										label: 'Checked by user',
										action: {
											type: 'encapsulate',
											options: {
												pre: "<ref>{{Refcheck|user=User|date=2012-12-21|comment=Comment (optional)}}</ref>"
											}
										}
									},
									'pathuid': {
										label: 'URL',
										action: {
											type: 'encapsulate',
											options: {
												pre: "<ref>{{Refurl|url=|title=|date=}}</ref>"
											}
										}
									},
									'pathhkcu': {
										label: 'Snippet from URL',
										action: {
											type: 'encapsulate',
											options: {
												pre: "<ref>{{Refsnip|url=|title=|date=|snippet=}}</ref>"
											}
										}
									},
								}
							}
						}
					}
				}
			}
		}
	} );
};
 
/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar . . . */
if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -1 ) {
	mw.loader.using( 'user.options', function () {
		// This can be the string "0" if the user disabled the preference ([[bugzilla:52542#c3]])
		if ( mw.user.options.get( 'usebetatoolbar' ) == 1 && mw.user.options.get( 'showtoolbar' ) == 1 ) {
			$.when(
				mw.loader.using( 'ext.wikiEditor.toolbar' ),
				$.ready
			).then( customizeToolbar );
		}
	} );
}

function addAnchorInHeaders() {
	$('span.mw-headline', '#mw-content-text').each(function() {
		var $this = $(this);
		if ($this.attr('id') !== undefined) {
			$('<span class="mw-linkhere"></span>').text(' • ').append(
				$('<a></a>').text('Link').attr({title: 'Link', href: '#'+$this.attr('id')})
			).appendTo(this);
		}
	});
}

$(addAnchorInHeaders);

/* ===== FUNCTIONALITY : Adds ReferenceTooltips =========================================================================================================================
 * 
 * Adds ReferenceTooltips copied directly over from the Russian Wikipedia.
 * 
 * Information: https://www.mediawiki.org/w/index.php?title=Topic:Ueqlcc482l9yw8gv&topic_showPostId=ueqlcc6fkvg15qzj#flow-post-ueqlcc6fkvg15qzj
 * 
 * Source Code:
 *  - Javascript : https://ru.wikipedia.org/wiki/MediaWiki:Gadget-referenceTooltips.js
 *  - CSS : https://ru.wikipedia.org/wiki/MediaWiki:Gadget-referenceTooltips.css
 * 
 * 2018-09-17 - Updated + added english text (Google Translated)
 *
 */

// See [[mw:Reference Tooltips]]

( function () {

// ruwiki settings
var REF_LINK_SELECTOR = '.reference, a[href^="#CITEREF"]',
	COMMENTED_TEXT_CLASS = 'ts-comment-commentedText',
	COMMENTED_TEXT_SELECTOR = '.' + COMMENTED_TEXT_CLASS + ', abbr[title]';

mw.messages.set( {
	'rt-settings': 'Tooltip settings', // hover alt text on the cog wheel shown on the tooltips.
	'rt-settings-title': 'Reference Tooltips settings',
	'rt-save': 'Save settings',
	'rt-cancel': 'Cancel',
	'rt-enable': 'Enable Reference Tooltips',
	'rt-disable': 'Disable Reference Tooltips',
	'rt-activationMethod': 'Tooltip is activated by:',
	'rt-hovering': 'hovering',
	'rt-clicking': 'clicking',
	'rt-delay': 'Delay before the tooltip appears (in milliseconds):',
	'rt-tooltipsForComments': 'Show tooltips over <span title="Tooltip example" class="'+ COMMENTED_TEXT_CLASS +'" style="border-bottom: 1px dotted; cursor: help;">underlined text</span> in the style of Reference Tooltips (allows you to see tooltips on devices without mouse support).',
	'rt-disabledNote': 'Once disabled, Reference Tooltips can be re-enabled using a link in the footer of the page.',
	'rt-ready': 'Done',
	'rt-enable-footer': 'Enable Reference Tooltips', // Text as shown in the footer among the category links
	'rt-enabled': 'Reference Tooltips have been enabled.' // Shown on the popup in the top right corner when re-enabling Reference Tooltips from the footer.
} );

// "Global" variables
var SECONDS_IN_A_DAY = 60 * 60 * 24,
	CLASSES = {
		FADE_IN_DOWN: 'rt-fade-in-down',
		FADE_IN_UP: 'rt-fade-in-up',
		FADE_OUT_DOWN: 'rt-fade-out-down',
		FADE_OUT_UP: 'rt-fade-out-up'
	},
	IS_TOUCHSCREEN = 'ontouchstart' in document.documentElement,
	// Quite a rough check for mobile browsers, a mix of what is advised at
	// https://stackoverflow.com/a/24600597 (sends to
	// https://developer.mozilla.org/en-US/docs/Browser_detection_using_the_user_agent)
	// and https://stackoverflow.com/a/14301832
	IS_MOBILE = /Mobi|Android/i.test( navigator.userAgent ) ||
		typeof window.orientation !== 'undefined',
	CLIENT_NAME = $.client.profile().name,
	settingsString, settings, enabled, delay, activatedByClick, tooltipsForComments, cursorWaitCss,
	windowManager,
	$body = $( document.body ),
	$window = $( window );

function rt( $content ) {
	// Popups gadget
	if ( window.pg ) {
		return;
	}

	var teSelector,
		settingsDialogOpening = false;

	function setSettingsCookie() {
		mw.cookie.set(
			'RTsettings',
			Number( enabled ) + '|' + delay + '|' + Number( activatedByClick ) + '|' +
				Number( tooltipsForComments ),
			{ path: '/', expires: 90 * SECONDS_IN_A_DAY }
		);
	}

	function enableRt() {
		enabled = true;
		setSettingsCookie();
		$( '.rt-enableItem' ).remove();
		rt( $content );
		mw.notify( mw.msg( 'rt-enabled' ) );
	}

	function disableRt() {
		$content.find( teSelector ).removeClass( 'rt-commentedText' ).off( '.rt' );
		$body.off( '.rt' );
		$window.off( '.rt' );
	}

	function addEnableLink() {
		// #footer-places – Vector
		// #f-list – Timeless, Monobook, Modern
		// parent of #footer li – Cologne Blue
		//var $footer = $( '#footer-places, #f-list' );
		var $footer = $( '#mw-normal-catlinks ul' );
		if ( !$footer.length ) {
			$footer = $( '#footer li' ).parent();
		}
		$footer.append(
			$( '<li>' )
				.addClass( 'rt-enableItem' )
				.append(
					$( '<a>' )
						.text( mw.msg( 'rt-enable-footer' ) )
						.attr( 'href', 'javascript:' )
						.click( function ( e ) {
							e.preventDefault();
							enableRt();
						} )
			)
		);
	}

	function TooltippedElement( $element ) {
		var tooltip,
			te = this;

		function onStartEvent( e ) {
			if ( activatedByClick ) {
				e.preventDefault();
			}
			if ( !te.noRef ) {
				te.showRef( $( this ) );
			}
		}

		function onEndEvent() {
			if ( !te.noRef ) {
				te.hideRef();
			}
		}

		if ( !$element ) {
			return;
		}

		// TooltippedElement.$element and TooltippedElement.$originalElement will be different when
		// the first is changed after its cloned version is hovered in a tooltip
		this.$element = $element;
		this.$originalElement = $element;
		if ( this.$element.is( REF_LINK_SELECTOR ) ) {
			if ( this.$element.prop( 'tagName' ) === 'SUP' ) {
				this.type = 'supRef';
			} else {
				this.type = 'harvardRef';
			}
		} else {
			this.type = 'commentedText';
			this.comment = this.$element.attr( 'title' );
			if ( !this.comment ) {
				return;
			}
			this.$element.addClass('rt-commentedText');
		}

		this.$element.on( activatedByClick ?
			{ 'click.rt': onStartEvent } :
			{ 'mouseenter.rt': onStartEvent, 'mouseleave.rt': onEndEvent }
		);

		this.hideRef = function ( immediately ) {
			clearTimeout( te.showTimer );

			if ( this.type === 'commentedText' ) {
				this.$element.attr( 'title', this.comment );
			}

			if ( this.tooltip && this.tooltip.isPresent ) {
				if ( activatedByClick || immediately ) {
					this.tooltip.hide();
				} else {
					this.hideTimer = setTimeout( function () {
						te.tooltip.hide();
					}, 200 );
				}
			} else if ( this.$ref && this.$ref.hasClass( 'rt-target' ) ) {
				this.$ref.removeClass( 'rt-target' );
				if ( activatedByClick ) {
					$body.off( 'click.rt touchstart.rt', this.onBodyClick );
				}
			}
		};

		this.showRef = function ( $element ) {
			// Popups gadget
			if ( window.pg ) {
				disableRt();
				return;
			}

			var tooltipInitiallyPresent = this.tooltip && this.tooltip.isPresent;

			function reallyShow() {
				var viewportTop, refOffsetTop, teHref;

				if ( !te.$ref && !te.comment ) {
					teHref = te.type === 'supRef' ?
						te.$element.find( 'a' ).attr( 'href' ) :
						te.$element.attr( 'href' ); // harvardRef
					te.$ref = teHref &&
						$( '#' + $.escapeSelector( teHref.slice( 1 ) ) );
					if ( !te.$ref || !te.$ref.length || !te.$ref.text() ) {
						te.noRef = true;
						return;
					}
				}

				if ( !tooltipInitiallyPresent && !te.comment ) {
					viewportTop = $window.scrollTop();
					refOffsetTop = te.$ref.offset().top;
					if ( !activatedByClick &&
						viewportTop < refOffsetTop &&
						viewportTop + $window.height() > refOffsetTop + te.$ref.height() &&
						// There can be gadgets/scripts that make references horizontally scrollable.
						$window.width() > te.$ref.offset().left + te.$ref.width()
					) {
						// Highlight the reference itself
						te.$ref.addClass( 'rt-target' );
						return;
					}
				}

				if ( !te.tooltip ) {
					te.tooltip = new Tooltip( te );
					if ( !te.tooltip.$content.length ) {
						return;
					}
				}

				// If this tooltip is called from inside another tooltip. We can't define it
				// in the constructor since a ref can be cloned but have the same Tooltip object;
				// so, Tooltip.parent is a floating value.
				te.tooltip.parent = te.$element.closest( '.rt-tooltip' ).data( 'tooltip' );
				if ( te.tooltip.parent && te.tooltip.parent.disappearing ) {
					return;
				}

				te.tooltip.show();

				if ( tooltipInitiallyPresent ) {
					if ( te.tooltip.$element.hasClass( 'rt-tooltip-above' ) ) {
						te.tooltip.$element.addClass( CLASSES.FADE_IN_DOWN );
					} else {
						te.tooltip.$element.addClass( CLASSES.FADE_IN_UP );
					}
					return;
				}

				te.tooltip.calculatePosition();

				$window.on( 'resize.rt', te.onWindowResize );
			}

			// We redefine this.$element here because e.target can be a reference link inside
			// a reference tooltip, not a link that was initially assigned to this.$element
			this.$element = $element;

			if ( this.type === 'commentedText' ) {
				this.$element.attr( 'title', '' );
			}

			if ( activatedByClick ) {
				if ( tooltipInitiallyPresent ||
					( this.$ref && this.$ref.hasClass( 'rt-target' ) )
				) {
					return;
				} else {
					setTimeout( function () {
						$body.on( 'click.rt touchstart.rt', te.onBodyClick );
					}, 0 );
				}
			}

			if ( activatedByClick || tooltipInitiallyPresent ) {
				reallyShow();
			} else {
				this.showTimer = setTimeout( reallyShow, delay );
			}
		};

		this.onBodyClick = function ( e ) {
			if ( !te.tooltip && !te.$ref.hasClass( 'rt-target' ) ) {
				return;
			}

			var $current = $( e.target );

			function contextMatchesParameter( parameter ) {
				return this === parameter;
			}

			// The last condition is used to determine cases when a clicked tooltip is the current
			// element's tooltip or one of its descendants
			while ( $current.length &&
				( !$current.hasClass( 'rt-tooltip' ) ||
					!$current.data( 'tooltip' ) ||
					!$current.data( 'tooltip' ).upToTopParent(
						contextMatchesParameter, [ te.tooltip ],
						true
					)
				)
			) {
				$current = $current.parent();
			}
			if ( !$current.length ) {
				te.hideRef();
			}
		};

		this.onWindowResize = function () {
			te.tooltip.calculatePosition();
		};
	}

	function Tooltip( te ) {
		function openSettingsDialog() {
			var settingsDialog, settingsWindow;

			if ( cursorWaitCss ) {
				cursorWaitCss.disabled = true;
			}

			function SettingsDialog() {
				SettingsDialog.parent.call( this );
			}
			OO.inheritClass( SettingsDialog, OO.ui.ProcessDialog );

			SettingsDialog.static.name = 'settingsDialog';
			//SettingsDialog.static.size = 'large';
			SettingsDialog.static.title = mw.msg( 'rt-settings-title' );
			SettingsDialog.static.actions = [
				{
					modes: 'basic',
					action: 'save',
					label: mw.msg( 'rt-save' ),
					flags: [ 'primary', 'progressive' ]
				},
				{
					modes: 'basic',
					label: mw.msg( 'rt-cancel' ),
					flags: 'safe'
				},
				{
					modes: 'disabled',
					action: 'deactivated',
					label: mw.msg( 'rt-ready' ),
					flags: [ 'primary', 'progressive' ]
				}
			];

			SettingsDialog.prototype.initialize = function () {
				var dialog = this;

				SettingsDialog.parent.prototype.initialize.apply( this, arguments );

				this.enableOption = new OO.ui.RadioOptionWidget( {
					label: mw.msg( 'rt-enable' )
				} );
				this.disableOption = new OO.ui.RadioOptionWidget( {
					label: mw.msg( 'rt-disable' )
				} );
				this.enableSelect = new OO.ui.RadioSelectWidget( {
					items: [ this.enableOption, this.disableOption ],
					classes: [ 'rt-enableSelect' ]
				} );
				this.enableSelect.selectItem( this.enableOption );
				this.enableSelect.on( 'choose', function ( item ) {
					if ( item === dialog.disableOption ) {
						dialog.activationMethodSelect.setDisabled( true );
						dialog.delayInput.setDisabled( true );
						dialog.tooltipsForCommentsCheckbox.setDisabled( true );
					} else {
						dialog.activationMethodSelect.setDisabled( false );
						dialog.delayInput.setDisabled( dialog.clickOption.isSelected() );
						dialog.tooltipsForCommentsCheckbox.setDisabled( false );
					}
				} );

				this.hoverOption = new OO.ui.RadioOptionWidget( {
					label: mw.msg( 'rt-hovering' )
				} );
				this.clickOption = new OO.ui.RadioOptionWidget( {
					label: mw.msg( 'rt-clicking' )
				} );
				this.activationMethodSelect = new OO.ui.RadioSelectWidget( {
					items: [ this.hoverOption, this.clickOption ]
				} );
				this.activationMethodSelect.selectItem( activatedByClick ?
					this.clickOption :
					this.hoverOption
				);
				this.activationMethodSelect.on( 'choose', function ( item ) {
					if ( item === dialog.clickOption ) {
						dialog.delayInput.setDisabled( true );
					} else {
						dialog.delayInput.setDisabled( dialog.clickOption.isSelected() );
					}
				} );
				this.activationMethodField = new OO.ui.FieldLayout( this.activationMethodSelect, {
					label: mw.msg( 'rt-activationMethod' ),
					align: 'top'
				} );

				this.delayInput = new OO.ui.NumberInputWidget( {
					input: { value: delay },
					step: 50,
					min: 0,
					max: 5000,
					disabled: activatedByClick,
					classes: [ 'rt-numberInput' ]
				} );
				this.delayField = new OO.ui.FieldLayout( this.delayInput, {
					label: mw.msg( 'rt-delay' ),
					align: 'top'
				} );

				this.tooltipsForCommentsCheckbox = new OO.ui.CheckboxInputWidget( {
					selected: tooltipsForComments
				} );
				this.tooltipsForCommentsField = new OO.ui.FieldLayout(
					this.tooltipsForCommentsCheckbox,
					{
						label: new OO.ui.HtmlSnippet( mw.msg( 'rt-tooltipsForComments' ) ),
						align: 'inline',
						classes: [ 'rt-tooltipsForCommentsField' ]
					}
				);
				new TooltippedElement(
					this.tooltipsForCommentsField.$element.find( '.' + COMMENTED_TEXT_CLASS )
				);

				this.fieldset = new OO.ui.FieldsetLayout();
				this.fieldset.addItems( [
					this.activationMethodField,
					this.delayField,
					this.tooltipsForCommentsField
				] );

				this.panelSettings = new OO.ui.PanelLayout( {
					padded: true,
					expanded: false
				} );
				this.panelSettings.$element.append(
					this.enableSelect.$element,
					$( '<hr>' ).addClass( 'rt-settingsFormSeparator' ),
					this.fieldset.$element
				);

				this.panelDisabled = new OO.ui.PanelLayout( {
					padded: true,
					expanded: false
				} );
				this.panelDisabled.$element.append(
					$( '<table>' )
						.addClass( 'rt-disabledHelp' )
						.append(
							$( '<tr>' ).append(
								$( '<td>' ).append(
									$( '<img>' ).attr( 'src', 'https://ru.wikipedia.org/w/load.php?modules=ext.popups.images&image=footer&format=rasterized&lang=ru&skin=vector&version=0uotisb' )
								),
								$( '<td>' )
									.addClass( 'rt-disabledNote' )
									.text( mw.msg( 'rt-disabledNote' ) )
							)
						)
				);

				this.stackLayout = new OO.ui.StackLayout( {
					items: [ this.panelSettings, this.panelDisabled ]
				} );

				this.$body.append( this.stackLayout.$element );
			};

			SettingsDialog.prototype.getSetupProcess = function ( data ) {
				return SettingsDialog.parent.prototype.getSetupProcess.call( this, data )
					.next( function () {
						this.stackLayout.setItem( this.panelSettings );
						this.actions.setMode( 'basic' );
					}, this );
			};

			SettingsDialog.prototype.getActionProcess = function ( action ) {
				var dialog = this;

				if ( action === 'save' ) {
					return new OO.ui.Process( function () {
						var newDelay = Number( dialog.delayInput.getValue() );

						enabled = dialog.enableOption.isSelected();
						if ( newDelay >= 0 && newDelay <= 5000 ) {
							delay = newDelay;
						}
						activatedByClick = dialog.clickOption.isSelected();
						tooltipsForComments = dialog.tooltipsForCommentsCheckbox.isSelected();

						setSettingsCookie();

						if ( enabled ) {
							dialog.close();
							disableRt();
							rt( $content );
						} else {
							dialog.actions.setMode( 'disabled' );
							dialog.stackLayout.setItem( dialog.panelDisabled );
							disableRt();
							addEnableLink();
						}
					} );
				} else if ( action === 'deactivated' ) {
					dialog.close();
				}
				return SettingsDialog.parent.prototype.getActionProcess.call( this, action );
			};

			SettingsDialog.prototype.getBodyHeight = function () {
				return this.stackLayout.getCurrentItem().$element.outerHeight( true );
				//return 400; // sets height of the dialog to ~430px
			};

			tooltip.upToTopParent( function adjustRightAndHide() {
				if ( this.isPresent ) {
					if ( this.$element[ 0 ].style.right ) {
						this.$element.css(
							'right',
							'+=' + ( window.innerWidth - $window.width() )
						);
					}
					this.te.hideRef( true );
				}
			} );

			if ( !windowManager ) {
				windowManager = new OO.ui.WindowManager();
				$body.append( windowManager.$element );
			}

			settingsDialog = new SettingsDialog();
			windowManager.addWindows( [ settingsDialog ] );
			settingsWindow = windowManager.openWindow( settingsDialog );
			settingsWindow.opened.then( function () {
				settingsDialogOpening = false;
			} );
			settingsWindow.closed.then( function () {
				windowManager.clearWindows();
			} );
		}

		var tooltip = this;

		// This variable can change: one tooltip can be called from a harvard-style reference link
		// that is put into different tooltips
		this.te = te;

		switch ( this.te.type ) {
			case 'supRef':
				this.id = 'rt-' + this.te.$originalElement.attr( 'id' );
				this.$content = this.te.$ref
					.children()
					.not( '.mw-cite-backlink' )
					.clone( true );
				break;
			case 'harvardRef':
				this.id = 'rt-' + this.te.$originalElement.closest( 'li' ).attr( 'id' );
				this.$content = this.te.$ref
					.clone( true )
					.removeAttr( 'id' );
				break;
			case 'commentedText':
				this.id = 'rt-' + String( Math.random() ).slice( 2 );
				this.$content = $( document.createTextNode( this.te.comment ) );
				break;
		}
		if ( !this.$content.length ) {
			return;
		}

		this.insideWindow = Boolean( this.te.$element.closest( '.oo-ui-window' ).length );

		this.$element = $( '<div>' )
			.addClass( 'rt-tooltip' )
			.attr( 'id', this.id )
			.attr( 'role', 'tooltip' )
			.data( 'tooltip', this );
		if ( this.insideWindow ) {
			this.$element.addClass( 'rt-tooltip-insideWindow' );
		}

		// We need the $content interlayer here in order for the settings icon to have the correct
		// margins
		this.$content = this.$content
			.wrapAll( '<div>' )
			.parent()
			.addClass( 'rt-tooltipContent' )
			.appendTo( this.$element );

		if ( !activatedByClick ) {
			this.$element
				.mouseenter( function () {
					if ( !tooltip.disappearing ) {
						tooltip.upToTopParent( function () {
							this.show();
						} );
					}
				} )
				.mouseleave( function ( e ) {
					// https://stackoverflow.com/q/47649442 workaround. Relying on relatedTarget
					// alone has pitfalls: when alt-tabbing, relatedTarget is empty too
					if ( CLIENT_NAME !== 'chrome' ||
						( !e.originalEvent ||
							e.originalEvent.relatedTarget !== null ||
							!tooltip.clickedTime ||
							$.now() - tooltip.clickedTime > 50
						)
					) {
						tooltip.upToTopParent( function () {
							this.te.hideRef();
						} );
					}
				} )
				.click( function () {
					tooltip.clickedTime = $.now();
				} );
		}

		if ( !this.insideWindow ) {
			$( '<div>' )
				.addClass( 'rt-settingsLink' )
				.attr( 'title', mw.msg( 'rt-settings' ) )
				.click( function () {
					if ( settingsDialogOpening ) {
						return;
					}
					settingsDialogOpening = true;

					if ( mw.loader.getState( 'oojs-ui' ) !== 'ready' ) {
						if ( cursorWaitCss ) {
							cursorWaitCss.disabled = false;
						} else {
							cursorWaitCss = mw.util.addCSS( 'body { cursor: wait; }' );
						}
					}
					mw.loader.using( [ 'oojs', 'oojs-ui' ], openSettingsDialog );
				} )
				.prependTo( this.$content );
		}

		// Tooltip tail element is inside tooltip content element in order for the tooltip
		// not to disappear when the mouse is above the tail
		$( '<div>' )
			.addClass( 'rt-tooltipTail' )
			.prependTo( this.$element );

		this.disappearing = false;

		this.show = function () {
			this.disappearing = false;
			clearTimeout( this.te.hideTimer );
			clearTimeout( this.te.removeTimer );

			this.$element
				.removeClass( CLASSES.FADE_OUT_DOWN )
				.removeClass( CLASSES.FADE_OUT_UP );

			if ( !this.isPresent ) {
				$body.append( this.$element );
			}

			this.isPresent = true;
		};

		this.hide = function () {
			var tooltip = this;

			tooltip.disappearing = true;

			if ( tooltip.$element.hasClass( 'rt-tooltip-above' ) ) {
				tooltip.$element
					.removeClass( CLASSES.FADE_IN_DOWN )
					.addClass( CLASSES.FADE_OUT_UP );
			} else {
				tooltip.$element
					.removeClass( CLASSES.FADE_IN_UP )
					.addClass( CLASSES.FADE_OUT_DOWN );
			}

			tooltip.te.removeTimer = setTimeout( function () {
				if ( tooltip.isPresent ) {
					tooltip.$element.detach();

					if ( tooltip.tailCss ) {
						tooltip.tailCss.disabled = true;
					}

					if ( activatedByClick ) {
						$body.off( 'click.rt touchstart.rt', tooltip.te.onBodyClick );
					}
					$window.off( 'resize.rt', tooltip.te.onWindowResize );

					tooltip.isPresent = false;
				}
			}, 200 );
		};

		this.calculatePosition = function () {
			var teElement, teOffset, teCenter, tooltipTailLeft,
				offsetYCorrection = 0;

			if ( this.tailCss ) {
				this.tailCss.disabled = true;
			}

			teElement = this.te.$element.get( 0 );
			teOffset = teElement.getClientRects &&
					teElement.getClientRects()[0] ?
				teElement.getClientRects()[0] :
				teElement.getBoundingClientRect();
			teOffset = {
				top: $window.scrollTop() + teOffset.top,
				left: $window.scrollLeft() + teOffset.left,
				width: teOffset.width,
				height: teOffset.height
			};
			teCenter = ( teOffset.left * 2 + teOffset.width ) / 2;
			if ( CLIENT_NAME === 'msie' && this.te.type === 'supRef' ) {
				offsetYCorrection = -Number(
					this.te.$element.parent().css( 'font-size' ).replace( 'px', '' )
				) / 2;
			}
			this.$element.css( {
				top: teOffset.top - this.$element.outerHeight() - 7 + offsetYCorrection,
				left: teCenter - 20,
				right: ''
			} );

			// Is it squished against the right side of the page?
			if ( this.$element.offset().left + this.$element.outerWidth() > $window.width() - 1 ) {
				this.$element.css( {
					left: '',
					right: 0
				} );
				tooltipTailLeft = teCenter - this.$element.offset().left - 5;
			}

			// Is a part of it above the top of the screen?
			if ( teOffset.top < this.$element.outerHeight() + $window.scrollTop() + 6 ) {
				this.$element
					.removeClass( 'rt-tooltip-above' )
					.addClass( 'rt-tooltip-below' )
					.addClass( CLASSES.FADE_IN_UP )
					.css( {
						top: teOffset.top + teOffset.height + 9 + offsetYCorrection
					} );
				if ( tooltipTailLeft ) {
					this.tailCss = mw.util.addCSS(
						'#' + $.escapeSelector( tooltip.id ) + ' .rt-tooltipTail { left: ' +
						( tooltipTailLeft + 12 ) + 'px; }'
					);
				}
			} else {
				this.$element
					.removeClass( 'rt-tooltip-below' )
					.addClass( 'rt-tooltip-above' )
					.addClass( CLASSES.FADE_IN_DOWN )
					// A fix for cases when a tooltip shown once is then wrongly positioned when it
					// is shown again after a window resize. We just repeat what is above.
					.css( {
						top: teOffset.top - this.$element.outerHeight() - 7 + offsetYCorrection
					} );
				if ( tooltipTailLeft ) {
					// 12 is the tail element width/height
					this.tailCss = mw.util.addCSS(
						'#' + $.escapeSelector( tooltip.id ) + ' .rt-tooltipTail { left: ' +
							tooltipTailLeft + 'px; }'
					);
				}
			}
		};

		// Run some function for all the tooltips up to the top one in a tree. Its context will be
		// the tooltip, while its parameters may be passed to Tooltip.upToTopParent as an array
		// in the second parameter. If the third parameter passed to ToolTip.upToTopParent is true,
		// the execution stops when the function in question returns true for the first time,
		// and ToolTip.upToTopParent returns true as well.
		this.upToTopParent = function ( func, parameters, stopAtTrue ) {
			var returnValue,
				currentTooltip = this;

			do {
				returnValue = func.apply( currentTooltip, parameters );
				if ( stopAtTrue && returnValue ) {
					break;
				}
			} while ( currentTooltip = currentTooltip.parent );

			if ( stopAtTrue ) {
				return returnValue;
			}
		};
	}

	if ( !enabled ) {
		addEnableLink();
		return;
	}

	teSelector = REF_LINK_SELECTOR;
	if ( tooltipsForComments ) {
		teSelector += ', ' + COMMENTED_TEXT_SELECTOR;
	}
	$content.find( teSelector ).each( function () {
		new TooltippedElement( $( this ) );
	} );
}

settingsString = mw.cookie.get( 'RTsettings' );
if ( settingsString ) {
	settings = settingsString.split( '|' );
	enabled = Boolean( Number( settings[ 0 ] ) );
	delay = Number( settings[ 1 ] );
	activatedByClick = Boolean( Number( settings[ 2 ] ) );
	// The forth value was added later, so we provide for a default value. See comments below
	// for why we use "IS_TOUCHSCREEN && IS_MOBILE".
	tooltipsForComments = settings[ 3 ] === undefined ?
		IS_TOUCHSCREEN && IS_MOBILE :
		Boolean( Number( settings[ 3 ] ) );
} else {
	enabled = true;
	delay = 200;
	// Since the mobile browser check is error-prone, adding IS_MOBILE condition here would probably
	// leave cases where a user interacting with the browser using touches doesn't know how to call
	// a tooltip in order to switch to activation by click. Some touch-supporting laptop users
	// interacting by touch (though probably not the most popular use case) would not be happy too.
	activatedByClick = IS_TOUCHSCREEN;
	// Arguably we shouldn't convert native tooltips into gadget tooltips for devices that have
	// mouse support, even if they have touchscreens (there are laptops with touchscreens).
	// IS_TOUCHSCREEN check here is for reliability, since the mobile check is prone to false
	// positives.
	tooltipsForComments = IS_TOUCHSCREEN && IS_MOBILE;
}

mw.hook( 'wikipage.content' ).add( rt );

}() );

/* ===== FUNCTIONALITY : Adds form edit links =========================================================================================================================
 * 
 * Adds section heading edit links on game pages with form editing enabled.
 */

function PCGW_formedit() {
	if ($('body').hasClass('mw-special-FormEdit')) {
		return;
	} if ($('body').hasClass('action-view')) {
		$(':header.Availability,:header.Essential_improvements,:header.Game_data,:header.Video_settings,:header.Input_settings,:header.Audio_settings,:header.Network,:header.VR_support,:header.Issues,:header.Other_information,h2.System_requirements', '#mw-content-text').each(function() {
			var $this = $(this);
			if ($this.attr('class') !== undefined) {
				var classes = $this.attr('class');
				var formclass = classes.split(' ', 2);
				if (formclass[1] !== undefined) {
					var formsection = '\#' + formclass[1];
					} else {var formsection = '';
				}
				$('<span class="mw-editsection"></span>').append('<span class="mw-editsection-bracket">\[</span>').append(
					$('<a></a>').text('edit').attr({title: 'Edit this section with a form', href: 'https://pcgamingwiki.com/wiki/Special:FormEdit/' + formclass[0] + '_test/' +mw.config.get( 'wgPageName' ) + formsection})
				).append('<span class="mw-editsection-bracket">\]</span>').appendTo(this);
			}
		});
	}
}

$(PCGW_formedit);