Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tidy-html5 to validate the home page #15594

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions public/javascript/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,15 +461,25 @@ $(function(){
});

// http://baymard.com/labs/country-selector
$('.js-select-to-autocomplete').selectToAutocomplete().on('change', function(){
var v = $(this).val();
if (v) {
// Assumes the <option>'s `value` attribute is a URL slug for the country
window.location.href = '/' + v + '/';
}
}).on('focus', function(){
$(this).next().trigger("focus");
});
var $placeholder = $('#js-placeholder');
$('.js-select-to-autocomplete')
.attr({
placeholder: $placeholder.text(),
autocorrect: 'off',
autocomplete: 'off'
})
.selectToAutocomplete()
.on('change', function(){
var v = $(this).val();
if (v) {
// Assumes the <option>'s `value` attribute is a URL slug for the country
window.location.href = '/' + v + '/';
}
})
.on('focus', function(){
$(this).next().trigger("focus");
});
$placeholder.attr('class', 'hidden')

// Fix the incorrect default autocomplete width, which meant that
// autocomplete menu was longer than the search input it's linked to.
Expand Down
8 changes: 8 additions & 0 deletions t/web/basic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,12 @@
last_response.status.must_equal 404
end
end

describe 'HTML validation' do
before { get '/' }

it 'has no errors in the home page' do
last_response_must_be_valid
end
end
end
2 changes: 1 addition & 1 deletion views/country_selector.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<select class="field js-select-to-autocomplete" placeholder="Search by country name" name="Country" id="country-selector" autofocus="autofocus" autocorrect="off" autocomplete="off">
<select class="field js-select-to-autocomplete" name="Country" id="country-selector" autofocus="autofocus">
<option value="" selected="selected">Select Country</option>
<% @page.all_countries.each do |country| %>
<option value="<%= country.slug %>" data-alternative-spellings="<%= country.names %>" title="<%= commify(country.total_people) %> <% if country.total_people == 1 %>person<% else %>people<% end %>"><%= country.name %></option>
Expand Down
7 changes: 6 additions & 1 deletion views/homepage.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<div class="hero hero--jazzy text-center homepage-hero">
<div class="container">
<h1><%= commify(@page.total_people) %> politicians from <a href="/countries.html"><%= @page.countries_with_data.count %> countries</a> (so far)</h1>
<p><label for="country-selector">Find representatives from your country:</label></p>
<p>
<label for="country-selector">
Find representatives from your country:
<span id="js-placeholder">Search by country name</span>
</label>
</p>
<%= erb :country_selector %>
</div>
<div class="homepage-map"></div>
Expand Down