MediaWiki:Common.js: Difference between revisions

Jump to navigation Jump to search
mNo edit summary
(Improted from tfwiki (@seb))
Line 335: Line 335:


// End collapsible tables
// End collapsible tables
/*
* Add language-dependent class to <body>
* Adds .lang-something to the body, where "something" is the language of the page.
*/
function langClass() {
  // Supported list of languages (not including the default one):
  var langList = ['ar', 'cs', 'da', 'de', 'es', 'fi', 'fr', 'hu', 'it', 'ja', 'ko', 'nl', 'no', 'pl', 'pt', 'pt-br', 'ro', 'ru', 'sv', 'zh-hans', 'zh-hant'];
  // Assumed language if the page is in none of the languages above:
  var defaultLang = 'en';
  try {
    var body = document.getElementsByTagName('body')[0];
  } catch(e) {
    return;
  }
  var lang = defaultLang;
  for(var i in langList) {
    if(wgPageName.substr(wgPageName.length-1-langList[i].length).toLowerCase() == '/' + langList[i].toLowerCase()) {
      lang = langList[i];
      break;
    }
  }
  if(body.getAttribute('class')) {
    body.setAttribute('class', body.getAttribute('class') + ' lang-' + lang);
  } else {
    body.setAttribute('class', 'lang-' + lang);
  }
}
addOnloadHook(langClass);


// PootTabs by User:WindPower~
// PootTabs by User:WindPower~