MediaWiki:Gadget-ImprovedEditToolbar.js

Origem: Wikilivros, livros abertos por um mundo aberto.

Nota: Depois de publicar, poderá ter de contornar a cache do seu navegador para ver as alterações.

  • Firefox / Safari: Pressione Shift enquanto clica Recarregar, ou pressione Ctrl-F5 ou Ctrl-R (⌘-R no Mac)
  • Google Chrome: Pressione Ctrl-Shift-R (⌘-Shift-R no Mac)
  • Internet Explorer / Edge: Pressione Ctrl enquanto clica Recarregar, ou pressione Ctrl-F5
  • Opera: Pressione Ctrl-F5.
/**
 * Altera a barra de ferramentas, incluindo novos botões para auxiliar a edição
 * Simplificado de [[en:MediaWiki:Common.js/Special characters.js]], que foi criado pelo [[:en:User:Darklama]]
 */
var customizeToolbar = function() {
	var	source,
		$edit = $( '#wpTextbox1' ),
		source_list = {
			'label': 'Tipo de texto',
			'type': 'select',
			'list': {
				'teletype': {
					'label': 'Monoespaçado',
					'action': { 'type': 'encapsulate', 'options': { 'pre': '<tt>', 'peri': 'text', 'post': '</tt>' } }
				},
				'code': {
					'label': 'Código em linha',
					'action': { 'type': 'encapsulate', 'options': { 'pre': '<code>', 'peri': 'text', 'post': '</code>' } }
				},
				'highlightedcode': {
					'label': 'Código-fonte formatado',
					'action': { 'type': 'encapsulate', 'options': { 'pre': '<syntaxhighlight lang="">', 'peri': '\n//Código-fonte\n', 'post': '</syntaxhighlight>' } }
				}
			}
		};
	$edit.wikiEditor( 'addToToolbar', {
		'section': 'main',
		'group': 'format',
		'tools': {
			'underline': {
				label: 'Sublinhado',
				type: 'button',
				icon: '//upload.wikimedia.org/wikipedia/commons/8/8b/Button_underline_he.png',
				action: {
					type: 'encapsulate',
					options: { pre: "<u>", peri: "text", post: "</u>" }
				}
			},
			'strikethrough': {
				label: 'Riscado',
				type: 'button',
				icon: '//upload.wikimedia.org/wikipedia/commons/6/6d/Vector_strikeout.png',
				action: {
					type: 'encapsulate',
					options: { pre: "<s>", peri: "text", post: "</s>" }
				}
			}
		}
	});
	$edit.wikiEditor( 'addToToolbar', {
		'section': 'main',
		'group': 'insert',
		'tools': {
			'math': {
				label: 'Fórmula matemática',
				type: 'button',
				icon: '//upload.wikimedia.org/wikipedia/commons/7/7d/Button_equation_he.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "<math>",
						post: "</math>"
					}
				}
			}
		}
	});
	$edit.wikiEditor( 'addToToolbar', {
		'section': 'advanced',
		'group': 'heading',
		'tools': {
			'text-type': source_list
		}
	});
};
 
/* 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', function () {
		if ( mw.user.options.get('usebetatoolbar') && mw.user.options.get( 'showtoolbar' ) ) {
			$.when(
				mw.loader.using( 'ext.wikiEditor' ),
				$.ready
			).then( customizeToolbar );
		}
	} );
}
// Add the customizations to LiquidThreads' edit toolbar, if available
mw.hook( 'ext.lqt.textareaCreated' ).add( customizeToolbar );