MediaWiki:Gadget-newPage.js

From RuneRealm Wiki

This is an old revision of this page, as edited by Alex (talk | contribs) at 00:10, 17 October 2024. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Jump to navigation Jump to search

After saving, you may need to bypass your browser's cache to see the changes. For further information, see Wikipedia:Bypass your cache.

  • In most Windows and Linux browsers: Hold down Ctrl and press F5.
  • In Safari: Hold down ⇧ Shift and click the Reload button.
  • In Chrome and Firefox for Mac: Hold down both ⌘ Cmd+⇧ Shift and press R.
$(function () {
	var $button, $window;
	
	function createWindow(modal){
		modal.content =  new OO.ui.PanelLayout({ padded: true, expanded: false });
		var pagenameInput = new OO.ui.TextInputWidget({placeholder: 'Full page name including namespace', type: 'text', id: 'gadget-newpage-pagename'});
		var submitButton = new OO.ui.ButtonInputWidget({ label: 'Create', flags: ['primary', 'progressive']});
		var cancelButton = new OO.ui.ButtonInputWidget({ label: 'Cancel', flags: 'destructive'});
		
		var submitAction = function(modal) {
			var page = pagenameInput.getValue();
			if (page == '') return;
			var url = mw.mw.util.getUrl(page, {action: 'edit'});
			window.location.assign(url);
		};
		
		submitButton.on('click', submitAction);
		pagenameInput.on('enter', submitAction);
		
		cancelButton.on('click', function(modal){window.OOUIWindowManager.closeWindow(modal);}, [modal]);
		
		var fieldset = new OO.ui.FieldsetLayout({});
		fieldset.addItems([
			new OO.ui.FieldLayout(pagenameInput, { label: 'Page name', help: 'Full page name of the page to created, including namespace' })
		]);
		modal.content.$element.append(fieldset.$element, '<br>', cancelButton.$element, submitButton.$element);
		modal.$body.append(modal.content.$element);
	}

	function openWindow(e){
		e.preventDefault();
		if ($window == undefined) {
			rswiki.createOOUIWindow('gadget-newpage-window', 'Create new page', {}, createWindow, true).then(function(w){
				$window = w;
			});
		} else {
			window.OOUIWindowManager.openWindow('gadget-newpage-window');
		}
	}

	function init(){
		$button = $('<li>').attr('id', 't-gadget-newpage').append($('<a>').attr('href', '#').text('Make new page'));
		
		$button.click(openWindow);
		
		$('#p-tb .vector-menu-content ul').append($button);
	}
	init();
})