MediaWiki:Common.js

From Mechanics

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.
/* Any JavaScript here will be loaded for all users on every page load. */

// Check if we're editing a page.
if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -1 ) {
	// Add a hook handler.
	mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) {
		
		// Add Math button
		$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
			section: 'advanced',
			group: 'format',
			tools: {
				"math": {
					label: 'Math',
					type: 'button',
					icon: '//latex.codecogs.com/png.image?%5Cdpi%7B110%7D%20%5Csqrt%7Bx%7D%20',
					//icon: '//upload.wikimedia.org/wikipedia/commons/2/2e/Button_math.png',
					action: {
						type: 'encapsulate',
						options: {
							pre: "<math>",
							post: "</math>"
						}
					}
				}
			}
		} );
	} );
}