MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
Spangineer (talk | contribs) fix instruction: have to set to "true" to disable |
for sandbox |
||
Line 45: | Line 45: | ||
/* dynamic layouts */ |
/* dynamic layouts */ |
||
self.ws_layouts = { |
if(!self.ws_layouts) self.ws_layouts = {}; |
||
self.ws_layouts['Layout 1'] = { |
|||
'text-wrap':"", |
|||
'#text-container':"" , |
'#text-container':"" , |
||
'#text':"", |
'#text':"", |
||
Line 52: | Line 53: | ||
'.sidenote-left':"float:left;margin:0.5em;padding:3px;border:solid 1px gray;max-width:9em;text-indent:0em;text-align:left;", |
'.sidenote-left':"float:left;margin:0.5em;padding:3px;border:solid 1px gray;max-width:9em;text-indent:0em;text-align:left;", |
||
'.editsection':"display:none", |
'.editsection':"display:none", |
||
'#headertemplate':"" } |
'#headertemplate':"" |
||
}; |
|||
self.ws_layouts['Layout 2'] = { |
|||
'text-wrap':"position:relative;margin-left:3em;margin-right:3em;", |
|||
'#text-container':"width:36em;margin:0px auto;font-family:Georgia,serif;" , |
'#text-container':"width:36em;margin:0px auto;font-family:Georgia,serif;" , |
||
'#text':"text-align:justify;", |
'#text':"text-align:justify;", |
||
Line 59: | Line 62: | ||
'.sidenote-left':"position:absolute; right:37em;width:16em;text-indent:0em;text-align:right;", |
'.sidenote-left':"position:absolute; right:37em;width:16em;text-indent:0em;text-align:right;", |
||
'.editsection':"display:none", |
'.editsection':"display:none", |
||
'#headertemplate':"" } |
'#headertemplate':"" |
||
}; |
|||
self.ws_layouts['Layout 3'] = { |
|||
'text-wrap':"margin-left:3em", |
|||
'#text-container':"position:relative; min-width:60em; float:left; width:100%; margin-right:-23em;" , |
'#text-container':"position:relative; min-width:60em; float:left; width:100%; margin-right:-23em;" , |
||
'#text':"text-align:justify;margin-right:23em; text-indent:0em; padding-left:0px; padding-right:0px;width:auto;", |
'#text':"text-align:justify;margin-right:23em; text-indent:0em; padding-left:0px; padding-right:0px;width:auto;", |
||
Line 66: | Line 71: | ||
'.sidenote-left': "position:absolute; right:-10em; width:9em; background-color:#eeeeee;text-indent:0em;text-align:left;", |
'.sidenote-left': "position:absolute; right:-10em; width:9em; background-color:#eeeeee;text-indent:0em;text-align:left;", |
||
'.editsection':"display:none", |
'.editsection':"display:none", |
||
'#headertemplate':"position:absolute; top:0em; right:-23em; width:21em;float:right; text-align:left;" |
'#headertemplate':"position:absolute; top:0em; right:-23em; width:21em;float:right; text-align:left;" |
||
} |
}; |
||
Revision as of 10:55, 20 February 2011
// <source lang="javascript">
/*
* scripts imported from wikisource.org
*/
/* messages are configurable here */
self.ws_messages = {
'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_X':'Source file is an excerpt of a larger volume, or a mixture of several sources',
'progress_L':'Source file is incorrect (missing pages, unordered pages, etc)',
'▲':'Return to the top of the page.',
'corr_list':"List of corrections performed on this page" ,
'corr_link':"Corrections" ,
'corr_one':"One typo </a> has been corrected." ,
'corr_many':" typos</a> have been corrected." ,
'corr_close':"Close." ,
'iwtrans':'Its text comes from',
'iwtrans2':'Its text comes from other Wikisource subdomains.'
}
/* dynamic layouts */
if(!self.ws_layouts) self.ws_layouts = {};
self.ws_layouts['Layout 1'] = {
'text-wrap':"",
'#text-container':"" ,
'#text':"",
'.sidenote-right':"float:right;margin:0.5em;padding:3px;border:solid 1px gray;max-width:9em;text-indent:0em;text-align:left;",
'.sidenote-left':"float:left;margin:0.5em;padding:3px;border:solid 1px gray;max-width:9em;text-indent:0em;text-align:left;",
'.editsection':"display:none",
'#headertemplate':""
};
self.ws_layouts['Layout 2'] = {
'text-wrap':"position:relative;margin-left:3em;margin-right:3em;",
'#text-container':"width:36em;margin:0px auto;font-family:Georgia,serif;" ,
'#text':"text-align:justify;",
'.sidenote-right':"position:absolute; left:37em;width:16em;text-indent:0em;text-align:left;",
'.sidenote-left':"position:absolute; right:37em;width:16em;text-indent:0em;text-align:right;",
'.editsection':"display:none",
'#headertemplate':""
};
self.ws_layouts['Layout 3'] = {
'text-wrap':"margin-left:3em",
'#text-container':"position:relative; min-width:60em; float:left; width:100%; margin-right:-23em;" ,
'#text':"text-align:justify;margin-right:23em; text-indent:0em; padding-left:0px; padding-right:0px;width:auto;",
'.sidenote-right':"position:absolute; right:-10em; width:9em; background-color:#eeeeee;text-indent:0em;text-align:left;",
'.sidenote-left': "position:absolute; right:-10em; width:9em; background-color:#eeeeee;text-indent:0em;text-align:left;",
'.editsection':"display:none",
'#headertemplate':"position:absolute; top:0em; right:-23em; width:21em;float:right; text-align:left;"
};
self.proofreadpage_add_container = true;
importScriptURI('http://wikisource.org/w/index.php?title=MediaWiki:Base.js&action=raw&ctype=text/javascript');
importScriptURI('http://wikisource.org/w/index.php?title=MediaWiki:OCR.js&action=raw&ctype=text/javascript');
importScriptURI('http://wikisource.org/w/index.php?title=MediaWiki:DisplayFooter.js&action=raw&ctype=text/javascript');
importScriptURI('http://wikisource.org/w/index.php?title=MediaWiki:PageNumbers.js&action=raw&ctype=text/javascript');
importScriptURI('http://wikisource.org/w/index.php?title=MediaWiki:Corrections.js&action=raw&ctype=text/javascript');
importScriptURI('http://wikisource.org/w/index.php?title=MediaWiki:IndexForm.js&action=raw&ctype=text/javascript');
importScriptURI('http://wikisource.org/w/index.php?title=MediaWiki:Dictionary.js&action=raw&ctype=text/javascript');
importScriptURI('http://wikisource.org/w/index.php?title=MediaWiki:InterWikiTransclusion.js&action=raw&ctype=text/javascript');
/*
Mouse wheel zoom should work now for most browsers.
If it does not work for you, set this to true in your javascript.
*/
self.proofreadpage_disable_wheelzoom = false;
/**********************
*** Allow descriptive labels next to sidebar language links using {{interwiki-info}}
*** by [[user:ThomasV]]
**********************/
function interwikiExtra() {
// iterate over all <span>-elements
for(var i=0; a=document.getElementsByTagName('span')[i]; i++) {
// if found a linkInfo span
if(a.className == 'interwiki-info') {
// iterate over all <li>-elements
var count=0;
for(var j=0; b=document.getElementsByTagName('li')[j]; j++) {
if(b.className == 'interwiki-' + a.id) {
b.innerHTML = b.innerHTML + ' ' + a.title;
if(a.title == '(vo)') {
b.title = 'Texte original';
}
}
else if(b.className == 'interwiki-' + a.id.substr(0, a.id.length-1)) {
count++;
if(a.id.charAt(a.id.length-1) == count) {
b.innerHTML = b.innerHTML + ' ' + a.title;
}
}
}
}
}
}
addOnloadHook(interwikiExtra);
/**********************
*** Quality indicators on "article" tab
*** by [[user:ThomasV]]
**********************/
// return src for icon given percentage
function icon_src(t){
var src='http://upload.wikimedia.org/wikipedia/commons/';
switch(t){
case '0%': src+='8/8f/00'; break;
case '25%': src+='5/5b/25'; break;
case '50%': src+='3/3a/50'; break;
case '75%': src+='c/cd/75'; break;
case '100%': src+='6/64/100'; break;
}
return src + '%25.png';
}
// add indicator
function pageQuality() {
var a = document.getElementById('ca-nstab-main');
if(!a) return;
var pr_index = document.getElementById('pr_index');
if(pr_index) return;
var q = document.getElementById('textquality');
if(q) {
var new_img = document.createElement('img');
new_img.setAttribute('src', icon_src(q.className));
a.firstChild.appendChild(new_img);
}
for(var i=0; spanElem = document.getElementsByTagName('span')[i]; i++) {
if (spanElem.className == 'pagequality') {
var new_img = document.createElement('img');
new_img.setAttribute('src', icon_src(spanElem.title));
if(wgCanonicalNamespace == 'Page') {
a.firstChild.appendChild(new_img);
}
else {
s1 = spanElem.parentNode.previousSibling;
opttext = s1.firstChild.firstChild;
img = opttext.firstChild.nextSibling.nextSibling.nextSibling;
next = img.nextSibling;
opttext.removeChild(img);
opttext.insertBefore(new_img,next);
}
}
}
}
addOnloadHook(pageQuality);
//add link to the extension [[user:sanbeg]]
function pr_add_quality_buttons_link(){
if(typeof proofreadPageMessageStatus == 'undefined') return;
if( self.proofreadpage_no_quality_buttons ) return;
var ig = document.getElementById("wpWatchthis");
if( !ig ) return;
var f = document.createElement("span");
f.innerHTML = ' (<a href="/wiki/Help:Page Status">help</a>)';
ig.parentNode.insertBefore(f,ig.nextSibling.nextSibling.nextSibling.nextSibling);
}
addOnloadHook(pr_add_quality_buttons_link);
/**********************
*** Add arrows on sidebar to compare current page to interlanguage link'd page
*** by [[user:Pathoschild]], based on older script by unknown
**********************/
function BilingualLink() {
if(document.getElementById('p-lang') != null) {
// get list of links
var biboxes = document.getElementById('p-lang').getElementsByTagName('li');
// iterate over links
for(var i=0; i<biboxes.length; i++) {
// get link
var bilink = biboxes[i].getElementsByTagName('a')[0];
// create new URL
var bilang = bilink.getAttribute('href').match(/http:\/\/([^\.]+)\.wikisource/)[1];
var bilanglink = wgServer + wgArticlePath.replace('$1', encodeURIComponent(wgPageName)) + '?match=' + bilang;
// create link
var bianchor = document.createElement('a');
bianchor.setAttribute('href',bilanglink);
bianchor.setAttribute('title','Compare this page with the '+bilang+' version.');
bianchor.appendChild(document.createTextNode(' ⇔'));
// add link
biboxes[i].appendChild(bianchor);
}
}
}
addOnloadHook(BilingualLink);
/****************
*** Allows extra script to run in Special:Watchlist — addition of announcements
*** script allows users to dismiss Mediawiki:watchlist-announcements, as per sitenotice
*** user:billinghurst 20100522, as hacked from WP script
*****************/
if (wgPageName == "Special:Watchlist") //watchlist scripts
{
importScript("MediaWiki:Common.js/watchlist.js")
}
/**********************
*** Script to rewrite external links to Wikipedia (and other Wikimedia projects) to
*** use the secure server when already browsing from https://secure.wikimedia.org, so
*** that links to diffs, etc., don't take you off the site.
*** user:billinghurst 20110111; importing script direct from Commons
***********************/
/* importScript("MediaWiki:Common.js/secure.js") */
if( wgServer == 'https://secure.wikimedia.org' ) {
importScriptURI('http://en.wikipedia.org/w/index.php?title=MediaWiki:Common.js/secure.js&action=raw&ctype=text/javascript');
}
/**********************
*** add menu on edit page /for selecting subsets of special characters
*** by [[user:Pathoschild]]
*** - note: must match MediaWiki:Edittools
**********************/
function addCharSubsetMenu() {
var specialchars = document.getElementById('specialchars');
if (specialchars) {
var menu = "<select style=\"display:inline\" onChange=\"chooseCharSubset(selectedIndex)\">";
menu += "<option>Select</option>";
menu += "<option>Ligatures and symbols</option>";
menu += "<option>Accents</option>";
menu += "<option>Tildes</option>";
menu += "<option>Cedillas</option>";
menu += "<option>Diereses</option>";
menu += "<option>Circumflexes</option>";
menu += "<option>Macrons</option>";
menu += "<option>Other diacritics</option>";
menu += "<option>Greek</option>";
menu += "<option>Hebrew</option>";
menu += "<option>Cyrillic</option>";
menu += "<option>IPA</option>";
menu += "</select>";
specialchars.innerHTML = menu + specialchars.innerHTML.replace(/_newline_/gm, "\n");
/* default subset - try to use a cookie some day */
chooseCharSubset(0);
}
}
/* select subsection of special characters */
function chooseCharSubset(s) {
var l = document.getElementById('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';
}
}
addOnloadHook(addCharSubsetMenu);
/*************
*** Execute JS file in MediaWiki namespace with &usejs parameter on any page
*** by [[m:user:Pathoschild]] <http://meta.wikimedia.org/wiki/User:Pathoschild/Scripts/Usejs>
*************/
document.write('<script type="text/javascript" src="'
+ 'http://meta.wikimedia.org/w/index.php?title=User:Pathoschild/Scripts/Usejs.js'
+ '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
/** Collapsible tables *********************************************************
*
* Description: Allows tables to be collapsed, showing only the header. See
* [[w:Wikipedia:NavFrame]].
* Maintainers: [[w:User:R. Koot]]
*/
var autoCollapse = 2;
var collapseCaption = "hide";
var expandCaption = "show";
function collapseTable( tableIndex )
{
var Button = document.getElementById( "collapseButton" + tableIndex );
var Table = document.getElementById( "collapsibleTable" + tableIndex );
if ( !Table || !Button ) {
return false;
}
var Rows = Table.rows;
if ( Button.firstChild.data == collapseCaption ) {
for ( var i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = "none";
}
Button.firstChild.data = expandCaption;
} else {
for ( var i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = Rows[0].style.display;
}
Button.firstChild.data = collapseCaption;
}
}
function createCollapseButtons()
{
var tableIndex = 0;
var NavigationBoxes = new Object();
var Tables = document.getElementsByTagName( "table" );
for ( var i = 0; i < Tables.length; i++ ) {
if ( hasClass( Tables[i], "collapsible" ) ) {
/* only add button and increment count if there is a header row to work with */
var HeaderRow = Tables[i].getElementsByTagName( "tr" )[0];
if (!HeaderRow) continue;
var Header = HeaderRow.getElementsByTagName( "th" )[0];
if (!Header) continue;
NavigationBoxes[ tableIndex ] = Tables[i];
Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );
var Button = document.createElement( "span" );
var ButtonLink = document.createElement( "a" );
var ButtonText = document.createTextNode( collapseCaption );
Button.style.styleFloat = "right"; //
Button.style.cssFloat = "right"; // REMOVE THESE LINES
Button.style.fontWeight = "normal"; // ON 10 FEBRUARY 2009
Button.style.textAlign = "right"; //
Button.style.width = "6em"; //
Button.className = "collapseButton"; //Styles are declared in Common.css
ButtonLink.style.color = Header.style.color;
ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" );
ButtonLink.appendChild( ButtonText );
Button.appendChild( document.createTextNode( "[" ) );
Button.appendChild( ButtonLink );
Button.appendChild( document.createTextNode( "]" ) );
Header.insertBefore( Button, Header.childNodes[0] );
tableIndex++;
}
}
for ( var i = 0; i < tableIndex; i++ ) {
if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) {
collapseTable( i );
}
else if ( hasClass( NavigationBoxes[i], "innercollapse" ) ) {
var element = NavigationBoxes[i];
while (element = element.parentNode) {
if ( hasClass( element, "outercollapse" ) ) {
collapseTable ( i );
break;
}
}
}
}
}
addOnloadHook( createCollapseButtons );
/** Dynamic Navigation Bars (experimental) *************************************
*
* Description: See [[w:Wikipedia:NavFrame]].
* Maintainers: UNMAINTAINED
*/
// set up the words in your language
var NavigationBarHide = '[' + collapseCaption + ']';
var NavigationBarShow = '[' + expandCaption + ']';
// 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 != null; NavChild = NavChild.nextSibling) {
if ( hasClass( NavChild, 'NavPic' ) ) {
NavChild.style.display = 'none';
}
if ( hasClass( NavChild, 'NavContent') ) {
NavChild.style.display = 'none';
}
}
NavToggle.firstChild.data = NavigationBarShow;
// if hidden now
} else if (NavToggle.firstChild.data == NavigationBarShow) {
for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
if (hasClass(NavChild, 'NavPic')) {
NavChild.style.display = 'block';
}
if (hasClass(NavChild, 'NavContent')) {
NavChild.style.display = 'block';
}
}
NavToggle.firstChild.data = NavigationBarHide;
}
}
// adds show/hide-button to navigation bars
function createNavigationBarToggleButton()
{
var indexNavigationBar = 0;
// iterate over all < div >-elements
var divs = document.getElementsByTagName("div");
for (var i = 0; NavFrame = divs[i]; i++) {
// if found a navigation bar
if (hasClass(NavFrame, "NavFrame")) {
indexNavigationBar++;
var NavToggle = document.createElement("a");
NavToggle.className = 'NavToggle';
NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');
var isCollapsed = hasClass( NavFrame, "collapsed" );
/*
* Check if any children are already hidden. This loop is here for backwards compatibility:
* the old way of making NavFrames start out collapsed was to manually add style="display:none"
* to all the NavPic/NavContent elements. Since this was bad for accessibility (no way to make
* the content visible without JavaScript support), the new recommended way is to add the class
* "collapsed" to the NavFrame itself, just like with collapsible tables.
*/
for (var NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling) {
if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) {
if ( NavChild.style.display == 'none' ) {
isCollapsed = true;
}
}
}
if (isCollapsed) {
for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) {
NavChild.style.display = 'none';
}
}
}
var NavToggleText = document.createTextNode(isCollapsed ? NavigationBarShow : 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 (hasClass(NavFrame.childNodes[j], "NavHead")) {
NavFrame.childNodes[j].appendChild(NavToggle);
}
}
NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
}
}
}
addOnloadHook( createNavigationBarToggleButton );
/************
*****Description: Uses regular expressions and caching for better performance to determine if an element has a class.
*****original authors (stolen from wikipedia): w:User:Mike Dillon, w:User:R. Koot, w: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);
};
})();
/*
* port from [[:he:mediawiki:common.js]] for [[mediawiki:edittools]] -Steve
*/
/* פונקציה שמשמשת לאיפשור ניקוד ב[[מדיה ויקי:edittools]] */
function nikud(){
if (document.getElementById('edit-templates')!=null){
for(var i=0; a = document.getElementsByTagName("span")[i]; i++) {
if(a.className == "nikud") {
a.onclick=function(){insertTags('', this.title, '');return false;};
}
}
}
}
addOnloadHook(nikud);
/** Adds withJS support to wikisource *******
*
* Matches the withJS support on en.wikipedia and commons
* added by [[User:Mdale]]
*
**/
// Escape all RegExp special characters such that the result can be safely used
// in a RegExp as a literal.
if( typeof String.prototype.escapeRE === 'undefined' ) {
String.prototype.escapeRE = function() {
return this.replace(/([\\{}()|.?*+^$\[\]])/g, "\\$1");
};
}
/** extract a URL parameter from the current URL **********
*
* paramName : the name of the parameter to extract
* url : optional URL to extract the parameter from, document.location.href if not given.
*
* Local Maintainer: [[User:Dschwen]], [[User:Lupo]], [[User:Krinkle]]
*/
function getParamValue( paramName, url)
{
url = url ? url : document.location.href;
// Get last match, stop at hash
var re = new RegExp( '[^#]*[&?]' + paramName.escapeRE() + '=([^&#]*)' );
var m = re.exec( url );
if( m && m.length > 1 ) {
return decodeURIComponent( m[1] );
}
return null;
}
/** &withJS= URL parameter *******
* Allow to try custom scripts on the MediaWiki namespace without
* editing [[Special:Mypage/monobook.js]]
*
* Maintainer: [[User:Platonides]], [[User:Lupo]]
*/
var extraJS = getParamValue('withJS');
// Leave here for backwards compatibility
(function(extraJS)
{
if( !extraJS ) {
return;
}
if( extraJS.match(/^MediaWiki:[^&<>=%#]*\.js$/) ) {
// Disallow some characters in file name
importScript(extraJS);
} else {
// Dont use alert but the jsMsg system. Run jsMsg only once the DOM is ready.
$(document).ready(function() {
jsMsgAppend(document.createTextNode(extraJS + ' javascript not allowed to be loaded.'), 'error');
});
}
})(extraJS);
// </source>