Sha256: 4bfddfb25f45cbc55a81a3f57e62fe460623a3f61873002aaeffe61e87e2ad61
Contents?: true
Size: 1.69 KB
Versions: 31
Compression:
Stored size: 1.69 KB
Contents
// Usage: // WorldFlagsUrlHelper.reloadWithLocaleParam('da'); var WorldFlagsUrlHelper = { reloadWithLocaleParam: function(locale) { // will reload page with 'locale' param added for locale // fx www.example.com?locale=da // or www.example.com?status=ok&locale=da window.location.href = this.addLocaleParameter(window.location.href, locale); }, addLocaleParameter: function(url, locale) { //return this.addParameterToURL(url, 'locale', locale); return this.addUrlParameter(url, 'locale', locale, true); }, // From http://stackoverflow.com/questions/486896/adding-a-parameter-to-the-url-with-javascript addUrlParameter: function (sourceUrl, parameterName, parameterValue, replaceDuplicates) { if ((sourceUrl == null) || (sourceUrl.length == 0)) sourceUrl = document.location.href; var urlParts = sourceUrl.split("?"); var newQueryString = ""; if (urlParts.length > 1) { var parameters = urlParts[1].split("&"); for (var i=0; (i < parameters.length); i++) { var parameterParts = parameters[i].split("="); if (!(replaceDuplicates && parameterParts[0] == parameterName)) { if (newQueryString == "") newQueryString = "?"; else newQueryString += "&"; newQueryString += parameterParts[0] + "=" + parameterParts[1]; } } } if (newQueryString == "") newQueryString = "?"; else newQueryString += "&"; newQueryString += parameterName + "=" + parameterValue; return urlParts[0] + newQueryString; } }
Version data entries
31 entries across 31 versions & 1 rubygems