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.Votes.initialize();
|
||||||
App.Tags.initialize();
|
App.Tags.initialize();
|
||||||
App.Stats.initialize();
|
App.Stats.initialize();
|
||||||
App.LocaleSwitcher.initialize();
|
App.LocationChanger.initialize();
|
||||||
App.DebatesOrderSelector.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'
|
home_page? ? '' : 'results'
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
<div class="locale">
|
<div class="locale">
|
||||||
<span class="inline-block"><%= t("layouts.header.locale") %></span>
|
<span class="inline-block"><%= t("layouts.header.locale") %></span>
|
||||||
<form class="locale-form">
|
<form class="locale-form">
|
||||||
<select class="js-locale-switcher locale-switcher" name="locale-switcher">
|
<select class="js-location-changer locale-switcher" name="locale-switcher">
|
||||||
<%= available_locale_options_for_select %>
|
<% 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>
|
</select>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ feature 'Localization' do
|
|||||||
scenario 'Available locales appear in the locale switcher' do
|
scenario 'Available locales appear in the locale switcher' do
|
||||||
visit '/'
|
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 'Español'
|
||||||
expect(page).to have_content 'English'
|
expect(page).to have_content 'English'
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user