Корбар:Aidan Kehoe/LanguageLinks.js: Тафовут байни таҳрирҳо
Content deleted Content added
Aidan Kehoe (баҳс | ҳисса) Саҳифаро холӣ кард |
Aidan Kehoe (баҳс | ҳисса) Ботили нусхаи 235806 аз тарафи Aidan Kehoe (Баҳс) |
||
Сатри 1: | Сатри 1: | ||
/* |
|||
* LanguageLinks.js |
|||
* |
|||
* Changes the text of language links in the sidebar, |
|||
* by replacing the name of the language with the code |
|||
* of the language and the name of the linked page, |
|||
* changing the language box into an ersatz multi-lingual |
|||
* dictionary. |
|||
* |
|||
*/ |
|||
// wait for everything to load |
|||
addOnloadHook(function() { |
|||
// get the language portlet |
|||
langs = document.getElementById('p-lang'); |
|||
// proceed only if the language portlet exists |
|||
if(langs) { |
|||
// get the links |
|||
var lnks=langs.getElementsByTagName('a'); |
|||
// start building the replacement table |
|||
var html = '<table style="font-size:90%;width:100%">'; |
|||
// cycle through all the links |
|||
for (var i=0;i<lnks.length;i++) { |
|||
lnk=lnks[i]; |
|||
// FF vs. IE 6 |
|||
href = document.addEventListener |
|||
? lnk.href |
|||
: lnk.href.replace(/\/wiki\/(.*)$/,'') + '/wiki/' + escape(lnk.href.replace(/^.*?\/wiki\//,'')); |
|||
// extract the language code and the page from the URL |
|||
var page=href.replace(/^.*?\/wiki\//,'').replace(/_/g,' '); |
|||
var lang=href.replace(/(^http:\/\/|\..*$)/g,''); |
|||
// prepare new text |
|||
// If pointing to the main page on another wiki, use the |
|||
// long language name, otherwise use the linked page's name. |
|||
var text = page == '' ? lnk.innerHTML : decodeURIComponent(page); |
|||
// for short language codes, make one row in the table |
|||
if (lang.length<4) |
|||
{ |
|||
html += '<tr><td style="width:2.5em" valign="top"><tt title="'+lnk.innerHTML+'">' |
|||
+ lang |
|||
+ ':</tt></td>' |
|||
+ '<td valign="top"><a href="'+href+'" title="'+lnk.innerHTML+'">' + text +'</a></td></tr>'; |
|||
} |
|||
// for long language codes, make two rows |
|||
else |
|||
{ |
|||
html += '<tr><td valign="top" colspan="2"><tt title="'+lnk.innerHTML+'">' |
|||
+ lang |
|||
+ ':</tt></td></tr>' |
|||
+ '<tr><td></td><td valign="top"><a href="'+href+'" title="'+lnk.innerHTML+'">' + text +'</a></td></tr>'; |
|||
} |
|||
}; // end of the loop |
|||
// finish the table |
|||
html += '</table>'; |
|||
//insert it into the first div in the portlet |
|||
langs.getElementsByTagName('div')[0].innerHTML=html |
|||
}; |
|||
}); |
Нусха 20:24, 6 июни 2011
/*
* LanguageLinks.js
*
* Changes the text of language links in the sidebar,
* by replacing the name of the language with the code
* of the language and the name of the linked page,
* changing the language box into an ersatz multi-lingual
* dictionary.
*
*/
// wait for everything to load
addOnloadHook(function() {
// get the language portlet
langs = document.getElementById('p-lang');
// proceed only if the language portlet exists
if(langs) {
// get the links
var lnks=langs.getElementsByTagName('a');
// start building the replacement table
var html = '<table style="font-size:90%;width:100%">';
// cycle through all the links
for (var i=0;i<lnks.length;i++) {
lnk=lnks[i];
// FF vs. IE 6
href = document.addEventListener
? lnk.href
: lnk.href.replace(/\/wiki\/(.*)$/,'') + '/wiki/' + escape(lnk.href.replace(/^.*?\/wiki\//,''));
// extract the language code and the page from the URL
var page=href.replace(/^.*?\/wiki\//,'').replace(/_/g,' ');
var lang=href.replace(/(^http:\/\/|\..*$)/g,'');
// prepare new text
// If pointing to the main page on another wiki, use the
// long language name, otherwise use the linked page's name.
var text = page == '' ? lnk.innerHTML : decodeURIComponent(page);
// for short language codes, make one row in the table
if (lang.length<4)
{
html += '<tr><td style="width:2.5em" valign="top"><tt title="'+lnk.innerHTML+'">'
+ lang
+ ':</tt></td>'
+ '<td valign="top"><a href="'+href+'" title="'+lnk.innerHTML+'">' + text +'</a></td></tr>';
}
// for long language codes, make two rows
else
{
html += '<tr><td valign="top" colspan="2"><tt title="'+lnk.innerHTML+'">'
+ lang
+ ':</tt></td></tr>'
+ '<tr><td></td><td valign="top"><a href="'+href+'" title="'+lnk.innerHTML+'">' + text +'</a></td></tr>';
}
}; // end of the loop
// finish the table
html += '</table>';
//insert it into the first div in the portlet
langs.getElementsByTagName('div')[0].innerHTML=html
};
});