MediaWiki

Common.js

Revision as of 13:51, 25 February 2020 by Jonathan (talk | contribs)

Note: After saving, 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: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/* Any JavaScript here will be loaded for all users on every page load. */

$( "span#mwext-bc" ).before( "<p>!!!!!!!!!!!" );


/* TreeAndMenu */
/* See: https://www.mediawiki.org/wiki/Extension:TreeAndMenu#Opening_a_tree_to_the_current_page */
$(document).ready( function() {
    $('#tree').bind('fancytreeinit', function(event, data) {
        data.tree.makeTitleVisible();
    });
});

/* Cargo radio buttons e.g. on Legislation form otherwise appear like a paragraph */
/* $( "label.radioButtonItem" ).after( "<br/>" ); */

/* Don't like this but necessary for now to fix formatting of Drilldown combobox/search */
$( "div.drilldown-filter" ).before( "<br clear='all'/>" );

function citationDownload(filename, text) {
  var element = document.createElement('a');
  element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
  element.setAttribute('download', filename);

  element.style.display = 'none';
  document.body.appendChild(element);

  element.click();

  document.body.removeChild(element);
}




/*window.os_max_lines_per_suggest = 4; */ /* was 7 in skins/common/mwsuggest.js but overlapped with menu*/

/* Page Forms */
$( function() {
  $('.pfCoordsInput').prop('readonly', true);
  // $('.pfUpdateMap').hide();
} );


/* Special:Drilldown */
/* Show filter values even when value selected; hide "Click arrow to add another value" message; hide arrow icons */
/*
$( function() {
  $('.drilldown-filter-values').show();
  $('.drilldown-filter-notes').hide();
  $('.drilldown-values-toggle').hide();
} );
*/

/* WikiEditor toolbar customisation: see https://www.mediawiki.org/wiki/Extension:WikiEditor/Toolbar_customization */

var customizeToolbar = function () {
	/* Your code goes here */
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		section: 'advanced',
		group: 'format',
		tools: {
			"blockquote": {
				label: 'Blockquote',
				type: 'button',
				icon: '//upload.wikimedia.org/wikipedia/commons/f/fd/Toolbar_blockquote.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "<blockquote>",
						post: "</blockquote>"
					}
				}
			}
		}
	} );


	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		section: 'advanced',
		group: 'insert',
		tools: {
			"category": {
				label: 'Category',
				type: 'button',
				icon: '//upload.wikimedia.org/wikipedia/commons/2/28/Toolbaricon_category.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "[[Category:",
						post: "]]"
					}
				}
			}
		}
	} );



};

/* 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' ).then( function () {
		// This can be the string "0" if the user disabled the preference ([[phab:T54542#555387]])
		if ( mw.user.options.get( 'showtoolbar' ) == 1 ) {
			$.when(
				mw.loader.using( 'ext.wikiEditor' ), $.ready
			).then( customizeToolbar );
		}
	} );
}