MediaWiki:Gadget-newPage.js: Difference between revisions

From RuneRealm Wiki
Jump to navigation Jump to search
Content added Content deleted
(Created page with "$(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:...")
 
No edit summary
Tag: Reverted
Line 11: Line 11:
var page = pagenameInput.getValue();
var page = pagenameInput.getValue();
if (page == '') return;
if (page == '') return;
var url = mw.util.getUrl(page, {action: 'edit'});
var url = mw.mw.util.getUrl(page, {action: 'edit'});
window.location.assign(url);
window.location.assign(url);
};
};

Revision as of 00:10, 17 October 2024

$(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();
})