NodeBB language dropdown menu in navbar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function () { | |
var url = new URL(window.location.href); | |
//if (!url.searchParams.get('lang')) { | |
// url.searchParams.set('lang', 'en-US'); | |
// window.location.href = ; | |
//} | |
document.getElementById('langOpt').value = url.searchParams.get('lang'); | |
}); | |
var langOpt = ['EN','UR']; | |
var langOptValue = ['en-US', 'ur']; | |
var langEle = document.createElement("li"); | |
var selectLang = document.createElement("select"); | |
selectLang.id = "langOpt"; | |
selectLang.setAttribute("class", "form-control"); | |
selectLang.style["margin-top"] = "11px"; | |
selectLang.style["margin-bottom"] = "3px"; | |
selectLang.style["height"] = "30px"; | |
selectLang.style["padding"] = "3px"; | |
selectLang.onchange= () => { | |
var currentUrl = window.location.href; | |
var newUrl = new URL(currentUrl); | |
newUrl.searchParams.set('lang', selectLang.value); | |
window.location.href = newUrl; | |
}; | |
langEle.appendChild(selectLang); | |
var loggedInMenu = document.getElementById("logged-in-menu"); | |
loggedInMenu.appendChild(langEle); | |
for (var i = 0; i < langOpt.length; i++) { | |
var option = document.createElement("option"); | |
option.value = langOptValue[i]; | |
option.text = langOpt[i]; | |
selectLang.appendChild(option); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment