Simplify code related to Foundation's sticky
In the past we had huge problems trying to make it work with Turbolinks.
However, after updating foundation-rails in commit 58071fd6, these hacks
aren't necessary anymore.
We're adding a test for the scenario of visiting a page using
Turbolinks, which was missing, so we're sure we aren't breaking
anything.
Note the sticky will still not work after using the browser back button.
We haven't been able to make it work with turbolinks-classic; we'll fix
this issue when upgrading turbolinks.
This commit is contained in:
committed by
Senén Rodero Rodríguez
parent
fde6fb4d97
commit
983bf49b38
@@ -1,29 +1,8 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.FoundationExtras = {
|
||||
clearSticky: function() {
|
||||
if ($("[data-sticky]").length) {
|
||||
$("[data-sticky]").foundation("destroy");
|
||||
}
|
||||
},
|
||||
mobile_ui_init: function() {
|
||||
$(window).trigger("load.zf.sticky");
|
||||
},
|
||||
desktop_ui_init: function() {
|
||||
$(window).trigger("init.zf.sticky");
|
||||
},
|
||||
initialize: function() {
|
||||
$(document).foundation();
|
||||
$(window).trigger("resize");
|
||||
$(document).on("page:before-unload", this.clearSticky);
|
||||
window.addEventListener("popstate", this.clearSticky, false);
|
||||
$(function() {
|
||||
if ($(window).width() < 620) {
|
||||
App.FoundationExtras.mobile_ui_init();
|
||||
} else {
|
||||
App.FoundationExtras.desktop_ui_init();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
|
||||
@@ -200,7 +200,7 @@ describe "Proposals" do
|
||||
end
|
||||
end
|
||||
|
||||
context "Show on mobile screens" do
|
||||
describe "Show sticky support button on mobile screens", :js do
|
||||
let!(:window_size) { Capybara.current_window.size }
|
||||
|
||||
before do
|
||||
@@ -211,7 +211,7 @@ describe "Proposals" do
|
||||
Capybara.current_window.resize_to(*window_size)
|
||||
end
|
||||
|
||||
scenario "Show support button sticky at bottom", :js do
|
||||
scenario "On a first visit" do
|
||||
proposal = create(:proposal)
|
||||
visit proposal_path(proposal)
|
||||
|
||||
@@ -220,6 +220,19 @@ describe "Proposals" do
|
||||
expect(page).not_to have_css(".is-anchored")
|
||||
end
|
||||
end
|
||||
|
||||
scenario "After visiting another page" do
|
||||
proposal = create(:proposal)
|
||||
|
||||
visit proposal_path(proposal)
|
||||
click_link "Go back"
|
||||
click_link proposal.title
|
||||
|
||||
within("#proposal_sticky") do
|
||||
expect(page).to have_css(".is-stuck")
|
||||
expect(page).not_to have_css(".is-anchored")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "Embedded video" do
|
||||
|
||||
Reference in New Issue
Block a user