MediaWiki:Common.js

From Wikisource
Jump to navigation Jump to search

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. */

self.ws_messages = { 
	'iwtrans':'Its text comes from', 
	'iwtrans2':'Its text comes from other sub-domains.',
	'optlist':'Display options',
	'hide_page_numbers':'Hide page links',
	'show_page_numbers':'Show page links',
	'layout':'Layout',
	'author':'Author',
	'translator':'Translator', 
	'editor':'Editor', 
	'publisher':'Publisher', 
	'place':'Place', 
	'volume':'Volume', 
	'school':'School', 
	'book':'Book', 
	'collection':'Collection', 
	'journal':'Journal or magazine', 
	'phdthesis':'Thesis, report', 
	'dictionary':'Dictionary', 
	'progress':'Progress', 
	'progress_T':'Done', 
	'progress_V':'To be validated', 
	'progress_C':'To be proofread', 
	'progress_MS':'Ready for Match & Split', 
	'progress_OCR':'Needs an OCR text layer', 
	'progress_L':'Source file is incorrect (missing pages, unordered pages, etc)',
 
	'page_namespace_name':      'Page',
	'page_trascluded_in':       'Page trascluded in:',
	'text_number':              'Text',

	'compare_with':  'Comparison with:',
	'compare_texts': 'Compare texts'
};

$.getScript( '//wikisource.org/w/index.php?title=MediaWiki:Base.js&action=raw&ctype=text/javascript' )
.done( function() {
	importScript('MediaWiki:InterWikiTransclusion.js');
	importScript('MediaWiki:TranscludedIn.js');
	importScript('MediaWiki:Compare.js');
} );
/* Footnotes as tooltip - from it.wikipedia.org - request by Candalua */

$( function ()
{
 sups = document.getElementsByTagName("sup");
 for (i=0; i<sups.length; i++)
 {
   note_id = sups[i].childNodes[0].href;
   if (note_id && (note_id.indexOf("#") != -1))
   {
     note_id = document.getElementById(note_id.substr(note_id.indexOf("#")+1));
     if (note_id)
       if (document.all) 
       { 
           sups[i].title = note_id.innerText; 
           sups[i].childNodes[0].title = note_id.innerText; 
       } 
       else 
       { 
           sups[i].title = note_id.textContent; 
      }
   }
 }
});

// Add links to Wikidata in the toolbar where [[Module:Interwiki]] is used
$("#t-wikibase").insertBefore($("#p-tb li").last()).removeAttr("style");

// Code to switch sizes for {{Tscore resizable}}
$( function ()
{
	el = document.getElementsByClassName("prp-page-content");
	if (el.length) {
		maxwidth = el[0].clientWidth;
	} else {
		maxwidth = document.getElementById("mw-content-text").clientWidth;
	}
	screslistslist = document.getElementsByClassName("score-resizable-container");
	scressizelist = [];
	for (i = 0; i < screslistslist.length; i++) {
		//maxwidth = screslistslist[i].parentNode.clientWidth;
		screslist = screslistslist[i].getElementsByClassName("score-resizable");
		fitwidth = 0;
		fitelement = -1;
		for (j = 0; j < screslist.length; j++) {
			s = screslist[j].className.match(/score-resizable-size-\d+/);
			scressizelist[j] = parseInt(s[0].match(/\d+/), 10);
			//find largest score that has width < parent width
			if (scressizelist[j] > fitwidth && scressizelist[j] <= maxwidth) {
				fitwidth = scressizelist[j];
				fitelement = j;
			}
		}
		if (fitelement < 0) {
			fitelement = 0;
		}
		for (j = 0; j < screslist.length; j++) {
			if (j != fitelement) {
				screslist[j].style.display = "none";
			}
		}
		screslist[fitelement].style.display = "block";
	}
});