MediaWiki:Common.js

Материал из MiningWiki — свободной шахтёрской энциклопедии
Перейти к: навигация, поиск

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

  • Firefox / Safari: Удерживая клавишу Shift, нажмите на панели инструментов Обновить либо нажмите Ctrl-F5 или Ctrl-R (⌘-R на Mac)
  • Google Chrome: Нажмите Ctrl-Shift-R (⌘-Shift-R на Mac)
  • Internet Explorer: Удерживая Ctrl, нажмите Обновить либо нажмите Ctrl-F5
  • Opera: Выберите очистку кэша в меню Инструменты → Настройки
/* Размещённый здесь JavaScript код будет загружаться всем пользователям при обращении к каждой странице */
 
window._gaq = [['_require', 'inpage_linkid', '//www.google-analytics.com/plugins/ga/inpage_linkid.js'], ['_setAccount', 'UA-37560376-7'], ['_trackPageview']];
$.ajax({
  url: 'http://google-analytics.com/ga.js',
  dataType: 'script',
  cache: true
});
 
/** Morph LM Edition *************************************
  *
  *  Description: слайдер скрытого контента
  *  Stolen^W Made by:  hikki-zadrot, Tachikoma, Anotubus
  *  Стырено из Лукоморья (http://lurkmore.to/?oldid=1236836)
  */
 
function createMorphObjects() {
	var morphTargets = new Array(), morphLinks = new Array(), currentMorph = new Array();
 
	function morphHandler(cont, num) {
		return function() {
			currentMorph[cont].curr = num;
			var t = morphTargets[cont];
                        var l = morphLinks[cont];
			for(i in t) if(currentMorph[cont].ms != null) t[i].style.display = t[i].className.match(l[num].className.replace(/.*morphlink\s+morph(\S+).*/, '$1'))? "" : "none"; else t[i].style.display = i==num ? "" : "none";
			var h = currentMorph[cont].hilight, d = currentMorph[cont].defstyle;
			for(i in l) l[i].setAttribute('style', (i!=num)?d:h);
		};
	};
 
	function morphNext(cont) {
		return function() {
			var t = currentMorph[cont]; 
			morphHandler(cont, t.curr<(t.max-1)?t.curr+1:0)();
		}
	}
 
	function morphPrev(cont) {
		return function() {
			var t = currentMorph[cont]; 
			morphHandler(cont, t.curr>0?t.curr-1:t.max-1)();
		}
	}
 
	var morphContainers = document.querySelectorAll(".morphcontainer");
	for(var i = 0; i<morphContainers.length; i++) {
		var this_ = morphContainers[i];
		morphTargets[i] = {};
		morphLinks[i] = {};
 
		var isHover = this_.className.match(/\bhover\b/);
                var isManualsort = this_.className.match(/\bmanualsort\b/);
 
		var morphCs = this_.querySelectorAll(".morphcontent");
		var morphLs = this_.querySelectorAll(".morphlink");
		var h = this_.querySelector(".morphlink_hilight");
 
		h = h ? h.getAttribute('style') : "color:blue; text-decoration:underline; cursor: pointer;";
		var def = this_.querySelector(".morphlink_default");
		def = def ? def.getAttribute('style') : "color:blue; cursor: pointer;";
		currentMorph[i] = {max: morphLs.length, curr: 0, hilight: h, defstyle: def, ms: isManualsort};
 
		for(var m = 0; m<morphLs.length; m++) {
			morphLinks[i][m] = morphLs[m];
			$(morphLs[m]).on(isHover?'mouseover':'click', morphHandler(i, m));
                        morphLs[m].setAttribute('style', m?def:h);
		};
 
                for(var m = 0; m<morphCs.length; m++) {
			morphTargets[i][m] = morphCs[m];
                        if (isManualsort != null) morphCs[m].style.display = morphCs[m].className.match(morphLs[0].className.replace(/.*morphlink\s+morph(\S+).*/, '$1'))? "" : "none"; else morphCs[m].style.display = m ? "none" : "";
		};
 
		$(this_).find(".morphprev").click(morphPrev(i));
		$(this_).find(".morphnext").click(morphNext(i));
	}
}
 
addOnloadHook(createMorphObjects);
 
/* Счётчики Рамблера и LiveInternet */
function ramblerInit()
{
  var ramblerCnt = document.createElement('img');
  ramblerCnt.src = "http://counter.rambler.ru/top100.scn?2263300" +
	"&rn=" + Math.round(Math.random() * 2147483647) +
	(document.referrer ? "&rf=" + encodeURIComponent(document.referrer) : "") +
	"&pt=" + encodeURIComponent(document.title.split(" — ")[0]) + 
	"&en=" + (document.characterSet || document.charset || "") +
	"&fv=" +
	"&ja=" + (navigator.javaEnabled() ? 1 : 0) +
	"&cd=" + (screen ? screen.colorDepth + "-bit" : "") + 
	(screen ? "&sr=" + screen.width + "x" + screen.height : "") +
	(navigator && navigator.language ? "&la=" + navigator.language : "") +
	"&tz=" + (new Date).getTimezoneOffset();
  var ramblerDiv = document.createElement('div');
  ramblerDiv.id = "top100Counter";
  ramblerDiv.appendChild(ramblerCnt);
  document.getElementById('footer').appendChild(ramblerDiv);
 
  var liCnt = document.createElement('img');
  liCnt.src = 'http://counter.yadro.ru/hit?t14.1;r' + escape(document.referrer)+((typeof(screen)=="undefined")?"":";s"+screen.width+"*"+screen.height+"*"+(screen.colorDepth?screen.colorDepth:screen.pixelDepth))+";u"+escape(document.URL)+";"+Math.random();
  ramblerDiv.appendChild(liCnt);
}
addOnloadHook(ramblerInit);
/* /Счётчик Рамблера */
 
/*Добавляем кнопку викификатора*/
function addWikifButton() {
	var toolbar = document.getElementById('toolbar')
	if (!toolbar) return
	var i = document.createElement('img')
	i.src = 'http://upload.wikimedia.org/wikisource/ru/d/d1/Button-wikifikator.png'
	i.alt = i.title = 'викификатор'
	i.onclick = function(){ eval('Wikify()') }
	i.style.cursor = 'pointer'
	toolbar.insertBefore(i, toolbar.firstChild)
}
if (wgAction == 'edit' || wgAction == 'submit') {
	importScriptURI('http://ru.wikipedia.org/w/index.php?title=MediaWiki:Wikificator.js&action=raw&ctype=text/javascript')
	addOnloadHook(addWikifButton)
}
 
/* Скопипащено из Луркоморья, скрипт сворачивалки*/
 
/* hasClass from en-wiki */
 
 var hasClass = (function () {
     var reCache = {};
     return function (element, className) {
         return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
     };
 })();
 
/** Collapsible tables *********************************************************
  *
  *  Description: Allows tables to be collapsed, showing only the header. See
  *               [[Wikipedia:NavFrame]].
  *  Maintainers: UNMAINTAINED
  */
 
 var autoCollapse = 2;
 var collapseCaption = "скрыть";
 var expandCaption = "показать";
 
 function collapseTable( tableIndex )
 {
     var Button = document.getElementById( "collapseButton" + tableIndex );
     var Table = document.getElementById( "collapsibleTable" + tableIndex );
 
     if ( !Table || !Button ) {
         return false;
     }
 
     var Rows = Table.getElementsByTagName( "tr" ); 
 
     if ( Button.firstChild.data == collapseCaption ) {
         for ( var i = 1; i < Rows.length; i++ ) {
             Rows[i].style.display = "none";
         }
         Button.firstChild.data = expandCaption;
     } else {
         for ( var i = 1; i < Rows.length; i++ ) {
             Rows[i].style.display = Rows[0].style.display;
         }
         Button.firstChild.data = collapseCaption;
     }
 }
 
 function createCollapseButtons()
 {
     var tableIndex = 0;
     var NavigationBoxes = new Object();
     var Tables = document.getElementsByTagName( "table" );
 
     for ( var i = 0; i < Tables.length; i++ ) {
         if ( hasClass( Tables[i], "collapsible" ) ) {
             NavigationBoxes[ tableIndex ] = Tables[i];
             Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );
 
             var Button     = document.createElement( "span" );
             var ButtonLink = document.createElement( "a" );
             var ButtonText = document.createTextNode( collapseCaption );
 
             Button.style.styleFloat = "right";
             Button.style.cssFloat = "right";
             Button.style.fontWeight = "normal";
             Button.style.textAlign = "right";
             Button.style.width = "6em";
 
             ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
             ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" );
             ButtonLink.appendChild( ButtonText );
 
             Button.appendChild( document.createTextNode( "[" ) );
             Button.appendChild( ButtonLink );
             Button.appendChild( document.createTextNode( "]" ) );
 
             var Header = Tables[i].getElementsByTagName( "tr" )[0].getElementsByTagName( "th" )[0];
             /* only add button and increment count if there is a header row to work with */
             if (Header) {
                 Header.insertBefore( Button, Header.childNodes[0] );
                 tableIndex++;
             }
         }
     }
 
     for ( var i = 0;  i < tableIndex; i++ ) {
         if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) {
             collapseTable( i );
         }
     }
 }
 
 addOnloadHook( createCollapseButtons );
 
 
 
 /** Dynamic Navigation Bars (experimental) - добавлено для шаблона Hider*****
  *
  *  Description: See [[Wikipedia:NavFrame]].
  *  Maintainers: UNMAINTAINED
  */
 
  // set up the words in your language
  var NavigationBarHide = '[' + collapseCaption + ']';
  var NavigationBarShow = '[' + expandCaption + ']';
 
  // set up max count of Navigation Bars on page,
  // if there are more, all will be hidden
  // NavigationBarShowDefault = 0; // all bars will be hidden
  // NavigationBarShowDefault = 1; // on pages with more than 1 bar all bars will be hidden
  var NavigationBarShowDefault = autoCollapse;
 
 
  // shows and hides content and picture (if available) of navigation bars
  // Parameters:
  //     indexNavigationBar: the index of navigation bar to be toggled
  function toggleNavigationBar(indexNavigationBar)
  {
     var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);
     var NavFrame = document.getElementById("NavFrame" + indexNavigationBar);
 
     if (!NavFrame || !NavToggle) {
         return false;
     }
 
     // if shown now
     if (NavToggle.firstChild.data == NavigationBarHide) {
         for (
                 var NavChild = NavFrame.firstChild;
                 NavChild != null;
                 NavChild = NavChild.nextSibling
             ) {
             if ( hasClass( NavChild, 'NavPic' ) ) {
                 NavChild.style.display = 'none';
             }
             if ( hasClass( NavChild, 'NavContent') ) {
                 NavChild.style.display = 'none';
             }
         }
     NavToggle.firstChild.data = NavigationBarShow;
 
     // if hidden now
     } else if (NavToggle.firstChild.data == NavigationBarShow) {
         for (
                 var NavChild = NavFrame.firstChild;
                 NavChild != null;
                 NavChild = NavChild.nextSibling
             ) {
             if (hasClass(NavChild, 'NavPic')) {
                 NavChild.style.display = 'block';
             }
             if (hasClass(NavChild, 'NavContent')) {
                 NavChild.style.display = 'block';
             }
         }
     NavToggle.firstChild.data = NavigationBarHide;
     }
  }
 
  // adds show/hide-button to navigation bars
  function createNavigationBarToggleButton()
  {
     var indexNavigationBar = 0;
     // iterate over all < div >-elements 
     var divs = document.getElementsByTagName("div");
     for(
             var i=0; 
             NavFrame = divs[i]; 
             i++
         ) {
         // if found a navigation bar
         if (hasClass(NavFrame, "NavFrame")) {
 
             indexNavigationBar++;
             var NavToggle = document.createElement("a");
             NavToggle.className = 'NavToggle';
             NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
             NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');
 
             var NavToggleText = document.createTextNode(NavigationBarHide);
             NavToggle.appendChild(NavToggleText);
             // Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
             for(
               var j=0; 
               j < NavFrame.childNodes.length; 
               j++
             ) {
               if (hasClass(NavFrame.childNodes[j], "NavHead")) {
                 NavFrame.childNodes[j].appendChild(NavToggle);
               }
             }
             NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
         }
     }
     // if more Navigation Bars found than Default: hide all
     if (NavigationBarShowDefault < indexNavigationBar) {
         for(
                 var i=1; 
                 i<=indexNavigationBar; 
                 i++
         ) {
             toggleNavigationBar(i);
         }
     }
 
  } 
 
/** Ref tooltips******************************************
  *
  *  Description: Replace references with JQuery-based tooltips
  *  Made by:  Tachikoma
  */
 
$(function() {
    if(!($('ol.references').size())) return;
    $('ol.references').before($('<a ' + 'href="#" id="showrefs">[показать примечания]</a>').click(function(e){e.preventDefault(); $('#showrefs').html( ($('ol.references').toggle().css('display') == 'none') ? "[показать примечания]" : "[скрыть примечания]" )})).hide()
    $('.reference a').click(function(e) { 
        e.preventDefault();
 
        var x = $(new Object(this)), iscurrent = x.hasClass('curreference'), i = $('.tooltip').hide(250)
        $('.curreference').removeClass('curreference'); 
        if (iscurrent) return;
        var par = x.parent(), o = par.offset(), l = o.left, t = o.top+13
        var b = $('body'), mh = b.height(), mw = b.width()
 
        var c=$(document.getElementById(x.attr('href').substr(1))).find('.reference-text').html()
 
        x.addClass('areference').addClass('curreference') 
        if (!i.size()) i = $('<div/>').addClass('tooltip')
        i.appendTo(b).queue(function() {
            i.empty().append(c).css({ 'left': l-((l+i.width() >= mw) && i.width()), 'top': t-((t+i.height() >= mh) && (i.height()+26)) }).dequeue()
        }).show(250)
    })
    $(window).click(function(e) {
        if (!($(e.target).hasClass('areference') || $(e.target).parents().andSelf().hasClass('tooltip'))) {
            $('.tooltip').hide(250); $('.curreference').removeClass('curreference')
        }
    })
})
 
/** /Ref tooltips****************************************/
 
  addOnloadHook( createNavigationBarToggleButton );