Материал из Портал винтажной CD-аудиотехники

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

Перейти к: навигация, поиск
Строка 1: Строка 1:
/* Размещённый здесь код JavaScript будет загружаться пользователям при обращении к каждой странице */
+
importMW = function (name) { importScript('MediaWiki:'+name+'.js') }
 
+
importScript_ = importScript
 
+
//Messages
/**
+
var zeroSectionTip = 'Править введение'
  * Dynamic Navigation Bars. See [[Wikipedia:NavFrame]]
+
var NavigationBarHide = '[скрыть]'
  *
+
var NavigationBarShow = '[показать]'
  * Based on script from en.wikipedia.org, 2008-09-15.
+
var NavigationBarShowDefault = 2
  *
+
if( /^en$/.test(wgUserLanguage) ) importMW('Common-' + wgUserLanguage)
  * @source www.mediawiki.org/wiki/MediaWiki:Gadget-NavFrame.js
+
function LinkFA(){
  * @maintainer Helder.wiki, 2012–2013
+
var ll, s
  * @maintainer Krinkle, 2013
+
  $('#p-lang li').each( function(i, iw){
*/
+
  ll = iw.className.split(' ')[0] + '-'
( function () {
+
  for( var s in listFA )
   
+
    if( document.getElementById(ll + s) )
// Set up the words in your language
+
      $( iw )
var collapseCaption = 'hide';
+
        .addClass( s.toUpperCase() )
var expandCaption = 'show';
+
        .attr( 'title',  listFA[s] + textFA )
+
  })
var navigationBarHide = '[' + collapseCaption + ']';
+
}
var navigationBarShow = '[' + expandCaption + ']';
+
function editZeroSection(){
+
  if( !wgArticleId ) return
/**
+
mw.util.$content.find('h2')
* Shows and hides content and picture (if available) of navigation bars.
+
  .children('span.editsection').first()
*
+
  .clone().prependTo(mw.util.$content)
  * @param {number} indexNavigationBar The index of navigation bar to be toggled
+
.find('a')
  * @param {jQuery.Event} e Event object
+
  .attr('title', zeroSectionTip)
*/
+
  .attr('href', wgScript + '?title='+encodeURIComponent(wgPageName) + '&action=edit&section=0' )
function toggleNavigationBar( indexNavigationBar, e ) {
+
}
        var navChild,
+
//Collapsiblе
                navToggle = document.getElementById( 'NavToggle' + indexNavigationBar ),
+
var hasClass = (function (){
                navFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
+
  var reCache = {}
+
return function (element, className){
        // Prevent browser from jumping to href "#"
+
  return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className)
        e.preventDefault();
+
  }
   
+
})()
        if ( !navFrame || !navToggle ) {
+
function collapsibleTables(){
                return false;
+
var Table, HRow,  HCell, btn, a, tblIdx = 0, colTables = []
        }
+
var allTables = document.getElementsByTagName('table')
   
+
for (var i=0; Table = allTables[i]; i++){
        // If shown now
+
  if (!hasClass(Table, 'collapsible')) continue
        if ( navToggle.firstChild.data == navigationBarHide ) {
+
  if (!(HRow=Table.rows[0])) continue
                for ( navChild = navFrame.firstChild; navChild != null; navChild = navChild.nextSibling ) {
+
  if (!(HCell=HRow.getElementsByTagName('th')[0])) continue
                        if ( hasClass( navChild, 'NavPic' ) ) {
+
  Table.id = 'collapsibleTable' + tblIdx
                                navChild.style.display = 'none';
+
  btn = document.createElement('span')
                        }
+
  btn.style.cssText = 'float:right; font-weight:normal; font-size:smaller'
                        if ( hasClass( navChild, 'NavContent' ) ) {
+
  a = document.createElement('a')
                                navChild.style.display = 'none';
+
  a.id = 'collapseButton' + tblIdx
                        }
+
  a.href = 'javascript:collapseTable(' + tblIdx + ');'
                }
+
  a.style.color = HCell.style.color
                navToggle.firstChild.data = navigationBarShow;
+
  a.appendChild(document.createTextNode(NavigationBarHide))
+
  btn.appendChild(a)
        // If hidden now
+
  HCell.insertBefore(btn, HCell.childNodes[0])
        } else if ( navToggle.firstChild.data == navigationBarShow ) {
+
  colTables[tblIdx++] = Table
                for ( navChild = navFrame.firstChild; navChild != null; navChild = navChild.nextSibling ) {
+
  }
                        if ( $( navChild ).hasClass( 'NavPic' ) || $( navChild ).hasClass( 'NavContent' ) ) {
+
  for (var i=0; i < tblIdx; i++)
                                navChild.style.display = 'block';
+
  if ((tblIdx > NavigationBarShowDefault && hasClass(colTables[i], 'autocollapse')) || hasClass(colTables[i], 'collapsed'))
                        }
+
    collapseTable(i)
                }
+
}
                navToggle.firstChild.data = navigationBarHide;
+
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 == NavigationBarHide)
 +
btn.firstChild.data = isShown ?  NavigationBarShow : NavigationBarHide
 +
var disp = isShown ? 'none' : Rows[0].style.display
 +
for (var i=1; i < Rows.length; i++)
 +
    Rows[i].style.display = disp
 +
}
 +
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))
 +
  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)
* Adds show/hide-button to navigation bars.
+
  var btn = document.getElementById('NavToggle' + idx)
*
+
if (!div || !btn) return false
* @param {jQuery} $content
+
var isShown = (btn.firstChild.data == NavigationBarHide)
*/
+
  btn.firstChild.data = isShown ? NavigationBarShow : NavigationBarHide
function createNavigationBarToggleButton( $content ) {
+
var disp = isShown ? 'none' : 'block'
        var i, j, navFrame, navToggle, navToggleText, navChild,
+
for (var child = div.firstChild; child != null; child = child.nextSibling)
                indexNavigationBar = 0,
+
  if (hasClass(child, 'NavPic') || hasClass(child, 'NavContent'))
                navFrames = $content.find( 'div.NavFrame' ).toArray();
+
      child.style.display = disp
   
 
        // Iterate over all (new) nav frames
 
        for ( i = 0; i < navFrames.length; i++ ) {
 
                navFrame = navFrames[i];
 
                // If found a navigation bar
 
                indexNavigationBar++;
 
                navToggle = document.createElement( 'a' );
 
                navToggle.className = 'NavToggle';
 
                navToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
 
                navToggle.setAttribute( 'href', '#' );
 
                $( navToggle ).on( 'click', $.proxy( toggleNavigationBar, null, indexNavigationBar ) );
 
   
 
                navToggleText = document.createTextNode( navigationBarHide );
 
                for ( navChild = navFrame.firstChild; navChild != null; navChild = navChild.nextSibling ) {
 
                        if ( $( navChild ).hasClass( 'NavPic' ) || $( navChild ).hasClass( 'NavContent' ) ) {
 
                                if ( navChild.style.display == 'none' ) {
 
                                        navToggleText = document.createTextNode( navigationBarShow );
 
                                        break;
 
                                }
 
                        }
 
                }
 
 
                navToggle.appendChild( navToggleText );
 
                // Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
 
                for ( j = 0; j < navFrame.childNodes.length; j++ ) {
 
                        if ( $( navFrame.childNodes[j] ).hasClass( 'NavHead' ) ) {
 
                                navFrame.childNodes[j].appendChild( navToggle );
 
                        }
 
                }
 
                navFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
 
        }
 
 
}
 
}
+
//Secure server
mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );
+
var metaBase = 'http://meta.wikimedia.org'
+
if (wgServer == 'https://secure.wikimedia.org') {
}());
+
  importScript('MediaWiki:Common.js/secure.js','en')
 
+
  metaBase = 'https://secure.wikimedia.org/wikipedia/meta'
/**
 
* Collapsible tables
 
*
 
* @version 2.0.1 (2013-03-26)
 
* @source https://www.mediawiki.org/wiki/MediaWiki:Gadget-collapsibleTables.js
 
* @author [[User:R. Koot]]
 
* @author [[User:Krinkle]]
 
* @deprecated Since MediaWiki 1.20: Use class="mw-collapsible" instead which
 
* is supported in MediaWiki core.
 
*/
 
 
var autoCollapse = 2;
 
var collapseCaption = 'hide';
 
var expandCaption = 'show';
 
 
function collapseTable( tableIndex ) {
 
        var Button = document.getElementById( 'collapseButton' + tableIndex );
 
        var Table = document.getElementById( 'collapsibleTable' + tableIndex );
 
 
        if ( !Table || !Button ) {
 
                return false;
 
        }
 
 
        var Rows = Table.rows;
 
 
        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;
 
        }
 
 
}
 
}
+
//Execution
function createClickHandler( tableIndex ) {
+
if (wgCanonicalNamespace == 'Special'){
        return function ( e ) {
+
if (/^(Uplo|Sear|Stat|Spec|Abus|Prefe)/i.test(wgCanonicalSpecialPageName))
                e.preventDefault();
+
  importMW(wgCanonicalSpecialPageName)
                collapseTable( tableIndex );
+
}else switch (wgAction){
        }
+
case 'history': importMW('History'); break
 +
case 'delete': importMW('Deletepage'); break
 +
case 'edit': case 'submit': importMW('Editpage') //and continue with the default: view, purge
 +
default:
 +
  $(editZeroSection)
 +
  addOnloadHook(collapsibleDivs)
 +
  addOnloadHook(collapsibleTables)
 +
  importScriptURI(metaBase+'/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript&smaxage=21600&maxage=86400')
 +
  if (navigator.platform.indexOf('Win') != -1)
 +
    importStylesheetURI('http://en.wikipedia.org/w/index.php?title=MediaWiki:Common.css/WinFixes.css&action=raw&ctype=text/css')
 +
    switch( wgNamespaceNumber ){
 +
    case 0: case 100:
 +
      $(LinkFA)
 +
      importMW('Osm')
 +
      importMW('Collapserefs')
 +
      if( wgArticleId==4401 ) importMW('Mainpage')
 +
      break
 +
    case 6:
 +
      importMW('Filepage')
 +
      break
 +
    default:
 +
      $(icqIcon)
 +
  }  
 
}
 
}
+
 
function createCollapseButtons() {
+
/* Ref tooltips */
        var tableIndex = 0;
+
addOnloadHook(function() {
        var NavigationBoxes = {};
+
    if(!($('ol.references').size())) return;
        var Tables = document.getElementsByTagName( 'table' );
+
    $('ol.references').before($('<a href="#">[Показать примечания]</a>').click(function(e){e.preventDefault(); $('ol.references').toggle()})).hide()
+
    $('.reference a').live('click', function(e) {  
        for ( var i = 0; i < Tables.length; i++ ) {
+
        e.preventDefault();
                if ( $( Tables[i] ).hasClass( 'collapsible' ) ) {
+
        var x = $(this), iscurrent = x.hasClass('curreference'), i = $('.tooltip').hide(250)
                        /* only add button and increment count if there is a header row to work with */
+
        $('.curreference').removeClass('curreference');  
                        var HeaderRow = Tables[i].getElementsByTagName( 'tr' )[0];
+
        if (iscurrent) return;
                        if ( !HeaderRow ) {
+
        var par = x.parent(), o = par.offset(), l = o.left, t = o.top+13
                                continue;
+
        var b = $('body'), mh = b.height(), mw = b.width()
                        }
+
        var c=$(x.attr('href')).clone().find('a:first').remove().end().html()
                        var Header = HeaderRow.getElementsByTagName( 'th' )[0];
+
 
                        if ( !Header ) {
+
        x.addClass('areference').addClass('curreference')  
                                continue;
+
        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()
                        NavigationBoxes[tableIndex] = Tables[i];
+
         }).show(250)
                        Tables[i].setAttribute( 'id', 'collapsibleTable' + tableIndex );
+
    })
+
    $(window).click(function(e) {
                        var Button = document.createElement( 'span' );
+
        if (!($(e.target).hasClass('areference') || $(e.target).parents().andSelf().hasClass('tooltip'))) {
                        var ButtonLink = document.createElement( 'a' );
+
            $('.tooltip').hide(250); $('.curreference').removeClass('curreference')
                        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.style.color = Header.style.color;
 
                        ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex );
 
                        $( ButtonLink ).on( 'click', createClickHandler( tableIndex ) );
 
                        ButtonLink.appendChild( ButtonText );
 
 
                        Button.appendChild( document.createTextNode( '[' ) );
 
                        Button.appendChild( ButtonLink );
 
                        Button.appendChild( document.createTextNode( ']' ) );
 
 
                        Header.insertBefore( Button, Header.childNodes[0] );
 
                        tableIndex++;
 
                }
 
         }
 
 
        for ( var i = 0; i < tableIndex; i++ ) {
 
                if ( $( NavigationBoxes[i] ).hasClass( 'collapsed' ) ||
 
                        ( tableIndex >= autoCollapse && $( NavigationBoxes[i] ).hasClass( 'autocollapse' ) )
 
                ) {
 
                        collapseTable( i );
 
                }
 
 
         }
 
         }
}
+
    })
+
})
$( createCollapseButtons );
 

Версия 13:03, 1 октября 2013

importMW = function (name) { importScript('MediaWiki:'+name+'.js') }
importScript_ = importScript
//Messages
var zeroSectionTip = 'Править введение'
var NavigationBarHide = '[скрыть]'
var NavigationBarShow = '[показать]'
var NavigationBarShowDefault = 2
if( /^en$/.test(wgUserLanguage) ) importMW('Common-' + wgUserLanguage)
function LinkFA(){
 var ll, s
 $('#p-lang li').each( function(i, iw){
   ll = iw.className.split(' ')[0] + '-'
   for( var s in listFA )
     if( document.getElementById(ll + s) )
       $( iw )
        .addClass( s.toUpperCase() )
        .attr( 'title',  listFA[s] + textFA )
 })
}
function editZeroSection(){
 if( !wgArticleId ) return
 mw.util.$content.find('h2')
 .children('span.editsection').first()
 .clone().prependTo(mw.util.$content)
 .find('a')
 .attr('title', zeroSectionTip)
 .attr('href', wgScript + '?title='+encodeURIComponent(wgPageName) + '&action=edit&section=0' )
} 
//Collapsiblе
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 collapsibleTables(){
 var Table, HRow,  HCell, 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
   if (!(HCell=HRow.getElementsByTagName('th')[0])) continue
   Table.id = 'collapsibleTable' + tblIdx
   btn = document.createElement('span')
   btn.style.cssText = 'float:right; font-weight:normal; font-size:smaller'
   a = document.createElement('a')
   a.id = 'collapseButton' + tblIdx
   a.href = 'javascript:collapseTable(' + tblIdx + ');'
   a.style.color = HCell.style.color
   a.appendChild(document.createTextNode(NavigationBarHide))
   btn.appendChild(a)
   HCell.insertBefore(btn, HCell.childNodes[0])
   colTables[tblIdx++] = Table
 }
 for (var i=0; i < tblIdx; i++)
   if ((tblIdx > NavigationBarShowDefault && 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 == NavigationBarHide)
 btn.firstChild.data = isShown ?  NavigationBarShow : NavigationBarHide
 var disp = isShown ? 'none' : Rows[0].style.display
 for (var i=1; i < Rows.length; i++)
    Rows[i].style.display = disp
}
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))
   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
}
//Secure server
var metaBase = 'http://meta.wikimedia.org'
if (wgServer == 'https://secure.wikimedia.org') {
  importScript('MediaWiki:Common.js/secure.js','en')
  metaBase = 'https://secure.wikimedia.org/wikipedia/meta'
}
//Execution
if (wgCanonicalNamespace == 'Special'){
if (/^(Uplo|Sear|Stat|Spec|Abus|Prefe)/i.test(wgCanonicalSpecialPageName))
   importMW(wgCanonicalSpecialPageName)
}else switch (wgAction){
 case 'history': importMW('History'); break
 case 'delete': importMW('Deletepage'); break
 case 'edit': case 'submit': importMW('Editpage') //and continue with the default: view, purge
 default:
  $(editZeroSection)
  addOnloadHook(collapsibleDivs)
  addOnloadHook(collapsibleTables)
  importScriptURI(metaBase+'/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript&smaxage=21600&maxage=86400')
  if (navigator.platform.indexOf('Win') != -1)
    importStylesheetURI('http://en.wikipedia.org/w/index.php?title=MediaWiki:Common.css/WinFixes.css&action=raw&ctype=text/css')
    switch( wgNamespaceNumber ){
    case 0: case 100:
      $(LinkFA)
      importMW('Osm')
      importMW('Collapserefs')
      if( wgArticleId==4401 ) importMW('Mainpage')
      break
    case 6:
      importMW('Filepage')
      break
    default:
       $(icqIcon) 
   }    
}

/* Ref tooltips */
addOnloadHook(function() {
    if(!($('ol.references').size())) return;
    $('ol.references').before($('<a href="#">[Показать примечания]</a>').click(function(e){e.preventDefault(); $('ol.references').toggle()})).hide()
    $('.reference a').live('click', function(e) { 
        e.preventDefault();
        var x = $(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=$(x.attr('href')).clone().find('a:first').remove().end().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')
        }
    })
})

Профиль