MediaWiki:Common.js

No ''Wikibooks''

Piezīme: Lai redzētu izmaiņas, pēc publicēšanas var nākties iztīrīt sava pārlūka kešatmiņu.

  • Firefox / Safari: Pieturi Shift un klikšķini uz Pārlādēt vai nospied Ctrl-F5 vai Ctrl-R (⌘-R uz Mac)
  • Google Chrome: Nospied Ctrl-Shift-R (⌘-Shift-R uz Mac)
  • Internet Explorer / Edge: Pieturi Ctrl un klikšķini uz Pārlādēt vai nospied Ctrl-F5
  • Opera: Nospied Ctrl-F5.
 //<nowiki> Common javascript code which effects everyone
 
 // book name
 var wgBookName = wgPageName.split("/", 1)[0] || wgPageName;
 wgBookName = wgBookName.split(':', 2).join(":");
 
 function get_query_value(query, name)
 {
   if (typeof query != "string" || typeof name != "string")
     return "";
   var value = query.match('[&?]' + name + '=([^&]*)');
   if (value)
     return decodeURIComponent(value[1]);
   else
     return "";
 }
 
 importScript("MediaWiki:Navigation.js");
 importScript("MediaWiki:NavigationTabs.js");
 importScript("MediaWiki:Displaytitle.js");
 
 /** Add dismiss button to watchlist-message *************************************
  *
  *  Description: Hide the watchlist message for one week.
  *  Maintainers: [[w:User:Ruud Koot|Ruud Koot]]
  */
 
 function addDismissButton() {
    var watchlistMessage = document.getElementById("watchlist-message");
    if ( watchlistMessage == null ) return;
    
    if ( document.cookie.indexOf( "hidewatchlistmessage=yes" ) != -1 ) {
        watchlistMessage.style.display = "none";
    }
    
    var Button     = document.createElement( "span" );
    var ButtonLink = document.createElement( "a" );
    var ButtonText = document.createTextNode( "dismiss" );
    
    ButtonLink.setAttribute( "id", "dismissButton" );
    ButtonLink.setAttribute( "href", "javascript:dismissWatchlistMessage();" );
    ButtonLink.setAttribute( "title", "Hide this message for one week" );
    ButtonLink.appendChild( ButtonText );
    
    Button.appendChild( document.createTextNode( "[" ) );
    Button.appendChild( ButtonLink );
    Button.appendChild( document.createTextNode( "]" ) );
    
    watchlistMessage.appendChild( Button );
 }
 
 function dismissWatchlistMessage() {
     var e = new Date();
     e.setTime( e.getTime() + (7*24*60*60*1000) );
     document.cookie = "hidewatchlistmessage=yes; expires=" + e.toGMTString() + "; path=/";
     var watchlistMessage = document.getElementById("watchlist-message");
     watchlistMessage.style.display = "none";
 }
 
 $( addDismissButton );
 
 //////////////////////////////////////////////////////////////////
 // BEGIN RANDOM BOOK
 //////////////////////////////////////////////////////////////////
 
 // Gets a page from the wiki and runs function action on it
 function GetPage(page, action)
 {
   var doc = false;
   
   if (window.XMLHttpRequest)
     doc = new XMLHttpRequest();
   else if (window.ActiveXObject) {
     try {
       doc = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) {
       try {
         doc = new ActiveXObject("Microsoft.XMLHTTP");
       } catch (E) {
       }
     }
   }
   
   if (doc) {
     var url = wgArticlePath.replace(/\$1$/, page);
     doc.onreadystatechange = function() { action(doc); };
     doc.open('GET', url+'?printable=true',  true);
     doc.overrideMimeType('text/xml');
     doc.send(null); 
   }
 }
 
 // Get a random page from Wikibooks:Alphabetical_classification
 function RandomBook()
 {
   function random_book(doc) {
     try {
       if (doc.readyState == 4 && doc.status == 200)
       {
         var wiki = doc.responseXML;
         if (wiki)
         {
           var books = wiki.getElementById('books').getElementsByTagName('li');
           if (books && books.length > 0) {
             var page = books.item(Math.floor(Math.random() * books.length + 1)).firstChild;
             while ($(page).hasClass( "new") || $(page).hasClass( "external")) {
               page = books.item(Math.floor(Math.random() * books.length + 1)).firstChild;
             }
             window.location = page.href;
           }
         }
       }
     } catch (e) { }
   }
   GetPage("Wikibooks:Alfab\u0113tiska_klasifik\u0101cija", random_book);
 }
 
 // Adds a random book link to the navigation toolbar and calls RandomBook when clicked
 function RandomBookLink() {
   var tb = document.getElementById('p-Navigation');
   var link = document.createElement('a');
   var li = document.createElement('li');
   
   if (tb) {
     tb = tb.getElementsByTagName('ul')[0];
     link.href = "javascript:RandomBook();";
     link.title = "Random Book";
     link.onmouseover = function() { window.status = "Random Book"; return true; }
     link.onmouseout = function() { window.status = ""; return true; }
     link.appendChild(document.createTextNode("Random book"));
     li.id = "n-random-book";
     li.appendChild(link);
     tb.appendChild(li);
   }
 }
 
 $( RandomBookLink );
 
 //Removes the default no-license option for image uploads. 
 //All new image uploads must be tagged with a license or nld
 function remove_no_license() {
   if (wgPageName != "Special:Upload")
     return;
   var license = document.getElementById("wpLicense");
   if (!license)
     return;
   var options = license.getElementsByTagName("option");
   if (!options)
     return;
   license.removeChild(options[0]);
 }
 
 $(remove_no_license);

 //</nowiki> End of Common.js