Template:LangMenu: Difference between revisions
From MediaWiki
(Created page with "<div class="selectlang"> <select id="language-select"> <option value="ru">Russian</option> <option value="en">English</option> <option value="zh">Chinese</option> </select> </div> <script> // Код JavaScript для обработки событий и перенаправления $(function() { var url = window.location.href; var languageCode = url.substring(url.lastIndexOf('/') + 1); var languageMenuEl...") |
No edit summary |
||
Line 47: | Line 47: | ||
}); | }); | ||
</script> | </script> | ||
Latest revision as of 20:39, 3 August 2023
<select id="language-select"> <option value="ru">Russian</option> <option value="en">English</option> <option value="zh">Chinese</option> </select>
<script>
// Код JavaScript для обработки событий и перенаправления $(function() { var url = window.location.href; var languageCode = url.substring(url.lastIndexOf('/') + 1); var languageMenuElement = document.getElementById('language-select');
if (languageCode.length === 2) { languageMenuElement.value = languageCode; } else { languageMenuElement.value = "ru"; }
var langCodes = ['en', 'ru', 'zh']; for (var i = 0; i < langCodes.length; i++) { var langCode = '/' + langCodes[i]; if (url.endsWith(langCode)) { url = url.slice(0, -langCode.length); } }
url = url.replace(/\/{2,}/g, '/'); var newUrl = url.replace("/wiki.gativus.com", "");
$('#language-select').change(function() { var selectedLanguage = $(this).val(); switch (selectedLanguage) { case 'ru': window.location.href = newUrl; break; case 'en': window.location.href = newUrl + "/en"; break; case 'zh': window.location.href = newUrl + "/zh"; break; } }); });
</script>