MediaWiki:Common.js — различия между версиями

Материал из roboforum.ru Wiki
Перейти к: навигация, поиск
Строка 1: Строка 1:
// <source lang="javascript">
+
//<source lang=javascript>
  
/* Execute function on page load *********************************************
+
//import module
  *
+
importedScripts = {}
  * Description: Wrapper around addOnloadHook() for backwards compatibility.
+
function importScript(page, lang) {
  *              Will be removed in the near future.
+
page = '?title=' + encodeURIComponent(page.replace(' ','_'))
  */
+
if (lang) page = 'http://' + lang + '.wikipedia.org/w/index.php' + page
 +
  else page = wgScript + page
 +
if (importedScripts[page]) return
 +
importedScripts[page] = true
 +
var s = document.createElement('script')
 +
s.type = 'text/javascript'
 +
s.src = page + '&action=raw&ctype=text/javascript'
 +
document.getElementsByTagName('head')[0].appendChild(s)
 +
}
 +
 
 +
 
 +
//hasClass, from en.wp
 +
var hasClass = (function (){
 +
  var reCache = {}
 +
  return function (element, className){
 +
  return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className)
 +
  }
 +
})()
 +
 
 +
 
 +
function addLoadEvent(f) {addOnloadHook(f)} //for backwards compatibility
 +
 
 +
 
 +
//fix for sortable tables: comma as decimal dot
 +
function ts_parseFloat(num){
 +
if (!num) return 0
 +
  num = parseFloat(num.replace(/\./g, '').replace(/,/, '.'))
 +
  return (isNaN(num) ? 0 : num)
 +
}
  
/* Чтоб была возможность изменить поведение кнопки "+" (добавление новой темы) для страниц обсуждения */
 
addOnloadHook(function(){
 
  var plus = document.getElementById('ca-addsection');
 
  if (!plus) return;
 
  var custom = document.getElementById('add-custom-section');
 
  if (!custom) return;
 
  plus.firstChild.setAttribute('href', custom.getElementsByTagName('A')[0].href);
 
})
 
/**********************************************************************************/
 
function addLoadEvent( f ) { addOnloadHook( f ); }
 
  
/** Import module *************************************************************
 
  *
 
  *  Предложен [[Участник:Alex_Smotrov]], на основе аналогичной английской функции
 
  *
 
  *  Description: Includes a raw wiki page as javascript or CSS,
 
  *              used for including user made modules.
 
  */
 
 
function importScript(page, lang) {
 
    var url = wgScriptPath + '/index.php?title='
 
                            + encodeURIComponent(page.replace(' ','_'))
 
                            + '&action=raw&ctype=text/javascript&dontcountme=s';
 
    var s = document.createElement('script');
 
    s.src = url;
 
    s.type='text/javascript';
 
    document.getElementsByTagName('head')[0].appendChild(s);
 
}
 
  
/** Internet Explorer bug fix **************************************************
+
//{Link FA}: interwiki to featured articles
  */
+
function LinkFA(){
   
+
  var pLang = document.getElementById('p-lang')
  if (window.showModalDialog && document.compatMode && document.compatMode == "CSS1Compat")
+
  if (!pLang) return
  {
+
  var iw = pLang.getElementsByTagName('li')
  var oldWidth;
+
for (var i=0; i < iw.length; i++)
  var docEl = document.documentElement;
+
   if (document.getElementById(iw[i].className+'-fa')){
+
     iw[i].className += ' FA'
  function fixIEScroll()
+
     iw[i].title = 'Эта статья является избранной в другом языковом разделе'
   {
 
    if (!oldWidth || docEl.clientWidth > oldWidth)
 
      doFixIEScroll();
 
     else
 
      setTimeout(doFixIEScroll, 1);
 
 
 
     oldWidth = docEl.clientWidth;
 
 
   }
 
   }
+
}
  function doFixIEScroll() {
 
    docEl.style.overflowX = (docEl.scrollWidth - docEl.clientWidth < 4) ? "hidden" : "";
 
  }
 
 
  document.attachEvent("onreadystatechange", fixIEScroll);
 
  attachEvent("onresize", fixIEScroll);
 
}
 
  
/** Tooltips and access keys ***************************************************
 
  */
 
ta = new Object();
 
ta["t-print"] = new Array("","Версия без кнопок, пригодная для распечатки");
 
ta["t-permalink"]          = new Array("","Ссылка на текущую версию этой статьи");
 
  
/** Interwiki links to featured articles ***************************************
+
//{ICQ}
  *
+
function icqIcons(){
  *  Описание: Ставит звёздочки для избранных иноязычных статей, а заодно и даёт картинку для статуса ICQ
+
  var a, spans = document.getElementById('content').getElementsByTagName('span')
  */
+
for (var i=0; a = spans[i]; i++)
+
  if (a.className == 'ICQ')  
function LinkFA()  
+
    a.style.backgroundImage = "url('http://status.icq.com/online.gif?icq="+a.id+"&img=5&randseed="+Math.floor(Math.random()*10000000)+"')"
  {
+
}
  // iterate over all span-elements
 
  for(var i=0; a = document.getElementsByTagName("span")[i]; i++) {
 
      // if found a ICQ span
 
      if(a.className == "ICQ") {
 
            a.style.padding = "0 0 0 20px";
 
            a.style.backgroundImage = "url('http://status.icq.com/online.gif?icq="+a.id+"&img=5')";
 
            a.style.backgroundRepeat = "no-repeat";
 
      }
 
      // if found a FA span
 
      if(a.className == "FA") {
 
        // iterate over all li-elements
 
        for(var j=0; b = document.getElementsByTagName("li")[j]; j++) {
 
            // if found a FA link
 
            if(b.className == "interwiki-" + a.id) {
 
                b.className += " FA"
 
                b.title = "Эта статья является избранной в другом языковом разделе.";             
 
            }
 
        }
 
      }
 
  }
 
}
 
 
addOnloadHook( LinkFA );
 
  
/* меняет текст вкладки «статья» на «заглавная», когда надо */
 
  
addOnloadHook(function(){
+
//{Modifynewsectionlink}
  if(wgArticleId==4401||wgArticleId==23){var nstabmain=document.getElementById('ca-nstab-main').firstChild;if(nstabmain.textContent){nstabmain.textContent='заглавная'}else{nstabmain.innerText='заглавная'};}
+
function newSectionLink(){
});
+
var plus = document.getElementById('ca-addsection')
 +
if (!plus) return
 +
var custom = document.getElementById('add-custom-section')
 +
if (!custom) return
 +
plus.firstChild.setAttribute('href', custom.getElementsByTagName('A')[0].href)
 +
}
  
/* hasClass from en-wiki */
 
  
var hasClass = (function () {
+
//{Неверный заголовок}
    var reCache = {};
+
function correctTitle(){
    return function (element, className) {
+
if (window.disableRealTitle) return
        return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
+
var toHide = document.getElementById('trestrictions_replace')
    };
+
if (!toHide) return
  })();
+
var newTitle = document.getElementById('trestrictions_correct')
 +
if (!newTitle) return
 +
document.getElementsByTagName('h1')[0].innerHTML  = newTitle.innerHTML
 +
toHide.style.display = 'none'
 +
  document.getElementById('trestrictions_replaced').style.display = 'block'
 +
}
  
/** Collapsible tables *********************************************************
 
  *
 
  *  Description: Allows tables to be collapsed, showing only the header. See
 
  *              [[Wikipedia:NavFrame]].
 
  *  Maintainers: [[User:R. Koot]]
 
  */
 
 
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) *************************************
+
//[edit] zero section
  *
+
function editZeroSection(){
  *  Description: See [[Wikipedia:NavFrame]].
+
var body = document.getElementById('bodyContent')
  *  Maintainers: UNMAINTAINED
+
if (!body || window.disable_zero_section) return
  */
+
var h2s = body.getElementsByTagName('H2')
+
var h2 = h2s[0]
  // set up the words in your language
+
if (!h2) return
  var NavigationBarHide = '[' + collapseCaption + ']';
+
if (h2.parentNode.id == 'toctitle') h2 = h2s[1]
  var NavigationBarShow = '[' + expandCaption + ']';
+
if (!h2) return
 
+
var span = h2.firstChild
  // set up max count of Navigation Bars on page,
+
if (!span || span.className != 'editsection') return
  // if there are more, all will be hidden
+
var zero = span.cloneNode(true)
  // NavigationBarShowDefault = 0; // all bars will be hidden
+
body.insertBefore(zero, body.firstChild)
  // NavigationBarShowDefault = 1; // on pages with more than 1 bar all bars will be hidden
+
var a = zero.getElementsByTagName('a')[0]
  var NavigationBarShowDefault = autoCollapse;
+
a.title = a.title.replace(/:.*$/,': 0')
 
+
a.setAttribute('href', a.href.replace(/&section=1/,'&section=0'))
 
+
}
  // 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);
 
        }
 
    }
 
 
 
  }
 
 
 
  addOnloadHook( createNavigationBarToggleButton );
 
  
/** Ed's counter ***********************************************************
 
*
 
*/
 
 
var disable_counter = 1;
 
function count_me()
 
{
 
if(disable_counter != 1 && window.location.href.match("^http://ru.wikipedia.org/wiki/") && !window.location.href.substring(7).match(":"))
 
 
{
 
var rnd = Math.random() > 0.1 ? 1 : 0;
 
if(rnd == 0 || (document.referrer && !document.referrer.match("(wikipedia.org|wiktionary.org|wikiquote.org|wikisource.org|wikimedia.org|yandex.ru|google.ru|google.com)")))
 
{
 
var img = new Image();
 
img.src = "http://tools.wikimedia.de:22902/" + (rnd == 0 ? "1" : "0") + document.referrer;
 
}
 
}
 
}
 
count_me();
 
  
/** Делаем ссылку "править" для нулевой секции *****************************************<nowiki>
+
//Mainpage: tab «статья» -> «заглавная»
*/
+
function mainPageTab(){
  var disable_zero_section = 0;
+
  if (wgArticleId == 4401 || wgArticleId == 23){
function edit_zero_section()
+
  var nstab = document.getElementById('ca-nstab-main')
  {
+
  if (!nstab || wgUserLanguage != 'ru') return //other skins
  var body = document.getElementById ('bodyContent');
+
  var a = nstab.firstChild
+
  if (a.textContent) a.textContent = 'Заглавная'
  if (disable_zero_section != 1 && body.innerHTML.match ('class="editsection"')) {
+
  else a.innerText = 'Заглавная'
    var title = document.title.substr (0, document.title.lastIndexOf (' — '));
 
 
    if (typeof encodeURIComponent == 'function')
 
      title = encodeURIComponent (title);
 
 
    body.innerHTML = '<div class="editsection" id="ca-edit-0">[<a href="http://ru.wikipedia.org/w/index.php?title=' + title + '&amp;action=edit&amp;section=0">править</a>]</div>' + body.innerHTML;
 
  }
 
 
  }
 
  }
+
}
addOnloadHook(edit_zero_section);
+
 
  
/*</nowiki>*/
 
  
/** Расширенный поиск *****************************************<nowiki>
+
//Collapsible Tables and Divs, [[ВП:СБ]]
** Автор: ru:User:Не А
 
*/
 
function SpecialSearchEnhanced()
 
{
 
    var mainNode = document.getElementsByTagName("form");
 
    if (!mainNode) return;
 
   
 
    var searchValue = document.forms[0].search.value
 
var safeSearchValue = searchValue.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
 
    var firstForm = mainNode[0];
 
  
    var node = document.createElement('div');
+
var autoCollapse = 2
   
+
var collapseCaption = 'скрыть'
    var googleSearch  = '<form action="http://www.google.com/custom" method="get" name="google" target="_blank" id="google">';
+
var expandCaption = 'показать'
    googleSearch += '<input type="hidden" name="hl" value="ru" />';
 
    googleSearch += '<input type="hidden" name="domains" value="ru.wikipedia.org" />';
 
    googleSearch += '<input type="hidden" name="q" maxlength="2048" value="' + safeSearchValue + '" />'
 
    googleSearch += '<input type="hidden" name="sitesearch" value="ru.wikipedia.org" />'
 
    googleSearch += '<input type="button" value="Google по Википедии" onclick="document.google.q.value = document.forms[0].search.value; this.form.submit();" style="width: 12em;" />'
 
    googleSearch += '</form>'
 
   
 
    var yandexSearch  = '<form action="http://www.yandex.ru/yandsearch" method="get" name="yandex" target="_blank" id="yandex">';
 
    yandexSearch += '<input type="hidden" name="text" maxlength="300" value="' + safeSearchValue + '" />';
 
    yandexSearch += '<input type="hidden" name="site" value="ru.wikipedia.org" />';
 
    yandexSearch += '<input type="hidden" name="ras" value="1" />'
 
    yandexSearch += '<input type="hidden" name="site_manually"  value="true" />'
 
    yandexSearch += '<input type="hidden" name="server_name" value="Википедия" />'
 
    yandexSearch += '<input type="button" value="Яндекс по Википедии"  onclick="document.yandex.text.value = document.forms[0].search.value; this.form.submit();" style="width: 12em;" />'
 
    yandexSearch += '</form>'
 
  
    node.innerHTML = node.innerHTML + '<table style="margin-left: 75%; padding-left:4px;"><tr><td>' + yandexSearch + '</td></tr><tr><td>' + googleSearch + '</td></tr></table>';
+
function collapsibleTables(){
       
+
var Table, HRow, THs, Header, btn, a, tblIdx = 0, colTables = []
    firstForm.parentNode.insertBefore(node, firstForm.nextSibling);
+
var allTables = document.getElementsByTagName('table')
 +
for (var i=0; Table = allTables[i]; i++){
 +
  if (!hasClass(Table, 'collapsible')) continue
 +
  if (!(HRow = Table.rows[0])) continue
 +
  THs = HRow.getElementsByTagName('th')
 +
  if (THs.length == 0) continue
 +
  Header = THs[THs.length-1] //last TH, not 1st like in en.wp
 +
  Table.id = 'collapsibleTable' + tblIdx
 +
  btn = document.createElement('span')
 +
  btn.style.styleFloat = btn.style.cssFloat = 'right'
 +
  btn.style.fontWeight = 'normal'
 +
  a = document.createElement('a')
 +
  a.id = 'collapseButton' + tblIdx
 +
  a.href = 'javascript:collapseTable(' + tblIdx + ');'
 +
  a.appendChild(document.createTextNode(collapseCaption))
 +
  btn.appendChild(document.createTextNode('['))
 +
  btn.appendChild(a)
 +
  btn.appendChild(document.createTextNode(']'))
 +
  Header.insertBefore(btn, Header.childNodes[0])
 +
  colTables[tblIdx++] = Table
 
  }
 
  }
 +
for (var i=0; i < tblIdx; i++)
 +
  if ((tblIdx > autoCollapse && hasClass(colTables[i], 'autocollapse')) || hasClass(colTables[i], 'collapsed'))
 +
    collapseTable(i)
 +
}
  
  if (wgPageName == "Служебная:Search") { addOnloadHook(SpecialSearchEnhanced); }
+
function collapseTable (idx){
 +
var Table = document.getElementById('collapsibleTable' + idx)
 +
var btn = document.getElementById('collapseButton' + idx)
 +
  if (!Table || !btn) return false
 +
var Rows = Table.rows
 +
var isShown = (btn.firstChild.data == collapseCaption)
 +
btn.firstChild.data = isShown ?  expandCaption : collapseCaption
 +
var disp = isShown ? 'none' : Rows[0].style.display
 +
for (var i=1; i < Rows.length; i++)  
 +
    Rows[i].style.display = disp
 +
}
  
/*</nowiki>*/
+
var NavigationBarHide = '[' + collapseCaption + ']'
 
+
var NavigationBarShow = '[' + expandCaption + ']'
/** "Technical restrictions" title fix *****************************************
+
var NavigationBarShowDefault = autoCollapse
  */
 
 
// For pages that have something like Template:Lowercase, replace the title, but only if it is cut-and-pasteable as a valid wikilink.
 
// (for instance [[iPod]]'s title is updated.  <nowiki>But [[C#]] is not an equivalent wikilink, so [[C Sharp]] doesn't have its main title changed)</nowiki>
 
//
 
// The function looks for a banner like this: <nowiki>
 
// <div id="RealTitleBanner">    <!-- div that gets hidden -->
 
//  <span id="RealTitle">title</span>
 
// </div>
 
// </nowiki>An element with id=DisableRealTitle disables the function.
 
 
// similar to innerHTML, but only returns the text portions of the insides, excludes HTML
 
function pickUpText(aParentElement) {
 
  var str = "";
 
 
   
 
   
  function pickUpTextInternal(aElement) {
+
function collapsibleDivs(){
    var child = aElement.firstChild;
+
var navIdx = 0, colNavs = [], i, NavFrame
    while (child) {
+
var divs = document.getElementById('content').getElementsByTagName('div')
      if (child.nodeType == 1)         // ELEMENT_NODE
+
for (i=0; NavFrame = divs[i]; i++) {
        pickUpTextInternal(child);
+
  if (!hasClass(NavFrame, 'NavFrame')) continue
      else if (child.nodeType == 3)     // TEXT_NODE
+
  NavFrame.id = 'NavFrame' + navIdx
        str += child.nodeValue;
+
  var a = document.createElement('a')
+
  a.className = 'NavToggle'
      child = child.nextSibling;
+
  a.id = 'NavToggle' + navIdx
    }
+
  a.href = 'javascript:collapseDiv(' + navIdx + ');'
  }
+
  a.appendChild(document.createTextNode(NavigationBarHide))
+
  // Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
  pickUpTextInternal(aParentElement);
+
  for (var j=0; j < NavFrame.childNodes.length; j++)
+
    if (hasClass(NavFrame.childNodes[j], 'NavHead'))
  return str;
+
      NavFrame.childNodes[j].appendChild(a)
 +
  colNavs[navIdx++] = NavFrame
 
  }
 
  }
   
+
  for (i=0; i < navIdx; i++)
var disableRealTitle = 0; // users can disable this by making this true from their monobook.js
+
  if ((navIdx > NavigationBarShowDefault && !hasClass(colNavs[i], 'expanded')) || hasClass(colNavs[i], 'collapsed'))
addOnloadHook(function() {
+
    collapseDiv(i)
try {
+
}
var realTitleBanner = document.getElementById("RealTitleBanner");
 
if (realTitleBanner && !document.getElementById("DisableRealTitle") && !disableRealTitle) {
 
var realTitle = document.getElementById("RealTitle");
 
if (realTitle) {
 
var realTitleHTML = realTitle.innerHTML;
 
realTitleText = pickUpText(realTitle);
 
 
var isPasteable = 0;
 
//var containsHTML = /</.test(realTitleHTML); // contains ANY HTML
 
var containsTooMuchHTML = /</.test( realTitleHTML.replace(/<\/?(sub|sup|small|big)>/gi, "") ); // contains HTML that will be ignored when cut-n-pasted as a wikilink
 
// calculate whether the title is pasteable
 
var verifyTitle = realTitleText.replace(/^ +/, ""); // trim left spaces
 
verifyTitle = verifyTitle.charAt(0).toUpperCase() + verifyTitle.substring(1, verifyTitle.length); // uppercase first character
 
 
// if the namespace prefix is there, remove it on our verification copy.  If it isn't there, add it to the original realValue copy.
 
if (wgNamespaceNumber != 0) {
 
if (wgCanonicalNamespace == verifyTitle.substr(0, wgCanonicalNamespace.length).replace(/ /g, "_") && verifyTitle.charAt(wgCanonicalNamespace.length) == ":") {
 
verifyTitle = verifyTitle.substr(wgCanonicalNamespace.length + 1);
 
} else {
 
realTitleText = wgCanonicalNamespace.replace(/_/g, " ") + ":" + realTitleText;
 
realTitleHTML = wgCanonicalNamespace.replace(/_/g, " ") + ":" + realTitleHTML;
 
}
 
}
 
 
// verify whether wgTitle matches
 
verifyTitle = verifyTitle.replace(/^ +/, "").replace(/ +$/, ""); // trim left and right spaces
 
verifyTitle = verifyTitle.replace(/_/g, " "); // underscores to spaces
 
verifyTitle = verifyTitle.charAt(0).toUpperCase() + verifyTitle.substring(1, verifyTitle.length); // uppercase first character
 
isPasteable = (verifyTitle == wgTitle);
 
 
var h1 = document.getElementsByTagName("h1")[0];
 
if (h1 && isPasteable) {
 
h1.innerHTML = containsTooMuchHTML ? realTitleText : realTitleHTML;
 
if (!containsTooMuchHTML)
 
realTitleBanner.style.display = "none";
 
}
 
document.title = realTitleText + " — Википедия";
 
}
 
}
 
} catch (e) {
 
/* Something went wrong. */
 
}
 
});
 
  
  /* Замена неправильного заголовка правильным by SergV *****************************************
+
function collapseDiv(idx) {
  */
+
  var div = document.getElementById('NavFrame' + idx)
 
+
  var btn = document.getElementById('NavToggle' + idx)
  // Все неправильные заголовки
+
if (!div || !btn) return false
  title_restr_alerts = ["trestrictions_replace", "trestrictions_alert"];
+
var isShown = (btn.firstChild.data == NavigationBarHide)
 +
btn.firstChild.data = isShown ? NavigationBarShow : NavigationBarHide
 +
var disp = isShown ? 'none' : 'block'
 +
for (var child = div.firstChild;  child != null;  child = child.nextSibling)
 +
  if (hasClass(child, 'NavPic') || hasClass(child, 'NavContent'))
 +
      child.style.display = disp
 +
}
  
  // Только шаблон title
+
//[[Special:Search]] extended
  //title_restr_alerts = ["trestrictions_replace"];
+
function searchPage() {
 
+
var search = document.forms['search']
  function display_correct_title () {
+
if (!search) return
    var title_restr_alert1, a1;
+
var div = document.createElement('div')
    if (document.getElementsByTagName && document.getElementById) {  
+
  div.innerHTML = '\
      for(var i=0; i < title_restr_alerts.length; i++) {
+
<table style="margin-left:75%;padding-left:4px;"><tr><td>\
        title_restr_alert1 = title_restr_alerts[i];
+
<form action="http://www.yandex.ru/yandsearch" name="yandex" target="_blank" id="yandex">\
        a1 = document.getElementById(title_restr_alert1);
+
<input type="hidden" name="text">\
        if(a1) {
+
<input type="hidden" name="site" value="ru.wikipedia.org">\
          ct = document.getElementById("trestrictions_correct");
+
<input type="hidden" name="ras" value="1">\
          if(ct) {
+
<input type="hidden" name="site_manually"  value="true">\
            document.getElementsByTagName("h1")[0].innerHTML  = ct.innerHTML;
+
<input type="hidden" name="server_name" value="Википедия">\
            a1.style.display = "none";
+
<input type="button" value="Яндекс по Википедии"  onclick="document.yandex.text.value = document.forms[0].search.value; this.form.submit();" style="width:12em;">\
            document.getElementById("trestrictions_replaced").style.display = "block";
+
</form></td></tr><tr><td>\
          }
+
<form action="http://www.google.com/custom" method="get" name="google" target="_blank" id="google">\
          break;
+
<input type="hidden" name="hl" value="ru">\
        }
+
<input type="hidden" name="domains" value="ru.wikipedia.org">\
      }
+
<input type="hidden" name="q">\
    }
+
<input type="hidden" name="sitesearch" value="ru.wikipedia.org">\
   }
+
<input type="button" value="Google по Википедии" onclick="document.google.q.value = document.forms[0].search.value; this.form.submit();" style="width:12em;">\
 
+
</form></td></tr></table>'
addOnloadHook(display_correct_title);
+
   search.parentNode.insertBefore(div, search.nextSibling)
 +
}
  
/* Другое  *****************************************
 
*/
 
window.przyciskiOpisDone = false;
 
var auto_comment = 0;
 
  
/* подгрузка файла со скриптами для редактирования  *****************************************
+
//[[Special:Upload]]: insert {Изображение} automatically, insert {Обоснование добросовестного использования} with click
*/
 
if (document.URL.indexOf("action=edit") > 0 || document.URL.indexOf("action=submit") > 0)
 
{
 
        if (wgCanonicalNamespace != "Special")
 
        {
 
                document.write('<script type="text/javascript" src="/w/index.php?title=MediaWiki:Onlyifediting.js&action=raw&ctype=text/javascript&dontcountme=s"></script>');
 
        }
 
}
 
 
 
/* При загрузке [[Special:Upload]] вставляет в поле описания [[Шаблон:Изображение]]
 
    По ссылке добавляет в поле [[Шаблон:Обоснование добросовестного использования]] и увеличивает размер поля
 
    Автор - [[User:Alex Smotrov]]
 
*/
 
 
function uploadPage(){
 
function uploadPage(){
//автоматически вставить {Изображение}
 
 
  var desc = document.getElementById('wpUploadDescription')
 
  var desc = document.getElementById('wpUploadDescription')
  var temp = document.getElementById('imageinfo')
+
  var tmpl = document.getElementById('imageinfo')
  if (temp && desc && !desc.value) desc.value = temp.innerHTML
+
  if (tmpl && desc && !desc.value) desc.value = tmpl.innerHTML
//создать ссылку для вставки {Обоснование}
 
 
  var span = document.getElementById('insertlink')
 
  var span = document.getElementById('insertlink')
 
  if (!span) return
 
  if (!span) return
Строка 533: Строка 237:
 
  span.style.display = 'inline'
 
  span.style.display = 'inline'
 
}
 
}
 
 
function addRationaleTemplate(){
 
function addRationaleTemplate(){
 
  var desc = document.getElementById('wpUploadDescription')
 
  var desc = document.getElementById('wpUploadDescription')
  var temp = document.getElementById('rationale')
+
  var tmpl = document.getElementById('rationale')
  if(!desc || !temp) return
+
  if (desc && tmpl && desc.value.indexOf(tmpl.innerHTML.substring(0,8)) == -1){
if (desc.value.indexOf(temp.innerHTML.substring(0,8)) == -1){
+
   desc.value += '\n' + tmpl.innerHTML
   desc.value += '\n' + temp.innerHTML
 
 
   desc.rows = 15
 
   desc.rows = 15
 
  }
 
  }
 
}
 
}
  
if (wgCanonicalNamespace == 'Special' && wgCanonicalSpecialPageName == 'Upload')
 
addOnloadHook(uploadPage);
 
  
// add resmark
 
importScript('MediaWiki:Resmark.js');
 
  
// </source>
+
//Load functions on special pages
 +
if (wgCanonicalNamespace == 'Special'){
 +
  if (wgCanonicalSpecialPageName == 'Upload')
 +
    addOnloadHook(uploadPage)
 +
  else if  (wgCanonicalSpecialPageName == 'Search')
 +
    addOnloadHook(searchPage)
 +
 
 +
//Load functions on normal pages
 +
}else if (wgAction != 'history'){
 +
  addOnloadHook(editZeroSection)
 +
  addOnloadHook(collapsibleDivs)
 +
  addOnloadHook(collapsibleTables)
 +
  addOnloadHook(correctTitle)
 +
  addOnloadHook(mainPageTab)
 +
  document.write('<script type="text/javascript" src="http://meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript&smaxage=21600&maxage=86400"><\/script>')
 +
  if (wgNamespaceNumber == 0)
 +
    addOnloadHook(LinkFA)
 +
  else{
 +
    addOnloadHook(icqIcons)
 +
    addOnloadHook(newSectionLink)
 +
  }
 +
if (wgAction == 'edit' || wgAction == 'submit' || wgAction == 'editredlink')
 +
  document.write('<script type="text/javascript" src="http://ru.wikipedia.org/w/index.php?title=MediaWiki:Editpage.js&action=raw&ctype=text/javascript"><\/script>')
 +
 +
 
 +
if (navigator.appName == 'Microsoft Internet Explorer')
 +
addOnloadHook(function(){
 +
  if (!window.IEFixesDisabled) importScript('MediaWiki:IEFixes.js')
 +
})
 +
 
 +
//</source>

Версия 18:14, 8 марта 2008

//<source lang=javascript>

//import module
importedScripts = {} 
function importScript(page, lang) {
 page = '?title=' + encodeURIComponent(page.replace(' ','_'))
 if (lang) page = 'http://' + lang + '.wikipedia.org/w/index.php' + page
 else page = wgScript + page
 if (importedScripts[page]) return
 importedScripts[page] = true
 var s = document.createElement('script')
 s.type = 'text/javascript'
 s.src = page + '&action=raw&ctype=text/javascript'
 document.getElementsByTagName('head')[0].appendChild(s)
}


//hasClass, from en.wp
var hasClass = (function (){
 var reCache = {}
 return function (element, className){
   return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className)
  }
})()


function addLoadEvent(f) {addOnloadHook(f)} //for backwards compatibility


//fix for sortable tables: comma as decimal dot
function ts_parseFloat(num){
 if (!num) return 0
 num = parseFloat(num.replace(/\./g, '').replace(/,/, '.'))
 return (isNaN(num) ? 0 : num)
}



//{Link FA}: interwiki to featured articles
function LinkFA(){
 var pLang = document.getElementById('p-lang')
 if (!pLang) return
 var iw = pLang.getElementsByTagName('li')
 for (var i=0; i < iw.length; i++)
   if (document.getElementById(iw[i].className+'-fa')){
     iw[i].className += ' FA'
     iw[i].title = 'Эта статья является избранной в другом языковом разделе'
   }
}


//{ICQ}
function icqIcons(){
 var a, spans = document.getElementById('content').getElementsByTagName('span')
 for (var i=0; a = spans[i]; i++)
   if (a.className == 'ICQ') 
     a.style.backgroundImage = "url('http://status.icq.com/online.gif?icq="+a.id+"&img=5&randseed="+Math.floor(Math.random()*10000000)+"')"
}


//{Modifynewsectionlink}
function newSectionLink(){
 var plus = document.getElementById('ca-addsection')
 if (!plus) return
 var custom = document.getElementById('add-custom-section')
 if (!custom) return
 plus.firstChild.setAttribute('href', custom.getElementsByTagName('A')[0].href)
}


//{Неверный заголовок} 
function correctTitle(){
 if (window.disableRealTitle) return
 var toHide = document.getElementById('trestrictions_replace')
 if (!toHide) return
 var newTitle = document.getElementById('trestrictions_correct')
 if (!newTitle) return
 document.getElementsByTagName('h1')[0].innerHTML  = newTitle.innerHTML
 toHide.style.display = 'none'
 document.getElementById('trestrictions_replaced').style.display = 'block'
}


//[edit] zero section
function editZeroSection(){
 var body = document.getElementById('bodyContent')
 if (!body || window.disable_zero_section) return
 var h2s = body.getElementsByTagName('H2')
 var h2 = h2s[0]
 if (!h2) return
 if (h2.parentNode.id == 'toctitle') h2 = h2s[1]
 if (!h2) return
 var span = h2.firstChild
 if (!span || span.className != 'editsection') return
 var zero = span.cloneNode(true)
 body.insertBefore(zero, body.firstChild)
 var a = zero.getElementsByTagName('a')[0]
 a.title = a.title.replace(/:.*$/,': 0')
 a.setAttribute('href', a.href.replace(/&section=1/,'&section=0'))
}


//Mainpage: tab  «статья» -> «заглавная» 
function mainPageTab(){
 if (wgArticleId == 4401 || wgArticleId == 23){
  var nstab = document.getElementById('ca-nstab-main')
  if (!nstab || wgUserLanguage != 'ru') return //other skins
  var a = nstab.firstChild
  if (a.textContent) a.textContent = 'Заглавная'
  else a.innerText = 'Заглавная'
 }
}



//Collapsible Tables and Divs, [[ВП:СБ]]

var autoCollapse = 2
var collapseCaption = 'скрыть'
var expandCaption = 'показать'

function collapsibleTables(){
 var Table, HRow, THs, Header, btn, a, tblIdx = 0, colTables = []
 var allTables = document.getElementsByTagName('table')
 for (var i=0; Table = allTables[i]; i++){
   if (!hasClass(Table, 'collapsible')) continue
   if (!(HRow = Table.rows[0])) continue
   THs = HRow.getElementsByTagName('th') 
   if (THs.length == 0) continue
   Header = THs[THs.length-1] //last TH, not 1st like in en.wp
   Table.id = 'collapsibleTable' + tblIdx
   btn = document.createElement('span')
   btn.style.styleFloat = btn.style.cssFloat = 'right'
   btn.style.fontWeight = 'normal'
   a = document.createElement('a')
   a.id = 'collapseButton' + tblIdx
   a.href = 'javascript:collapseTable(' + tblIdx + ');' 
   a.appendChild(document.createTextNode(collapseCaption))
   btn.appendChild(document.createTextNode('['))
   btn.appendChild(a)
   btn.appendChild(document.createTextNode(']'))
   Header.insertBefore(btn, Header.childNodes[0])
   colTables[tblIdx++] = Table
 }
 for (var i=0; i < tblIdx; i++)
   if ((tblIdx > autoCollapse && hasClass(colTables[i], 'autocollapse')) || hasClass(colTables[i], 'collapsed'))
     collapseTable(i)
}

function collapseTable (idx){
 var Table = document.getElementById('collapsibleTable' + idx)
 var btn = document.getElementById('collapseButton' + idx)
 if (!Table || !btn) return false
 var Rows = Table.rows
 var isShown = (btn.firstChild.data == collapseCaption)
 btn.firstChild.data = isShown ?  expandCaption : collapseCaption
 var disp = isShown ? 'none' : Rows[0].style.display
 for (var i=1; i < Rows.length; i++) 
    Rows[i].style.display = disp
}

var NavigationBarHide = '[' + collapseCaption + ']'
var NavigationBarShow = '[' + expandCaption + ']'
var NavigationBarShowDefault = autoCollapse
 
function collapsibleDivs(){
 var navIdx = 0, colNavs = [], i, NavFrame
 var divs = document.getElementById('content').getElementsByTagName('div')
 for (i=0; NavFrame = divs[i]; i++) {
   if (!hasClass(NavFrame, 'NavFrame')) continue
   NavFrame.id = 'NavFrame' + navIdx
   var a = document.createElement('a')
   a.className = 'NavToggle'
   a.id = 'NavToggle' + navIdx
   a.href = 'javascript:collapseDiv(' + navIdx + ');'
   a.appendChild(document.createTextNode(NavigationBarHide))
   // 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(a)
   colNavs[navIdx++] = NavFrame
 }
 for (i=0; i < navIdx; i++)
  if ((navIdx > NavigationBarShowDefault && !hasClass(colNavs[i], 'expanded')) || hasClass(colNavs[i], 'collapsed'))
     collapseDiv(i)
}

function collapseDiv(idx) {
 var div = document.getElementById('NavFrame' + idx)
 var btn = document.getElementById('NavToggle' + idx)
 if (!div || !btn) return false
 var isShown = (btn.firstChild.data == NavigationBarHide)
 btn.firstChild.data = isShown ? NavigationBarShow : NavigationBarHide 
 var disp = isShown ? 'none' : 'block'
 for (var child = div.firstChild;  child != null;  child = child.nextSibling)
   if (hasClass(child, 'NavPic') || hasClass(child, 'NavContent')) 
      child.style.display = disp
}

//[[Special:Search]] extended
function searchPage() {
 var search = document.forms['search']
 if (!search) return
 var div = document.createElement('div')
 div.innerHTML = '\
<table style="margin-left:75%;padding-left:4px;"><tr><td>\
<form action="http://www.yandex.ru/yandsearch" name="yandex" target="_blank" id="yandex">\
<input type="hidden" name="text">\
<input type="hidden" name="site" value="ru.wikipedia.org">\
<input type="hidden" name="ras" value="1">\
<input type="hidden" name="site_manually"  value="true">\
<input type="hidden" name="server_name" value="Википедия">\
<input type="button" value="Яндекс по Википедии"  onclick="document.yandex.text.value = document.forms[0].search.value; this.form.submit();" style="width:12em;">\
</form></td></tr><tr><td>\
<form action="http://www.google.com/custom" method="get" name="google" target="_blank" id="google">\
<input type="hidden" name="hl" value="ru">\
<input type="hidden" name="domains" value="ru.wikipedia.org">\
<input type="hidden" name="q">\
<input type="hidden" name="sitesearch" value="ru.wikipedia.org">\
<input type="button" value="Google по Википедии" onclick="document.google.q.value = document.forms[0].search.value; this.form.submit();" style="width:12em;">\
</form></td></tr></table>'
  search.parentNode.insertBefore(div, search.nextSibling)
}


//[[Special:Upload]]: insert {Изображение} automatically, insert {Обоснование добросовестного использования} with click
function uploadPage(){
 var desc = document.getElementById('wpUploadDescription')
 var tmpl = document.getElementById('imageinfo')
 if (tmpl && desc && !desc.value) desc.value = tmpl.innerHTML
 var span = document.getElementById('insertlink')
 if (!span) return
 var a = document.createElement('a')
 a.href = 'javascript:addRationaleTemplate()'
 span.parentNode.insertBefore(a, span)
 a.appendChild(span)
 span.style.display = 'inline'
}
function addRationaleTemplate(){
 var desc = document.getElementById('wpUploadDescription')
 var tmpl = document.getElementById('rationale')
 if (desc && tmpl && desc.value.indexOf(tmpl.innerHTML.substring(0,8)) == -1){
   desc.value += '\n' + tmpl.innerHTML
   desc.rows = 15
 }
}



//Load functions on special pages
if (wgCanonicalNamespace == 'Special'){
  if (wgCanonicalSpecialPageName == 'Upload')
    addOnloadHook(uploadPage)
  else if  (wgCanonicalSpecialPageName == 'Search')
    addOnloadHook(searchPage)

//Load functions on normal pages
}else if (wgAction != 'history'){
  addOnloadHook(editZeroSection)
  addOnloadHook(collapsibleDivs)
  addOnloadHook(collapsibleTables)
  addOnloadHook(correctTitle)
  addOnloadHook(mainPageTab)
  document.write('<script type="text/javascript" src="http://meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript&smaxage=21600&maxage=86400"><\/script>')
  if (wgNamespaceNumber == 0)
    addOnloadHook(LinkFA)
  else{
    addOnloadHook(icqIcons)
    addOnloadHook(newSectionLink)
  }
 if (wgAction == 'edit' || wgAction == 'submit' || wgAction == 'editredlink')
   document.write('<script type="text/javascript" src="http://ru.wikipedia.org/w/index.php?title=MediaWiki:Editpage.js&action=raw&ctype=text/javascript"><\/script>')
}  

if (navigator.appName == 'Microsoft Internet Explorer') 
 addOnloadHook(function(){
  if (!window.IEFixesDisabled) importScript('MediaWiki:IEFixes.js')
})

//</source>