made the locale switcher use less js, more ruby & html
This commit is contained in:
@@ -31,7 +31,7 @@ var initialize_modules = function() {
|
||||
App.Votes.initialize();
|
||||
App.Tags.initialize();
|
||||
App.Stats.initialize();
|
||||
App.LocaleSwitcher.initialize();
|
||||
App.LocationChanger.initialize();
|
||||
App.DebatesOrderSelector.initialize();
|
||||
};
|
||||
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
App.LocaleSwitcher =
|
||||
|
||||
href_with_params: (query_params) ->
|
||||
loc = window.location
|
||||
|
||||
loc.protocol + "//" + loc.hostname +
|
||||
(if loc.port then ':' + loc.port else '') +
|
||||
loc.pathname +
|
||||
loc.hash +
|
||||
'?' + $.param(query_params)
|
||||
|
||||
initialize: ->
|
||||
$('.js-locale-switcher').on 'change', ->
|
||||
query_params = window.getQueryParameters()
|
||||
query_params['locale'] = $(this).val()
|
||||
window.location.assign(App.LocaleSwitcher.href_with_params(query_params))
|
||||
|
||||
|
||||
|
||||
8
app/assets/javascripts/location_changer.js.coffee
Normal file
8
app/assets/javascripts/location_changer.js.coffee
Normal file
@@ -0,0 +1,8 @@
|
||||
App.LocationChanger =
|
||||
|
||||
initialize: ->
|
||||
$('.js-location-changer').on 'change', ->
|
||||
window.location.assign($(this).val())
|
||||
|
||||
|
||||
|
||||
@@ -14,13 +14,4 @@ module ApplicationHelper
|
||||
home_page? ? '' : 'results'
|
||||
end
|
||||
|
||||
def available_locale_options_for_select
|
||||
options_for_select(available_locales_array, I18n.locale)
|
||||
end
|
||||
|
||||
private
|
||||
def available_locales_array
|
||||
I18n.available_locales.map { |loc| [I18n.t('locale', locale: loc), loc] }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
<div class="locale">
|
||||
<span class="inline-block"><%= t("layouts.header.locale") %></span>
|
||||
<form class="locale-form">
|
||||
<select class="js-locale-switcher locale-switcher" name="locale-switcher">
|
||||
<%= available_locale_options_for_select %>
|
||||
<select class="js-location-changer locale-switcher" name="locale-switcher">
|
||||
<% I18n.available_locales.map do |loc| %>
|
||||
<option <%= 'selected' if loc == I18n.locale %>
|
||||
value='<%= url_for(request.query_parameters.merge(locale: loc))%>'>
|
||||
<%= I18n.t('locale', locale: loc) %>
|
||||
</option>
|
||||
<% end %>
|
||||
</select>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -12,7 +12,7 @@ feature 'Localization' do
|
||||
scenario 'Available locales appear in the locale switcher' do
|
||||
visit '/'
|
||||
|
||||
within('.js-locale-switcher') do
|
||||
within('.locale-form .js-location-changer') do
|
||||
expect(page).to have_content 'Español'
|
||||
expect(page).to have_content 'English'
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user