መልዕክት:Monobook.js

ከWiktionary

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* </pre>
==Dynamic Navigation Bars (experimental)==
<pre> */
 // ============================================================
 // BEGIN Dynamic Navigation Bars (experimental)
 
 // set up the words in your language
 var NavigationBarHide = '[Hide]';
 var NavigationBarShow = '[Show]';
 
 // 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 = 0;
  
/* </pre>
===toggleNavigationBar===
<pre> */
 // 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;
                NavChild = NavChild.nextSibling
            ) {
            if (NavChild.className == 'NavPic') {
                NavChild.style.display = 'none';
            }
            if (NavChild.className == 'NavContent') {
                NavChild.style.display = 'none';
            }
        }
    NavToggle.firstChild.data = NavigationBarShow;
 
    // if hidden now
    } else if (NavToggle.firstChild.data == NavigationBarShow) {
        for (
                var NavChild = NavFrame.firstChild;
                NavChild;
                NavChild = NavChild.nextSibling
            ) {
            if (NavChild.className == 'NavPic') {
                NavChild.style.display = 'block';
            }
            if (NavChild.className == 'NavContent') {
                NavChild.style.display = 'block';
            }
        }
    NavToggle.firstChild.data = NavigationBarHide;
    }
 }
 
/* </pre>
===createNavigationBarToggleButton===
<pre> */
 // adds show/hide-button to navigation bars
 function createNavigationBarToggleButton()
 {
    var indexNavigationBar = 0;
    // iterate over all < div >-elements
    for(
            var i=0; 
            NavFrame = document.getElementsByTagName("div")[i]; 
            i++
        ) {
        // if found a navigation bar
        if (NavFrame.className == "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 (NavFrame.childNodes[j].className == "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);
        }
    }
 
 }
 
 jQuery(document).ready(createNavigationBarToggleButton);
 
 // END Dynamic Navigation Bars
 // ============================================================

/* </pre>
==addCharSubsetMenu==
<pre> */
/* add menu for selecting subsets of secial characters */
/***** must match MediaWiki:Edittools *****/
function addCharSubsetMenu() {
  var edittools = document.getElementById('editpage-specialchars');

  if (edittools) {
    var menu = "<select id=\"charSubsetControl\" style=\"display:inline\" onChange=\"chooseCharSubset(selectedIndex)\">";
    menu += "<option>Templates</option>";
    menu += "<option>Latin/Roman</option>";
    menu += "<option>Greek (Modern)</option>";
    menu += "<option>Cyrillic</option>";
    menu += "<option>IPA</option>";
    menu += "<option>AHD</option>";
    menu += "<option>Misc.</option>";
    menu += "<option>Arabic</option>";
    menu += "<option>Catalan</option>";
    menu += "<option>Devanāgarī</option>";
    menu += "<option>Esperanto</option>";
    menu += "<option>Estonian</option>";
    menu += "<option>French</option>";
    menu += "<option>German</option>";
    menu += "<option>Hawaiian</option>";
    menu += "<option>Hebrew</option>";
    menu += "<option>Icelandic</option>";
    menu += "<option>Italian</option>";
    menu += "<option>Maltese</option>";
    menu += "<option>Old English</option>";
    menu += "<option>Pinyin</option>";
    menu += "<option>Portuguese</option>";
    menu += "<option>Romaji</option>";
    menu += "<option>Romanian</option>";
    menu += "<option>Scandinavian</option>";
    menu += "<option>Slavic Roman</option>";
    menu += "<option>Spanish</option>";
    menu += "<option>Vietnamese</option>";
    menu += "<option>Welsh</option>";
    menu += "</select>";
    edittools.innerHTML = menu + edittools.innerHTML;

    /* default subset from cookie */
    var s = parseInt( $.cookie('edittoolscharsubset') );
    if ( isNaN(s) ) s = 0;

    /* update dropdown control to value of cookie */
    document.getElementById('charSubsetControl').selectedIndex = s; 

    /* display the subset indicated by the cookie */
    chooseCharSubset( s );
  }
}


/* </pre>
===chooseCharSubsetMenu===
<pre> */
/* select subsection of special characters */
function chooseCharSubset(s) {
  var l = document.getElementById('editpage-specialchars').getElementsByTagName('p');
  for (var i = 0; i < l.length ; i++) {
    l[i].style.display = i == s ? 'inline' : 'none';
    l[i].style.visibility = i == s ? 'visible' : 'hidden';
  }
  $.cookie('edittoolscharsubset', s);
}



/* </pre>
==<s>nogomatchHideInputBoxen</s>==
<pre> */
/* Hide the inputboxes that appear when entering a new page */
/* See MediaWiki:Nogomatch */
/* ----------------------start dead code------------------
function nogomatchHideInputBoxen() {
  var preloadTable = document.getElementById('preload-table');

  if (preloadTable) {
    var f = preloadTable.getElementsByTagName('form');
    for (var i=0; i < f.length ; i++) {
      var l = f[i].getElementsByTagName('input');
      for (var j=0; j < l.length ; j++) {
        if ( l[j].type == "text" ) {
          l[j].size = 1;
          l[j].width = 1;
          l[j].style.visibility = 'hidden';
        }
      }
    }
  }
}
------------------------end dead code------------------ */



/* </pre>


==doRedirect==
<pre> */

/* Redirect if a case-insensitive search on an external link is found */
function doRedirect() {
  dym = document.getElementById('did-you-mean')
   if ( dym ) {
      var dymtarget = dym.firstChild.title ;
      var target = dymtarget ;
      pagetitle = document.getElementsByTagName('h1').item(0).firstChild.nodeValue;
      if (pagetitle == target) {
        alert('No looping allowed.');
        return;
      }
      if ( pagetitle.toLowerCase().replace(/[^a-z]/g, "") != target.toLowerCase().replace(/[^a-z]/g, "") ) {
        alert(target + " does not match " + pagetitle);
        return;
      }
      if ( pagetitle.search(/Editing /g) != -1 ) return;
      pagenamee = pagetitle.replace(/\ /g, "_");
   document.location.replace( '//en.wiktionary.org/wiki/Special:Search/' + pagenamee ) ;
   }
}

/* </pre>
==fixEditSectionWikifiedLinks==
<pre> */
// edit-section still doesn't return to correct spot if link contains a [[wikified]] term.
function fixEditSectionWikifiedLinks() {
  if (/\.5B/.test(window.location.href)) {
   var url=window.location.href.replace(/.5B.5B:/g,"").replace(/.5B/g, "").replace(/.5D/g, "");
   window.location = url;
  }
  //removed check for 7B/7D
}

/* </pre>
==customizeWiktionary==
<pre> */
/* do any Wiktionary-specific customizations */
function customizeWiktionary() {
  addCharSubsetMenu();
  //nogomatchHideInputBoxen(); //dead code 7/11/2006, new option "hidden=yes"
  doRedirect();
  fixEditSectionWikifiedLinks();
  headingToolTips();
}

jQuery(document).ready(customizeWiktionary);

/* </pre>

==Hide "Main Page" heading==
<pre> */
 var mpTitle = "Wiktionary:Main Page";
 var isMainPage = (document.title.substr(0, document.title.lastIndexOf(" - ")) == mpTitle);
 var isDiff = (document.location.search && (document.location.search.indexOf("diff=") != -1 || document.location.search.indexOf("oldid=") != -1));

 if (isMainPage && !isDiff) mw.util.addCSS('#lastmod, #siteSub, #contentSub, h1.firstHeading { display: none !important; }');

/* </pre>

==Blocking Page Tweak==
<pre> */
//Check the box for "anon only" for AOL blocks (from IRC)
$(function(){ var x; if (x=document.getElementById('wpAnonOnly')) {x.checked=true;} });


/* </pre>
== Wiktionary-specific tooltips ==
<pre> */
function headingToolTips() {

  // only add heading tooltips in the article namespace
  if (document.getElementsByTagName('body')[0].className.match(/ns-0/)) {

    // all level-2 headings are languages (or equivalents such as Translingual)
    var allh2s = document.getElementById('bodyContent').getElementsByTagName('h2');

    if (allh2s != -1) {
      for (var i = 0; i < allh2s.length; i++) {
        allh2s[i].title = 'The language this term belongs to';
      }
    }

    // level 3, 4, and 5 headings depend on their content
    var h345 = new Array('h3', 'h4', 'h5');

    for (var j = 0; j < h345.length ; j++) {

      var allh345s = document.getElementById('bodyContent').getElementsByTagName(h345[j]);

      if (allh345s != -1) {
        for (var i = 0; i < allh345s.length; i++) {

          // part of speech
          var ht = allh345s[i].innerHTML.replace(/^(?:\d+(?:\.\d+)* )?(.*)/, "$1");

          if (ht == 'Adjective' || ht == 'Adverb' || ht == 'Interjection' || ht == 'Noun' || ht == 'Pronoun' || ht == 'Proper noun' || ht == 'Verb' || ht == 'Verb form') {
            allh345s[i].title = 'Part of speech or function of this term';

          } else if (ht == 'Alternative spellings') {
            allh345s[i].title = 'Other ways to spell this term in the same language';
          } else if (ht == 'Anagrams') {
            allh345s[i].title = 'Terms spelled with the same letters in a different order';
          } else if (ht == 'Antonyms') {
            allh345s[i].title = 'Terms with the opposite meaning in at least one sense';
          } else if (ht.match(/^Etymology(?: \d+)?/)) {
            allh345s[i].title = 'The origin of this term';
          } else if (ht == 'Derived terms') {
            allh345s[i].title = 'Terms which are derived through applying derivational suffixes etc.';
          } else if (ht == 'Dictionary notes') {
            allh345s[i].title = 'How other dictionaries treat this term';
          } else if (ht == 'Homophones') {
            allh345s[i].title = 'Terms with the same pronunciation as this term in at least one dialect or accent';
          } else if (ht == 'Pronunciation') {
            allh345s[i].title = 'How to pronounce this term, possibly in various dialects';
          } else if (ht == 'References') {
            allh345s[i].title = 'Links to external language authorities';
          } else if (ht == 'Related terms') {
            allh345s[i].title = 'Terms which are related etymologically other than simple derivations';
          } else if (ht == 'See also') {
            allh345s[i].title = 'Terms which have a semantic relationship but not an etymological one';
          } else if (ht == 'Synonyms') {
            allh345s[i].title = 'Terms with the same meaning in at least one sense';
          } else if (ht == 'Translations') {
            allh345s[i].title = 'Equivalent terms in other languages';
          } else if (ht == 'Usage notes') {
            allh345s[i].title = 'Things to keep in mind when using this term';
          } else {

            // default case - warn that it's nonstandard (or just not handled yet)
            allh345s[i].title = 'This is not a standard Wiktionary heading';
          }
        }
      }
    }
  }
}

/* Remember to keep [[MediaWiki:Standard.js]] in sync with this, for classic style! */
/*
</pre> 
[[bs:MediaWiki:Monobook.js]]
[[he:MediaWiki:Monobook.js]]
[[fr:MediaWiki:Monobook.js]]
[[de:MediaWiki:Monobook.js]]
[[ja:MediaWiki:Monobook.js]]
[[zh:MediaWiki:Monobook.js]]
*/