MediaWiki:Common.js

De Grêmiopédia, a enciclopédia do Grêmio
(Redirecionado de JavaScript)
Ir para navegação Ir para pesquisar

Nota: Após publicar, você pode ter que limpar o "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: PressioneCtrl enquanto clica Recarregar, ou Pressione Ctrl-F5
  • Opera: Pressione Ctrl-F5.
/* Qualquer código JavaScript presente aqui será carregado por todos os usuários em cada página carregada. */
/*jshint camelcase: true, curly: true, eqeqeq: true, immed: true, latedef: true, newcap: true, noarg: true, noempty: true, nonew: true, quotmark: single, trailing: true, undef: true, unused: true, bitwise: true, forin: true, regexp: true, strict: true, onevar: true, laxbreak: true */
/*global mediaWiki, jQuery */

( function ( mw, $ ) {
'use strict';

/**
 * Oculta botão editar da [[Wikipédia:Esplanada/propostas]] e da [[Wikipédia:Esplanada/geral]]
 *
 * @author: Helder (https://github.com/he7d3r)
 * @license: CC BY-SA 3.0 <https://creativecommons.org/licenses/by-sa/3.0/>
 */
function hideEditButton() {
	var temp = 'Template:Esplanada2/Preload';

	if ( mw.config.get( 'wgUserLanguage' ) !== 'pt' ) {
		temp += '/en';
	}

	$( '#ca-addsection' ).find( 'a' ).attr(
		'href',
		mw.util.getUrl( mw.config.get( 'wgPageName' ), {
			action: 'edit',
			section: 'new',
			preload: temp
		} )
	);

	if ( mw.config.get( 'skin' ) === 'vector' ) {
		// Move o botão "editar" para o menu de ações
		$( '#p-cactions' ).removeClass( 'emptyPortlet' ).find( 'ul' ).append( $( '#ca-edit' ) );
	}
}

/**
 * Parâmetros &withCSS= e &withJS= para a URL
 * 
 * Permite que sejam testados scripts e folhas de estilos do domínio MediaWiki
 * sem precisar editar páginas ".css" ou ".js" pessoais
 * @source https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
 * @revision 2016-03-26
 */
mw.loader.using( ['mediawiki.util', 'mediawiki.notify'], function () {
	var extraCSS = mw.util.getParamValue( 'withCSS' ),
		extraJS = mw.util.getParamValue( 'withJS' );

	if ( extraCSS ) {
		if ( /^MediaWiki:[^&<>=%#]*\.css$/.test( extraCSS ) ) {
			mw.loader.load( '/w/index.php?title=' + extraCSS + '&action=raw&ctype=text/css', 'text/css' );
		} else {
			mw.notify( 'Só são permitidas páginas do domínio MediaWiki.', { title: 'Valor withCSS inválido' } );
		}
	}

	if ( extraJS ) {
		if ( /^MediaWiki:[^&<>=%#]*\.js$/.test( extraJS ) ) {
			mw.loader.load( '/w/index.php?title=' + extraJS + '&action=raw&ctype=text/javascript' );
		} else {
			mw.notify( 'Só são permitidas páginas do domínio MediaWiki.', { title: 'Valor withJS inválido' } );
		}
	}
} );

// Ocultar a barra de sumário das páginas de pedidos
mw.loader.using( 'mediawiki.util', function () {
	if ( /Wikipédia:Pedidos\/(?!Outros|Revisão_de_ações_administrativas$)/.test( mw.config.get( 'wgPageName' ) ) && mw.util.getParamValue( 'section' ) === 'new' ) {
		$( '.mw-summary' ).hide();
	}
} );

// Scripts para páginas específicas
if ( $.inArray( mw.config.get( 'wgPageName' ), [ 'Wikipédia:Esplanada/propostas', 'Wikipédia:Esplanada/geral' ] ) !== -1 ) {
	$( hideEditButton );
}

}( mediaWiki, jQuery ) );