MediaWiki:Common.js: mudanças entre as edições

De PokeStorm Wiki
Sem resumo de edição
Sem resumo de edição
 
(5 revisões intermediárias por 2 usuários não estão sendo mostradas)
Linha 1: Linha 1:
/* Códigos JavaScript aqui colocados serão carregados por todos aqueles que acessarem alguma página deste wiki */
/*
* This is the JS for all skins (for both mobile and desktop) on MediaWiki.org.
* Consider whether you can use a gadget with one of the options set to limit
* where it is loaded. See [[Extension:Gadgets#Options]].
*/
/* global mw, $ */
/**
* Hide prefix in category
*
* @source https://www.mediawiki.org/wiki/Snippets/Hide_prefix_in_category
* @rev 5
*/
var prefix = $.trim( $( '#mw-cat-hideprefix' ).text() ) || ( mw.config.get( 'wgTitle' ) + '/' );
$( '#mw-pages' ).find( 'a' ).text( function ( i, val ) {
    return val.slice( 0, prefix.length ) === prefix ? val.slice( prefix.length ) : val;
} );


function ModifySidebar( action, section, name, link ) {
/**
try {
* @source https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
switch ( section ) {
* @revision 2017-05-16
case 'languages':
*/
var target = 'p-lang';
mw.loader.using( ['mediawiki.util'], function () {
break;
var extraCSS = mw.util.getParamValue( 'withCSS' ),
case 'toolbox':
extraJS = mw.util.getParamValue( 'withJS' ),
var target = 'p-tb';
extraModule = mw.util.getParamValue( 'withModule' );
break;
 
case 'navigation':
if ( extraCSS ) {
var target = 'p-navigation';
// WARNING: DO NOT REMOVE THIS "IF" - REQUIRED FOR SECURITY (against XSS/CSRF attacks)
break;
if ( /^MediaWiki:[^&<>=%#]*\.css$/.test( extraCSS ) ) {
default:
mw.loader.load( '/w/index.php?title=' + encodeURIComponent( extraCSS ) + '&action=raw&ctype=text/css', 'text/css' );
var target = 'p-' + section;
} else {
break;
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } );
}
}
}


if ( action == 'add' ) {
if ( extraJS ) {
var node = document.getElementById( target )
// WARNING: DO NOT REMOVE THIS "IF" - REQUIRED FOR SECURITY (against XSS/CSRF attacks)
  .getElementsByTagName( 'div' )[1]
if ( /^MediaWiki:[^&<>=%#]*\.js$/.test( extraJS ) ) {
  .getElementsByTagName( 'ul' )[0];
mw.loader.load( '/w/index.php?title=' + encodeURIComponent( extraJS ) + '&action=raw&ctype=text/javascript' );
 
} else {
var aNode = document.createElement( 'a' );
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
var liNode = document.createElement( 'li' );
 
aNode.appendChild( document.createTextNode( name ) );
aNode.setAttribute( 'href', link );
liNode.appendChild( aNode );
liNode.className = 'mw-list-item';
node.appendChild( liNode );
}
}
}


if ( action == 'remove' ) {
if ( extraModule ) {
var list = document.getElementById( target )
if ( /^ext\.gadget\.[^,\|]+$/.test( extraModule ) ) {
  .getElementsByTagName( 'div' )[1]
mw.loader.load( extraModule );
  .getElementsByTagName( 'ul' )[0];
} else {
 
mw.notify( 'Only gadget modules are allowed.', { title: 'Invalid withModule value' } );
var listelements = list.getElementsByTagName( 'li' );
 
for ( var i = 0; i < listelements.length; i++ ) {
if (
listelements[i].getElementsByTagName( 'a' )[0].innerHTML == name ||
listelements[i].getElementsByTagName( 'a' )[0].href == link
)
{
list.removeChild( listelements[i] );
}
}
}
}
} catch( e ) {
// let's just ignore what's happened
return;
}
}
}
});
 
function CustomizeModificationsOfSidebar() {
// Adds [[Special:CategoryTree|Special:CategoryTree]] to toolbox
ModifySidebar( 'add', 'toolbox', 'CategoryTree', 'https://en.wikipedia.org/wiki/Special:CategoryTree' );
}


jQuery( CustomizeModificationsOfSidebar );
$(document).ready(function() {
    $('a.image-popup').click(function(event) {
        event.preventDefault();
        var imageUrl = $(this).attr('href');
        var popupWindow = window.open(imageUrl, 'ImagemPopup', 'width=800,height=600,resizable=yes,scrollbars=yes');
        if (popupWindow) {
            popupWindow.focus();
        }
    });
});

Edição atual tal como às 08h33min de 28 de março de 2025

/*
 * This is the JS for all skins (for both mobile and desktop) on MediaWiki.org.
 * Consider whether you can use a gadget with one of the options set to limit
 * where it is loaded. See [[Extension:Gadgets#Options]].
 */
/* global mw, $ */
/**
 * Hide prefix in category
 *
 * @source https://www.mediawiki.org/wiki/Snippets/Hide_prefix_in_category
 * @rev 5
 */
var prefix = $.trim( $( '#mw-cat-hideprefix' ).text() ) || ( mw.config.get( 'wgTitle' ) + '/' );
$( '#mw-pages' ).find( 'a' ).text( function ( i, val ) {
    return val.slice( 0, prefix.length ) === prefix ? val.slice( prefix.length ) : val;
} );

/**
 * @source https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
 * @revision 2017-05-16
 */
mw.loader.using( ['mediawiki.util'], function () {
	var extraCSS = mw.util.getParamValue( 'withCSS' ),
		extraJS = mw.util.getParamValue( 'withJS' ),
		extraModule = mw.util.getParamValue( 'withModule' );

	if ( extraCSS ) {
		// WARNING: DO NOT REMOVE THIS "IF" - REQUIRED FOR SECURITY (against XSS/CSRF attacks)
		if ( /^MediaWiki:[^&<>=%#]*\.css$/.test( extraCSS ) ) {
			mw.loader.load( '/w/index.php?title=' + encodeURIComponent( extraCSS ) + '&action=raw&ctype=text/css', 'text/css' );
		} else {
			mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } );
		}
	}

	if ( extraJS ) {
		// WARNING: DO NOT REMOVE THIS "IF" - REQUIRED FOR SECURITY (against XSS/CSRF attacks)
		if ( /^MediaWiki:[^&<>=%#]*\.js$/.test( extraJS ) ) {
			mw.loader.load( '/w/index.php?title=' + encodeURIComponent( extraJS ) + '&action=raw&ctype=text/javascript' );
		} else {
			mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
		}
	}

	if ( extraModule ) {
		if ( /^ext\.gadget\.[^,\|]+$/.test( extraModule ) ) {
			mw.loader.load( extraModule );
		} else {
			mw.notify( 'Only gadget modules are allowed.', { title: 'Invalid withModule value' } );
		}
	}
});

$(document).ready(function() {
    $('a.image-popup').click(function(event) {
        event.preventDefault();
        var imageUrl = $(this).attr('href');
        var popupWindow = window.open(imageUrl, 'ImagemPopup', 'width=800,height=600,resizable=yes,scrollbars=yes');
        if (popupWindow) {
            popupWindow.focus();
        }
    });
});