MediaWiki:Common.js

From Wikiversity

Jump to: navigation, search

Note - After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh); Konqueror: click Reload or press F5; Opera: clear the cache in Tools → Preferences; Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.

/* Any JavaScript here will be loaded for all users on every page load. */
 
//<pre>
// BEGIN hasClass
// Description: Uses regular expressions and caching for better performance.
// Maintainers: User:Mike Dillon, User:R. Koot, User:SG
 
var hasClass = (function () {
    var reCache = {};
    return function (element, className) {
        return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
    };
})();
// END hasClass
 
// Provides an easy way to disable unwanted load dependent features
function delOnloadHook(hookFunct) {
  for (var i = 0; i < onloadFuncts.length; i++) {
    if (onloadFuncts[i] == hookFunct)
      onloadFuncts.splice(i, 1);
  }
}
 
// Provides an easy way to import additional scripts local to the wiki
function import_script(name)
{
  name = encodeURIComponent(name);
  document.write('<script type="text/javascript" src="/w/index.php?title=' + name + '&action=raw&ctype=text/javascript"><\/script>');
}
 
import_script("MediaWiki:Navigation.js");  // collapsible tables and dynamic navigation
import_script("MediaWiki:ExtraTabs.js");   // additional tabs for the toolbox
import_script("MediaWiki:EditToolbar.js"); // additional edit tools
import_script("MediaWiki:Displayname.js"); // change the namespace tab and the display title
import_script("MediaWiki:Tables.js");      // change style of some tables
 
 /** 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";
 }
 
 addOnloadHook( addDismissButton );
 
//</pre>