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

Version Path
world-flags-0.6.6 app/assets/javascripts/world_flags/url_helper.js
world-flags-0.6.5 vendor/assets/javascripts/world_flags/url_helper.js
world-flags-0.6.4 vendor/assets/javascripts/world_flags/url_helper.js
world-flags-0.6.3.1 vendor/assets/javascripts/world_flags/url_helper.js
world-flags-0.6.3 vendor/assets/javascripts/world_flags/url_helper.js
world-flags-0.6.2.1 vendor/assets/javascripts/world_flags/url_helper.js
world-flags-0.6.2 vendor/assets/javascripts/world_flags/url_helper.js
world-flags-0.6.1.1 vendor/assets/javascripts/world_flags/url_helper.js
world-flags-0.6.1 vendor/assets/javascripts/world_flags/url_helper.js
world-flags-0.6.0 vendor/assets/javascripts/world_flags/url_helper.js
world-flags-0.5.1 vendor/assets/javascripts/world_flags/url_helper.js
world-flags-0.5.0 vendor/assets/javascripts/world_flags/url_helper.js
world-flags-0.4.9 vendor/assets/javascripts/world_flags/url_helper.js
world-flags-0.4.8.3 vendor/assets/javascripts/world_flags/url_helper.js
world-flags-0.4.8.2 vendor/assets/javascripts/world_flags/url_helper.js
world-flags-0.4.7 vendor/assets/javascripts/world_flags/url_helper.js
world-flags-0.4.5 vendor/assets/javascripts/world_flags/url_helper.js
world-flags-0.4.4 vendor/assets/javascripts/world_flags/url_helper.js
world-flags-0.4.3 vendor/assets/javascripts/world_flags/url_helper.js
world-flags-0.4.2 vendor/assets/javascripts/world_flags/url_helper.js