OBS: Efter du har publicerat sidan kan du behöva tömma din webbläsares cache för att se ändringarna.

  • Firefox / Safari: Håll ned Skift och klicka på Uppdatera sidan eller tryck Ctrl-F5 eller Ctrl-R (⌘-R på Mac)
  • Google Chrome: Tryck Ctrl-Skift-R (⌘-Skift-R på Mac)
  • Internet Explorer / Edge: Håll ned Ctrl och klicka på Uppdatera eller tryck Ctrl-F5
  • Opera: Tryck Ctrl-F5.
$( function() {
	'use strict';
	var v = mw.config.get();
	var actions = [
		'edit',
		'submit'
	];
	var msg1 = 'You do not appear to have entered any heading.';
	var msg2 = 'Note that subjects without a heading are not visible on the mobile site.';
	var closetitle = 'Close the dialog window';
	var closetext = 'close';
	if ( v.wgUserLanguage === 'sv' ) {
		msg1 = 'Du verkar inte ha angivit någon rubrik.';
		msg2 = 'Notera att ämnen utan rubrik inte syns på den mobila webbplatsen.';
		closetitle = 'Stäng dialogrutan';
		closetext = 'Stäng';
	}
	function openDialog() {
		var dialogstr = '<div id="gadget-noheading-container">';
		dialogstr += '<p>' +
			msg1 + '<br>' +
			msg2 +
			'</p>';
		dialogstr += '<button id="gadget-noheading-close" title="' + closetitle + '">' + closetext + '</button>';
		dialogstr += '</div>';

		// Creating and opening a simple dialog window.

		// Subclass Dialog class. Note that the OOjs inheritClass() method extends the parent constructor's prototype and static methods and properties to the child constructor.

		function MyDialog( config ) {
			MyDialog.super.call( this, config );
		}
		var myDialog;
		var windowManager;
		if ( $( '.oo-ui-window-active' ).length === 0 ) {
			OO.inheritClass( MyDialog, OO.ui.Dialog );

			// Specify a title statically (or, alternatively, with data passed to the opening() method).
			MyDialog.static.name = 'gadgetnoheadingdialog';
			MyDialog.static.title = 'Simple dialog';

			// Customize the initialize() function: This is where to add content to the dialog body and set up event handlers.
			MyDialog.prototype.initialize = function () {
				// Call the parent method
				MyDialog.super.prototype.initialize.call( this );
				// Create and append a layout and some content.
				this.content = new OO.ui.PanelLayout( {
					padded: true,
					expanded: false
				} );
				this.content.$element.append( dialogstr );
				this.$body.append( this.content.$element );
				$( '.oo-ui-windowManager' ).click( function( e ) {
					if ( !$( e.target ).parents().filter( '.oo-ui-window' ).length ) {
						myDialog.close();
					}
				} );
				$( '#gadget-noheading-close' ).click( function() {
					myDialog.close();
				} );
			};

			// Use the getTeardownProcess() method to perform actions whenever the dialog is closed.
			// This method provides access to data passed into the window's close() method
			// or the window manager's closeWindow() method.
			MyDialog.prototype.getTeardownProcess = function ( data ) {
				return MyDialog.super.prototype.getTeardownProcess.call( this, data )
				.first( function () {
					// Perform any cleanup as needed
					$( '.oo-ui-windowManager' ).remove();
				}, this );
			};

			// Make the window.
			myDialog = new MyDialog( {
				classes: [
					'gadget-noheading-dialog'
				]
			} );

			// Create and append a window manager, which will open and close the window.
			windowManager = new OO.ui.WindowManager();
			$( 'body' ).append( windowManager.$element );

			// Add the window to the window manager using the addWindows() method.
			windowManager.addWindows( [ myDialog ] );

			// Open the window!
			windowManager.openWindow( myDialog );
		}
	}
	if ( actions.indexOf( v.wgAction ) !== -1 ) {
		if ( v.wgArticleId === 0 ) {
			if ( v.wgRelevantUserName !== v.wgUserName ) {
				if ( $( '#wpTextbox1' ).length === 1 ) {
					$.getJSON( v.wgScript + '?title=MediaWiki:Gadget-NoHeading.json&action=raw&ctype=text/json', function( namespaces ) {
						if ( Array.isArray( namespaces ) ) {
							if ( namespaces.indexOf( v.wgNamespaceNumber ) !== -1 ) {
								$( '#wpSave' ).off();
								$( '#wpSave' ).click( function( ev ) {
									ev.preventDefault();
									if ( ( mw.util.getParamValue( 'section' ) === 'new' && $( '#wpSummary' ).val() ) || ( /^==/gm ).test( $( '#wpTextbox1' ).val() ) ) {
										$( '#wpSave' ).off();
										$( '#wpSave' ).click();
									} else {
										openDialog();
										$( '#wpSave' ).off();
									}
								} );
							}
						}
					} );
				}
			}
		}
	}
} );