Перейти до вмісту

MediaWiki:Common.js: відмінності між версіями

Матеріал з Вікіновин — вільних новин.
Вилучено вміст Додано вміст
мНемає опису редагування
 
Рядок 361: Рядок 361:
for (j = 0 ; j < UnitNode.childNodes.length ; j++ ) {
for (j = 0 ; j < UnitNode.childNodes.length ; j++ ) {
var temp = UnitNode.childNodes[j];
var temp = UnitNode.childNodes[j];
if (temp.className === "center") { units.push(temp); }
if (['center', 'mw-halign-center'].some(function(className) { return temp.classList.contains(className); })) { units.push(temp); }
}
}
var rightlink = undefined;
var rightlink = undefined;
var commentText = undefined;
var commentText = undefined;
var wrap;
for (j = 0; j < units.length; j++) {
for (j = 0; j < units.length; j++) {
currentimage = units[j];
currentimage = units[j];
wrap = document.createElement('div');
currentimage.id = "ImageGroupsGr" + i + "Im" + j;
wrap.id = "ImageGroupsGr" + i + "Im" + j;
currentimage.parentNode.insertBefore(wrap, currentimage);
wrap.appendChild(currentimage);
var leftlink = document.createElement("a");
var leftlink = document.createElement("a");
if (commentText !== undefined) {
if (commentText !== undefined) {
Рядок 405: Рядок 409:
imghead.appendChild(rightlink);
imghead.appendChild(rightlink);
if (units.length > 1) {
if (units.length > 1) {
currentimage.insertBefore(imghead,currentimage.childNodes[0]);
wrap.insertBefore(imghead,wrap.childNodes[0]);
}
}
if (j != 0) {
if (j != 0) {
currentimage.style["display"] = "none";
wrap.style["display"] = "none";
}
}
}
}

Поточна версія на 21:29, 23 лютого 2023

// <nowiki>

/**
 * WikiMiniAtlas is a popup click and drag world map.
 * See [[meta:WikiMiniAtlas]] for more information.
 * Maintainers: [[w:User:Dschwen]]
 */
mw.loader.load( '//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript' );


 /** Execute function on page load *********************************************
  *
  *  Description: Wrapper around $.ready for backwards compatibility.
  *               Will be removed in the near future.
  *  Maintainers: [[:en:User:R. Koot]]
  */
 function addLoadEvent( f ) { $.when($.ready).then( f ); }

/* Load fixes for Windows font rendering */
if( navigator.platform.indexOf( "Win" ) != -1 ) {
    mw.loader.load( '/w/index.php?title=MediaWiki:Common.css/WinFixes.css&action=raw&ctype=text/css', 'text/css' );
}

 /** Collapsible tables *********************************************************
  *
  *  Description: Allows tables to be collapsed, showing only the header. See
  *               [[:en:w:NavFrame]].
  *  Maintainers: [[:en: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.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;
    }
}

function createCollapseButtons(){
    var tableIndex = 0;
    var NavigationBoxes = new Object();
    var Tables = document.getElementsByTagName( "table" );

    for ( var i = 0; i < Tables.length; i++ ) {
        if ( $(Tables[i]).hasClass( "collapsible" ) ) {

            /* only add button and increment count if there is a header row to work with */
            var HeaderRow = Tables[i].getElementsByTagName( "tr" )[0];
            if (!HeaderRow) continue;
            var Header = HeaderRow.getElementsByTagName( "th" )[0];
            if (!Header) continue;

            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.className = "collapseButton";  //Styles are declared in Common.css

            ButtonLink.style.color = Header.style.color;
            ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
            ButtonLink.setAttribute( "href", "#" );
            addHandler( ButtonLink,  "click", new Function( "evt", "collapseTable(" + tableIndex + " ); return false;") );
            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 );
        } 
        else if ( $(NavigationBoxes[i]).hasClass( "innercollapse" ) ) {
            var element = NavigationBoxes[i];
            while (element = element.parentNode) {
                if ( $(element).hasClass( "outercollapse" ) ) {
                    collapseTable ( i );
                    break;
                }
            }
        }
    }
}

$( createCollapseButtons );


/** Dynamic Navigation Bars (experimental) *************************************
 *
 *  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 ($(NavChild).hasClass( 'NavContent') || $(NavChild).hasClass( 'NavPic')) {
                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 ($(NavChild).hasClass( 'NavContent') || $(NavChild).hasClass( 'NavPic')) {
                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 ($(NavFrame).hasClass( "NavFrame")) {

            indexNavigationBar++;
            var NavToggle = document.createElement("a");
            NavToggle.className = 'NavToggle';
            NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
            NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');

            var isCollapsed = $(NavFrame).hasClass( "collapsed" );
            /*
             * Check if any children are already hidden.  This loop is here for backwards compatibility:
             * the old way of making NavFrames start out collapsed was to manually add style="display:none"
             * to all the NavPic/NavContent elements.  Since this was bad for accessibility (no way to make
             * the content visible without JavaScript support), the new recommended way is to add the class
             * "collapsed" to the NavFrame itself, just like with collapsible tables.
             */
            for (var NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling) {
                if ( $(NavChild).hasClass( 'NavPic' ) || $(NavChild).hasClass( 'NavContent' ) ) {
                    if ( NavChild.style.display == 'none' ) {
                        isCollapsed = true;
                    }
                }
            }
            if (isCollapsed) {
                for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
                    if ( $(NavChild).hasClass( 'NavPic' ) || $(NavChild).hasClass( 'NavContent' ) ) {
                        NavChild.style.display = 'none';
                    }
                }
            }
            var NavToggleText = document.createTextNode(isCollapsed ? NavigationBarShow : 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 ($(NavFrame.childNodes[j]).hasClass( "NavHead")) {
                    NavToggle.style.color = NavFrame.childNodes[j].style.color;
                    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);
        }
    }
}

$( createNavigationBarToggleButton );

  /*
   * Функція, що на головній сторінці в кінці списку інтервікі ставить посилання на повний список всіх Вікіновин
   * todo: теж винести в додатки нафіг, напевно
   */
  function mainPageAppendCompleteListLink() {
    try {
        var node = document.getElementById( "p-lang" )
                           .getElementsByTagName('div')[0]
                           .getElementsByTagName('ul')[0];
        var aNode = document.createElement( 'a' );
        var liNode = document.createElement( 'li' );
        aNode.appendChild( document.createTextNode( 'Повний список' ) );
        aNode.setAttribute( 'href' , '//meta.wikimedia.org/wiki/Wikinews#Wikinews_Statistics' );
        liNode.appendChild( aNode );
        liNode.className = 'interwiki-completelist';
        node.appendChild( liNode );
     } catch(e) {
       // lets just ignore what's happened
       return;
    }
  }

  if (mw.config.get('wgIsMainPage')) {
       $( mainPageAppendCompleteListLink );
  }

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

 /** Import module *************************************************************
  *
  *  Предложен [[Участник:Alex_Smotrov]], на основе аналогичной английской функции
  *
  *  Description: Includes a raw wiki page as javascript or CSS, 
  *               used for including user made modules.
  * 2017-05-17 Хай повисить ще рік, потім треба знести, легше потім ботом
  * по користувацьких скриптах пройтись і позаміняти на мв.лоадер.лоад.
  * Або не потім. --Base
  */

 function importScript(page, lang) {
     var url = mw.config.get('wgScriptPath') + '/index.php?title='
                            + encodeURIComponent(page.replace(' ','_'))
                            + '&action=raw&ctype=text/javascript';
     if (lang) {
          url = '//' + lang + '.wikinews.org' + url;
     } else {
          url = '//uk.wikinews.org' + url;
     }
     mw.loader.load(url);
 }

/**
 * Панелі редагування та друзі 
*/
if (document.URL.indexOf("action=edit") > 0 || document.URL.indexOf("action=submit") > 0) {
        if (mw.config.get('wgCanonicalNamespace') != "Special") {
              mw.loader.load('//uk.wikinews.org/w/index.php?title=MediaWiki:Onlyifediting.js&action=raw&ctype=text/javascript'); 
        }
}

// Розширений пошук
// Автор: 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 googleSearch  = '<form action="http://www.google.com/custom" method="get" name="google" target="_blank" id="google">';
    googleSearch += '<input type="hidden" name="hl" value="uk" />';
    googleSearch += '<input type="hidden" name="domains" value="uk.wikinews.org" />';
    googleSearch += '<input type="hidden" name="q" maxlength="2048" value="' + safeSearchValue + '" />'
    googleSearch += '<input type="hidden" name="sitesearch" value="uk.wikinews.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.ua/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="uk.wikinews.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>';
        
    firstForm.parentNode.insertBefore(node, firstForm.nextSibling);
}

// Можливість редагування "нульового" розділу
// Теоретично це мало б бути у додатках...
importScript('MediaWiki:Gadget-edittop.js');

var auto_comment = 0

 /** Для шаблону Шаблон:Scroll Gallery‎
 *   
 */
 $(function() {
  if (document.URL.match(/printable/g)) return;
 
  function toggleImageFunction(group,  remindex, shwindex) {
    return function() {
      document.getElementById("ImageGroupsGr" + group + "Im" + remindex).style["display"] = "none";
      document.getElementById("ImageGroupsGr" + group + "Im" + shwindex).style["display"] = "block";
      return false;
    };
  }
 
  var divs = document.getElementsByTagName("div");
  var i = 0, j = 0;
  var units, search;
  var currentimage;
  var UnitNode;
  for (i = 0; i < divs.length; i++) {
    if (divs[i].className !== "ImageGroup") { continue; }
    UnitNode = undefined;
    search = divs[i].getElementsByTagName("div");
    for (j = 0; j < search.length; j++) {
      if (search[j].className !== "ImageGroupUnits") { continue; }
      UnitNode=search[j];
      break;
    }
    if (UnitNode === undefined) { continue; }
    units = [];
    for (j = 0 ; j < UnitNode.childNodes.length ; j++ ) {
      var temp = UnitNode.childNodes[j];
      if (['center', 'mw-halign-center'].some(function(className) { return temp.classList.contains(className); })) { units.push(temp); }
    }
    var rightlink = undefined;
    var commentText = undefined;
    var wrap;
    for (j = 0; j < units.length; j++) {
      currentimage = units[j];
      wrap = document.createElement('div');
      wrap.id = "ImageGroupsGr" + i + "Im" + j;
      currentimage.parentNode.insertBefore(wrap, currentimage);
      wrap.appendChild(currentimage);
      var leftlink = document.createElement("a");
      if (commentText !== undefined) {
        leftlink.setAttribute("title", commentText);
      }
      var comment;
      if (typeof(currentimage.getAttribute("title")) !== "string") {
        commentText = (j+1) + "/" + units.length;
        comment = document.createElement("tt").appendChild(document.createTextNode("("+ commentText + ")"));
      }
      else {
        commentText = currentimage.getAttribute("title");
        comment = document.createElement("span").appendChild(document.createTextNode(commentText));
        currentimage.removeAttribute("title");
      }
      if(rightlink !== undefined) {
        rightlink.setAttribute("title", commentText);
      }
      var imghead = document.createElement("div");
      rightlink = document.createElement("a");
      if (j != 0) {
        leftlink.href = "#";
        leftlink.onclick = toggleImageFunction(i, j, j-1);
        leftlink.appendChild(document.createTextNode("◀"));
      }
      if (j != units.length - 1) {
        rightlink.href = "#";
        rightlink.onclick = toggleImageFunction(i, j, j+1);
        rightlink.appendChild(document.createTextNode("▶"));
      }
      imghead.style["fontSize"] = "110%";
      imghead.style["fontweight"] = "bold";
      imghead.appendChild(leftlink);
      imghead.appendChild(document.createTextNode("\xA0"));
      imghead.appendChild(comment);
      imghead.appendChild(document.createTextNode("\xA0"));
      imghead.appendChild(rightlink);
      if (units.length > 1) {
        wrap.insertBefore(imghead,wrap.childNodes[0]);
      }
      if (j != 0) {
        wrap.style["display"] = "none";
      }
    }
  }
 });
 //Кінець блоку для шаблону Scroll Gallery

// </nowiki>