diff --git a/WcaOnRails/app/assets/javascripts/application.js b/WcaOnRails/app/assets/javascripts/application.js index 5d3edf20356..39dd6147f08 100644 --- a/WcaOnRails/app/assets/javascripts/application.js +++ b/WcaOnRails/app/assets/javascripts/application.js @@ -379,3 +379,26 @@ $(function() { $(this).text(formatted); }); }); + + +// Handler for locale changes. +$(function() { + $('#locale-selector').on('click', 'a', function(e) { + e.preventDefault(); + e.stopPropagation(); + + // More or less copied from + // https://github.com/rails/jquery-ujs/blob/9e805c90c8cfc57b39967052e1e9013ccb318cf8/src/rails.js#L215. + var href = this.href; + var method = "patch"; + var csrfToken = $('meta[name=csrf-token]').attr('content'); + var csrfParam = $('meta[name=csrf-param]').attr('content'); + var form = $('
'); + var metadataInput = ''; + metadataInput += ''; + metadataInput += ''; + + form.hide().append(metadataInput).appendTo('body'); + form.submit(); + }); +}); diff --git a/WcaOnRails/app/assets/stylesheets/navbar-static-top.scss b/WcaOnRails/app/assets/stylesheets/navbar-static-top.scss index 7eec1844e47..6f76bbe0d0c 100644 --- a/WcaOnRails/app/assets/stylesheets/navbar-static-top.scss +++ b/WcaOnRails/app/assets/stylesheets/navbar-static-top.scss @@ -10,7 +10,7 @@ margin-right: 10px; } - .dropdown-menu.countries { + #locale-selector { min-width: 0; li { text-align: left; diff --git a/WcaOnRails/app/controllers/application_controller.rb b/WcaOnRails/app/controllers/application_controller.rb index 97f84860259..be7d1d4d938 100644 --- a/WcaOnRails/app/controllers/application_controller.rb +++ b/WcaOnRails/app/controllers/application_controller.rb @@ -43,7 +43,7 @@ def update_locale else flash[:danger] = I18n.t('users.update_locale.unavailable') end - redirect_to request.referer || root_path + redirect_to params[:current_url] || root_path end # https://github.com/doorkeeper-gem/doorkeeper/wiki/Customizing-the-response-body-when-unauthorized diff --git a/WcaOnRails/app/views/layouts/_navigation.html.erb b/WcaOnRails/app/views/layouts/_navigation.html.erb index 561d8922da5..d78737cf47d 100644 --- a/WcaOnRails/app/views/layouts/_navigation.html.erb +++ b/WcaOnRails/app/views/layouts/_navigation.html.erb @@ -90,10 +90,10 @@ <%= flag_icon active_locale_info[:flag_id] %> -