MediaWiki:Gadget-newPage.js

From Old School Near-Reality Wiki
Jump to navigation Jump to search

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

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
 1 $(function () {
 2 	var $button, $window;
 3 	
 4 	function createWindow(modal){
 5 		modal.content =  new OO.ui.PanelLayout({ padded: true, expanded: false });
 6 		var pagenameInput = new OO.ui.TextInputWidget({placeholder: 'Full page name including namespace', type: 'text', id: 'gadget-newpage-pagename'});
 7 		var submitButton = new OO.ui.ButtonInputWidget({ label: 'Create', flags: ['primary', 'progressive']});
 8 		var cancelButton = new OO.ui.ButtonInputWidget({ label: 'Cancel', flags: 'destructive'});
 9 		
10 		var submitAction = function(modal) {
11 			var page = pagenameInput.getValue();
12 			if (page == '') return;
13 			var url = mw.util.getUrl(page, {action: 'edit'});
14 			window.location.assign(url);
15 		};
16 		
17 		submitButton.on('click', submitAction);
18 		pagenameInput.on('enter', submitAction);
19 		
20 		cancelButton.on('click', function(modal){window.OOUIWindowManager.closeWindow(modal);}, [modal]);
21 		
22 		var fieldset = new OO.ui.FieldsetLayout({});
23 		fieldset.addItems([
24 			new OO.ui.FieldLayout(pagenameInput, { label: 'Page name', help: 'Full page name of the page to created, including namespace' })
25 		]);
26 		modal.content.$element.append(fieldset.$element, '<br>', cancelButton.$element, submitButton.$element);
27 		modal.$body.append(modal.content.$element);
28 	}
29 
30 	function openWindow(e){
31 		e.preventDefault();
32 		if ($window == undefined) {
33 			rswiki.createOOUIWindow('gadget-newpage-window', 'Create new page', {}, createWindow, true).then(function(w){
34 				$window = w;
35 			});
36 		} else {
37 			window.OOUIWindowManager.openWindow('gadget-newpage-window');
38 		}
39 	}
40 
41 	function init(){
42 		$button = $('<li>').attr('id', 't-gadget-newpage').append($('<a>').attr('href', '#').text('Make new page'));
43 		
44 		$button.click(openWindow);
45 		
46 		$('#p-tb .vector-menu-content ul').append($button);
47 	}
48 	init();
49 })