Common.js

Revision as of 09:30, 15 November 2019 by Registered User

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.
/* Any JavaScript here will be loaded for all users on every page load. */

/* HW, rvogel:  importScript is not available in MW 1.31 anymore. */
function importScript( pageName ) {
	mw.loader.using( 'mediawiki.Title', function() {
		var title = mw.Title.newFromText( pageName );
		var url = title.getUrl( {'action':'raw','ctype':'text/javascript'} );
		mw.loader.load( url );
	} );
}

/** Collasible tables & frames *************************************
 *  Please have a look to css in MediaWiki:Common.css 
 */
//importScript("MediaWiki:Collapsible-tables.js"); // With [show] / [hide]
//importScript("MediaWiki:Collapsible-frames.js"); // With [show] / [hide]
/*HW, Dsavuljesku: All scripts loaded below are moved to the extension*/
//importScript("MediaWiki:Collapsible-tables-pm.js"); // With [+] / [-]
//importScript("MediaWiki:Collapsible-frames-pm.js"); // With [+] / [-]


//importScript("MediaWiki:Imagemap-Highlight.js");

//importScript("MediaWiki:AddLinkToTop.js");

//importScript("MediaWiki:RotateTable.js");

//importScript("MediaWiki:Copy2Clipboard.js");

/* Jean-Christophe Trotin: add a ST custom menu in the WikiEditor toolbar */
importScript("MediaWiki:CustomizeToolbar.js");

/*HW, DS: Hack until release 12.02 */
delete( Array.prototype.exclude );

/* ******************** HELPERS ****************** */

/** Test if an element has a certain class
 *
 * 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 );
        };
})();


function replaceText(oldText, newText, node){ 
  node = node || document.body; // base node 

  var childs = node.childNodes, i = 0;

  while(node = childs[i]){ 
//console.log("coucou" + node.nodeName);
    if (node.nodeType == 3){ // text node found, do the replacement

      if (node.textContent) {
        node.textContent = node.textContent.replace(oldText, newText);

      } else { // support to IE
        node.nodeValue = node.nodeValue.replace(oldText, newText);
      }
    } else { // not a text mode, look forward
      replaceText(oldText, newText, node); 
    } 
    i++; 
  } 
}

//$(document).ready(replaceText('PCO ', 'PCO ') );

/* Show few items dedicated to writers only when logged */
function hide_edition() {
  if (wgUserName) {
    $('#n-Help-\\.26-Syntax, #n-Glossary, #n-Contributors').css('display', 'block');
  }
}
$(document).ready(hide_edition());
No categories assignedEdit