MediaWiki:Common.js

Материал из Wikivoyage

Замечание: Возможно, после публикации вам придётся очистить кэш своего браузера, чтобы увидеть изменения.

  • Firefox / Safari: Удерживая клавишу Shift, нажмите на панели инструментов Обновить либо нажмите Ctrl+F5 или Ctrl+R (⌘+R на Mac)
  • Google Chrome: Нажмите Ctrl+Shift+R (⌘+Shift+R на Mac)
  • Internet Explorer / Edge: Удерживая Ctrl, нажмите Обновить либо нажмите Ctrl+F5
  • Opera: Нажмите Ctrl+F5.
/* Размещённый здесь код JavaScript будет загружаться пользователям при обращении к каждой странице */

// Moving of article states in the upper right corner
importScript( 'MediaWiki:MoveArticleStates.js' );
 
//Test of Migration widgets
importScript('MediaWiki:Common.js/RenameWizard.js');

// For dynamic maps
importScript('MediaWiki:MapFrame.js');

// Patch against unauthorized mirrors
( function () {
		var i, isBad,
			badMirrors = [
			'ru.wikivoyage.net.ru/',
			];
		for ( i = 0; i < badMirrors.length; i++ ) {
			if ( document.location.href.indexOf( badMirrors[ i ] ) !== -1 ) {
				isBad = true;
				break;
			}
		}
		if ( isBad ) {
			// redirect users to the same page on itvoy
			document.location.href = '//ru.wikivoyage.org/wiki/' + mw.config.get( 'wgPageName' );
		}
	} )();

mw.loader.using( ['mediawiki.util', 'jquery.client'], function () {
/* Begin of mw.loader.using callback */

/*
* rwdImageMaps jQuery plugin v1.4
*
* Allows image maps to be used in a responsive design by recalculating the area coordinates to match the actual image size on load and window.resize
*
* Copyright (c) 2012 Matt Stow
* https://github.com/stowball/jQuery-rwdImageMaps
* http://mattstow.com
* Licensed under the MIT license
*/
;(function(a){a.fn.rwdImageMaps=function(){var d=this,c=parseFloat(a.fn.jquery);var b=function(){d.each(function(){if(typeof(a(this).attr("usemap"))=="undefined"){return}var f=this,e=a(f);a("<img />").on('load',function(){var o,k,i="width",n="height";if(c<1.6){o=f.getAttribute(i),k=f.getAttribute(n)}else{o=e.attr(i),k=e.attr(n)}if(!o||!k){var p=new Image();p.src=e.attr("src");if(!o){o=p.width}if(!k){k=p.height}}var g=e.width()/100,l=e.height()/100,j=e.attr("usemap").replace("#",""),m="coords";a('map[name="'+j+'"]').find("area").each(function(){var s=a(this);if(!s.data(m)){s.data(m,s.attr(m))}var r=s.data(m).split(","),q=new Array(r.length);for(var h=0;h<q.length;++h){if(h%2===0){q[h]=parseInt(((r[h]/o)*100)*g)}else{q[h]=parseInt(((r[h]/k)*100)*l)}}s.attr(m,q.toString())})}).attr("src",e.attr("src"))})};a(window).resize(b).trigger("resize");return this}})(jQuery);

// This method will resize elements that have a class name of "js-proportional-resize" by
// changing the font-size (%) based on a viewing area width of 900px being the baseline,
// i.e. 450px width=font size 50%, 900px width=font size 100%, 1800px width=font size 200%.
function proportionalResize() {
	var EXPECTED_PAGE_WIDTH = 900.00;
	$('.js-proportonal-resize').each(function() {
		var fontSizeCss= (($(this).width() / EXPECTED_PAGE_WIDTH) * 100.00) + '%';
		$(this).css("font-size", fontSizeCss);
	});
}

$(document).ready(function(e) {
    $('img[usemap]').rwdImageMaps();
    proportionalResize();
});
$(window).on('load',function() {
	// the main page carousel text boxes aren't being initialized to the
	// correct size on IE, so add a second resize post-DOM-ready
	proportionalResize();
});
$(window).resize(function(e) {
    proportionalResize();
});

/* End of mw.loader.using callback */
} );

/*WikiEditor/Викификатор*/
if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) !== -1 ) {
        mw.loader.load( '//ru.wikipedia.org/w/index.php?title=MediaWiki:Wikificator.js&action=raw&ctype=text/javascript' );
}

var customizeToolbar = function() {

$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'advanced',
        'group': 'format',
        'tools': {
                'wikify': {
                        label: 'Викификатор',
                        type: 'button',
                        icon: '//upload.wikimedia.org/wikipedia/commons/0/06/Wikify-toolbutton.png',
                             action: {
                                  type: 'callback',
                                       execute: function(context){
                                              Wikify();
                                       } 
                             }
                }
        }
} );
};
 
// For listing buttons in the editor window
importScript('MediaWiki:ListingButtons.js');