No edit summary |
No edit summary |
||
Line 13: | Line 13: | ||
window.location = this.options[this.selectedIndex].value; | window.location = this.options[this.selectedIndex].value; | ||
}; | }; | ||
var tSelectLang = document.createElement('option'); | |||
tSelectLang.value = window.location.href; | |||
tSelectLang.style = 'background: url(http://wiki.simplemachines.org/extensions/Translate/images/prog-5.png) rgba(0,0,0,0);'; | |||
tSelectLang.appendChild(document.createTextNode('Select your language')); | |||
tSelect.appendChild(tSelectLang); | |||
var tEnglish = document.createElement('option'); | var tEnglish = document.createElement('option'); | ||
tEnglish.value = window.location.href; | tEnglish.value = getEnglishPage(window.location.href); | ||
tEnglish.style = 'background: url(http://wiki.simplemachines.org/extensions/Translate/images/prog-5.png) rgba(0,0,0,0);'; | tEnglish.style = 'background: url(http://wiki.simplemachines.org/extensions/Translate/images/prog-5.png) rgba(0,0,0,0);'; | ||
tEnglish.appendChild(document.createTextNode('English')); | tEnglish.appendChild(document.createTextNode('English')); | ||
Line 41: | Line 47: | ||
} | } | ||
setTimeout("create_translation_dropdown();", 250); | setTimeout("create_translation_dropdown();", 250); | ||
function getEnglishPage(aUrl) | |||
{ | |||
aUrl.replace(aUrl.substr(aUrl.lastIndexOf('/') + 1), ''); | |||
} |
Revision as of 08:28, 24 April 2013
function create_translation_dropdown () { var translation_bar = document.getElementById('translation_bar'); var avail_languages = translation_bar.getElementsByTagName('a'); // Get the <td> where the list is var tds = translation_bar.getElementsByTagName('td'); for (var i = 0; i < tds.length; i++) if (tds[i].className == 'mw-pt-languages-list') var list_position = tds[i]; var tSelect = document.createElement('select'); tSelect.onchange = function() { window.location = this.options[this.selectedIndex].value; }; var tSelectLang = document.createElement('option'); tSelectLang.value = window.location.href; tSelectLang.style = 'background: url(http://wiki.simplemachines.org/extensions/Translate/images/prog-5.png) rgba(0,0,0,0);'; tSelectLang.appendChild(document.createTextNode('Select your language')); tSelect.appendChild(tSelectLang); var tEnglish = document.createElement('option'); tEnglish.value = getEnglishPage(window.location.href); tEnglish.style = 'background: url(http://wiki.simplemachines.org/extensions/Translate/images/prog-5.png) rgba(0,0,0,0);'; tEnglish.appendChild(document.createTextNode('English')); tSelect.appendChild(tEnglish); var langs = avail_languages.length; for (var i = 0; i < langs; i++) { var tOption = document.createElement('option'); tOption.value = avail_languages[0].href; var tImg = avail_languages[0].getElementsByTagName('img')[0]; if (tImg == undefined) continue; tOption.style = 'background: url(' + tImg.src + ') rgba(0,0,0,0);'; avail_languages[0].removeChild(tImg); if (avail_languages[0].innerHTML.replace(/^\s\s*/, '').replace(/\s\s*$/, '') != '') { tOption.appendChild(document.createTextNode(avail_languages[0].innerHTML)); tSelect.appendChild(tOption); } avail_languages[0].parentNode.removeChild(avail_languages[0]); } list_position.innerHTML = ''; list_position.appendChild(tSelect); } setTimeout("create_translation_dropdown();", 250); function getEnglishPage(aUrl) { aUrl.replace(aUrl.substr(aUrl.lastIndexOf('/') + 1), ''); }