Merge pull request #524 from dgilperez/ie_alert_cookie

Cookie for IE alert
This commit is contained in:
Enrique García
2015-09-22 16:38:31 +02:00
5 changed files with 40 additions and 3 deletions

View File

@@ -34,6 +34,7 @@ var initialize_modules = function() {
App.LocationChanger.initialize(); App.LocationChanger.initialize();
App.CheckAllNone.initialize(); App.CheckAllNone.initialize();
App.PreventDoubleSubmission.initialize(); App.PreventDoubleSubmission.initialize();
App.IeAlert.initialize();
}; };
$(function(){ $(function(){

View File

@@ -1,4 +1,4 @@
App.Dropdown = App.Dropdown =
initialize: -> initialize: ->
$(document).foundation(); $(document).foundation()

View File

@@ -0,0 +1,9 @@
App.IeAlert =
set_cookie_and_hide: (event) ->
event.preventDefault()
$.cookie('ie_alert_closed', 'true', { path: '/', expires: 365 });
$('.ie-alert-box').remove()
initialize: ->
$('.ie-alert-box-close-js').on 'click', (event) ->
App.IeAlert.set_cookie_and_hide(event)

View File

@@ -24,9 +24,9 @@
<%= render 'layouts/header' %> <%= render 'layouts/header' %>
<!--[if lt IE 9]> <!--[if lt IE 9]>
<% if browser.ie? %> <% if browser.ie? && cookies['ie_alert_closed'] != 'true' %>
<div data-alert class="alert-box info ie-alert-box"> <div data-alert class="alert-box info ie-alert-box">
<a href="#" class="close">&times;</a> <a href="#" class="close ie-alert-box-close-js">&times;</a>
<h2><%= t("layouts.application.ie_title") %></h2> <h2><%= t("layouts.application.ie_title") %></h2>
<p> <p>
<%= t("layouts.application.ie", <%= t("layouts.application.ie",

View File

@@ -19,4 +19,31 @@ feature "Home" do
end end
end end
feature 'IE alert' do
scenario 'IE visitors are presented with an alert until they close it', :js do
page.driver.headers = { "User-Agent" => "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)" }
visit root_path
expect(page).to have_xpath(ie_alert_box_xpath, visible: false)
expect(page.driver.cookies['ie_alert_closed']).to be_nil
# faking close button, since a normal find and click
# will not work as the element is inside a HTML conditional comment
page.driver.set_cookie 'ie_alert_closed', 'true'
visit root_path
expect(page).not_to have_xpath(ie_alert_box_xpath, visible: false)
expect(page.driver.cookies["ie_alert_closed"].value).to eq('true')
end
scenario 'non-IE visitors are not bothered with IE alerts', :js do
visit root_path
expect(page).not_to have_xpath(ie_alert_box_xpath, visible: false)
expect(page.driver.cookies['ie_alert_closed']).to be_nil
end
def ie_alert_box_xpath
"/html/body/div[@class='wrapper']/comment()[contains(.,'ie-alert-box')]"
end
end
end end