MediaWiki:Common.js: Razlika med redakcijama

Iz Wikinavedka, proste zbirke navedkov in pregovorov
Izbrisana vsebina Dodana vsebina
Dbc334 (pogovor | prispevki)
prenesen začetek w:MediaWiki:Common.js
 
Ruslik0 (pogovor | prispevki)
moving from monobook.js, update
Vrstica 1: Vrstica 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */


/* Scripts specific to Internet Explorer */
/* Preizkus, ali ima element določen razred **************************************
if ($.client.profile().name == 'msie') {
*
/** Internet Explorer bug fix **************************************************
* Opis: Uses regular expressions and caching for better performance.
*
* Vzdrževalci: [[:en:User:Mike Dillon|Mike Dillon]], [[:en:User:R. Koot|R. Koot]], [[:en:User:SG|SG]]
* Description: Fixes IE horizontal scrollbar bug
*/
* Maintainers: [[User:Tom-]]?
*/
var oldWidth;
var hasClass = (function () {
var reCache = {};
var docEl = document.documentElement;
return function (element, className) {
return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
};
})();

/** Popravek hrošča za Internet Explorer **************************************************
*
* Opis: UNDOCUMENTED
* Vzdrževalci: [[:en:User:Tom-|Tom-]]?
*/
var fixIEScroll = function() {
if (navigator.appName == "Microsoft Internet Explorer" && document.compatMode == "CSS1Compat")
if (!oldWidth || docEl.clientWidth > oldWidth) {
{
doFixIEScroll();
var oldWidth;
} else {
var docEl = document.documentElement;
setTimeout(doFixIEScroll, 1);
}
oldWidth = docEl.clientWidth;
function fixIEScroll()
{
};
if (!oldWidth || docEl.clientWidth > oldWidth)
doFixIEScroll();
else
setTimeout(doFixIEScroll, 1);
oldWidth = docEl.clientWidth;
}
function doFixIEScroll() {
var doFixIEScroll = function () {
docEl.style.overflowX = (docEl.scrollWidth - docEl.clientWidth < 4) ? "hidden" : "";
docEl.style.overflowX = (docEl.scrollWidth - docEl.clientWidth < 4) ? "hidden" : "";
}
};
document.attachEvent("onreadystatechange", fixIEScroll);
document.attachEvent("onreadystatechange", fixIEScroll);
attachEvent("onresize", fixIEScroll);
document.attachEvent("onresize", fixIEScroll);
}
// In print IE (7?) does not like line-height
mw.util.addCSS('@media print { sup, sub, p, .documentDescription { line-height: normal; } }');
// IE overflow bug
mw.util.addCSS('div.overflowbugx { overflow-x: scroll !important; overflow-y: hidden !important; } '
+ 'div.overflowbugy { overflow-y: scroll !important; overflow-x: hidden !important; }');
// IE zoomfix
// Use to fix right floating div/table inside tables
mw.util.addCSS('.iezoomfix div, .iezoomfix table { zoom: 1; }');
}


/** Skrčljive razpredelnice *********************************************************
/** Skrčljive razpredelnice *********************************************************
Vrstica 85: Vrstica 83:
for ( var i = 0; i < Tables.length; i++ ) {
for ( var i = 0; i < Tables.length; i++ ) {
if ( hasClass( Tables[i], "collapsible" ) ) {
if ( $(Tables[i]).hasClass("collapsible" ) ) {
/* only add button and increment count if there is a header row to work with */
/* only add button and increment count if there is a header row to work with */
Vrstica 121: Vrstica 119:
for ( var i = 0; i < tableIndex; i++ ) {
for ( var i = 0; i < tableIndex; i++ ) {
if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) {
if ( $(NavigationBoxes[i]).hasClass("collapsed" ) || ( tableIndex >= autoCollapse && $(NavigationBoxes[i]).hasClass("autocollapse" ) ) ) {
collapseTable( i );
collapseTable( i );
}
}
Vrstica 158: Vrstica 156:
NavChild = NavChild.nextSibling
NavChild = NavChild.nextSibling
) {
) {
if ( hasClass( NavChild, 'NavPic' ) ) {
if ( $(NavChild).hasClass('NavPic' ) ) {
NavChild.style.display = 'none';
NavChild.style.display = 'none';
}
}
if ( hasClass( NavChild, 'NavContent') ) {
if ( $(NavChild).hasClass('NavContent') ) {
NavChild.style.display = 'none';
NavChild.style.display = 'none';
}
}
Vrstica 174: Vrstica 172:
NavChild = NavChild.nextSibling
NavChild = NavChild.nextSibling
) {
) {
if (hasClass(NavChild, 'NavPic')) {
if ($(NavChild).hasClass('NavPic')) {
NavChild.style.display = 'block';
NavChild.style.display = 'block';
}
}
if (hasClass(NavChild, 'NavContent')) {
if ($(NavChild).hasClass('NavContent')) {
NavChild.style.display = 'block';
NavChild.style.display = 'block';
}
}
Vrstica 197: Vrstica 195:
) {
) {
// if found a navigation bar
// if found a navigation bar
if (hasClass(NavFrame, "NavFrame")) {
if ($(NavFrame).hasClass("NavFrame")) {
indexNavigationBar++;
indexNavigationBar++;
Vrstica 211: Vrstica 209:
NavChild = NavChild.nextSibling
NavChild = NavChild.nextSibling
) {
) {
if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) {
if ( $(NavChild).hasClass('NavPic' ) || $(NavChild).hasClass('NavContent' ) ) {
if (NavChild.style.display == 'none') {
if (NavChild.style.display == 'none') {
NavToggleText = document.createTextNode(NavigationBarShow);
NavToggleText = document.createTextNode(NavigationBarShow);
Vrstica 226: Vrstica 224:
j++
j++
) {
) {
if (hasClass(NavFrame.childNodes[j], "NavHead")) {
if ($(NavFrame.childNodes[j]).hasClass("NavHead")) {
NavFrame.childNodes[j].appendChild(NavToggle);
NavFrame.childNodes[j].appendChild(NavToggle);
}
}

Redakcija: 20:41, 19. avgust 2012

/* Any JavaScript here will be loaded for all users on every page load. */

/* Scripts specific to Internet Explorer */
if ($.client.profile().name == 'msie') {
    /** Internet Explorer bug fix **************************************************
     *
     *  Description: Fixes IE horizontal scrollbar bug
     *  Maintainers: [[User:Tom-]]?
     */
 
    var oldWidth;
    var docEl = document.documentElement;
 
    var fixIEScroll = function() {
        if (!oldWidth || docEl.clientWidth > oldWidth) {
            doFixIEScroll();
        } else {
            setTimeout(doFixIEScroll, 1);
        }
 
        oldWidth = docEl.clientWidth;
    };
 
    var doFixIEScroll = function () {
        docEl.style.overflowX = (docEl.scrollWidth - docEl.clientWidth < 4) ? "hidden" : "";
    };
 
    document.attachEvent("onreadystatechange", fixIEScroll);
    document.attachEvent("onresize", fixIEScroll);
 
    // In print IE (7?) does not like line-height
    mw.util.addCSS('@media print { sup, sub, p, .documentDescription { line-height: normal; } }');
 
    // IE overflow bug
    mw.util.addCSS('div.overflowbugx { overflow-x: scroll !important; overflow-y: hidden !important; } '
      + 'div.overflowbugy { overflow-y: scroll !important; overflow-x: hidden !important; }');
 
    // IE zoomfix
    // Use to fix right floating div/table inside tables
    mw.util.addCSS('.iezoomfix div, .iezoomfix table { zoom: 1; }');
}

 /** Skrčljive razpredelnice *********************************************************
  *
  *  Opis: Allows tables to be collapsed, showing only the header. See
  *               [[:en:Wikipedia:NavFrame]].
  *  Vzdrževalci: [[:en:User:R. Koot|R. Koot]]
  */
 
 var autoCollapse = 2;
 var collapseCaption = "zapri";
 var expandCaption = "odpri";
 
 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.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.setAttribute( "href", "javascript:collapseTable(" + 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 );
         }
     }
 }
 
 addOnloadHook( createCollapseButtons );

 /** Dinamični navigacijski menuji (preizkusno) *************************************
  *
  *  Opis: See [[:en:Wikipedia:NavFrame|Wikipedia:NavFrame]].
  *  Vzdrževalci: NI VZDRŽEVANO
  */
 
  // set up the words in your language
  var NavigationBarHide = '[' + collapseCaption + ']';
  var NavigationBarShow = '[' + expandCaption + ']';
 
  // 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('NavPic' ) ) {
                 NavChild.style.display = 'none';
             }
             if ( $(NavChild).hasClass('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 ($(NavChild).hasClass('NavPic')) {
                 NavChild.style.display = 'block';
             }
             if ($(NavChild).hasClass('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 ($(NavFrame).hasClass("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);
             for (
                  var 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(
               var j=0; 
               j < NavFrame.childNodes.length; 
               j++
             ) {
               if ($(NavFrame.childNodes[j]).hasClass("NavHead")) {
                 NavFrame.childNodes[j].appendChild(NavToggle);
               }
             }
             NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
         }
     }
  }
 
  addOnloadHook( createNavigationBarToggleButton );