Skip to content

Commit

Permalink
Merge pull request #3515 from consul/proposals-support-mobile
Browse files Browse the repository at this point in the history
Proposals support on mobile
  • Loading branch information
decabeza committed May 22, 2019
2 parents ac1d819 + 148ea1e commit 7abeb59
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 23 deletions.
21 changes: 20 additions & 1 deletion app/assets/javascripts/foundation_extras.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,23 @@ App.FoundationExtras =

initialize: ->
$(document).foundation()
$(window).trigger "load.zf.sticky"
$(window).trigger "resize"

clearSticky = ->
$("[data-sticky]").foundation("destroy") if $("[data-sticky]").length

$(document).on("page:before-unload", clearSticky)

window.addEventListener("popstate", clearSticky, false)

mobile_ui_init = ->
$(window).trigger "load.zf.sticky"

desktop_ui_init = ->
$(window).trigger "init.zf.sticky"

$ ->
if $(window).width() < 620
do mobile_ui_init
else
do desktop_ui_init
16 changes: 15 additions & 1 deletion app/assets/stylesheets/layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,11 @@ header {
border-bottom: 1px solid $border;
margin-bottom: $line-height;

@include breakpoint(small down) {
position: relative;
z-index: 10;
}

.selected {
border-bottom: 1px solid #fff;
}
Expand Down Expand Up @@ -1077,10 +1082,13 @@ form {

.notice-container {
min-width: $line-height * 12;
position: absolute;
right: 24px;
top: 24px;

@include breakpoint(medium) {
position: absolute;
}

.notice {
height: $line-height * 4;

Expand Down Expand Up @@ -2666,6 +2674,12 @@ table {
}
}

.leaflet-bottom,
.leaflet-pane,
.leaflet-top {
z-index: 4 !important;
}

// 24. Homepage
// ------------

Expand Down
9 changes: 9 additions & 0 deletions app/assets/stylesheets/participation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,15 @@
}
}

.fixed-mobile-content {

@include breakpoint(medium down) {
background: #fff;
margin-bottom: rem-calc(-1) !important;
padding-top: $line-height / 2;
}
}

// 04. List participation
// ----------------------

Expand Down
57 changes: 36 additions & 21 deletions app/views/proposals/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -62,30 +62,45 @@
</div>
<% end %>

<div class="sidebar-divider"></div>
<h2><%= t("votes.supports") %></h2>
<div id="<%= dom_id(@proposal) %>_votes">
<% if @proposal.draft? %>
<div class="callout primary">
<p class=text-center><strong><%= t('.draft') %></strong></p>
</div>
<% elsif @proposal.successful? %>
<p>
<%= t("proposals.proposal.successful") %>
</p>
<% elsif @proposal.archived? %>
<div class="padding text-center">
<p>
<strong><%= t("proposals.proposal.supports", count: @proposal.total_votes) %></strong>
</p>
<p><%= t("proposals.proposal.archived") %></p>
<div id="proposal_sticky" data-sticky-container>
<div class="sticky fixed-mobile-content"
data-sticky
data-stick-to="bottom"
data-sticky-on="small"
data-top-anchor="0"
data-btm-anchor="sticky_stop"
data-check-every="0">
<div class="fixed-mobile-content">
<div class="sidebar-divider"></div>
<h2><%= t("votes.supports") %></h2>

<div id="<%= dom_id(@proposal) %>_votes">
<% if @proposal.draft? %>
<div class="callout primary">
<p class=text-center><strong><%= t('.draft') %></strong></p>
</div>
<% elsif @proposal.successful? %>
<p>
<%= t("proposals.proposal.successful") %>
</p>
<% elsif @proposal.archived? %>
<div class="padding text-center">
<p>
<strong><%= t("proposals.proposal.supports", count: @proposal.total_votes) %></strong>
</p>
<p><%= t("proposals.proposal.archived") %></p>
</div>
<% else %>
<%= render "votes",
{ proposal: @proposal, vote_url: vote_proposal_path(@proposal, value: "yes") } %>
<% end %>
</div>
</div>
<% else %>
<%= render "votes",
{ proposal: @proposal, vote_url: vote_proposal_path(@proposal, value: "yes") } %>
<% end %>
</div>
</div>

<div id="sticky_stop"></div>

<%= render "proposals/social_share", proposal: @proposal, share_title: t("proposals.show.share") %>
<% if current_user %>
Expand Down
21 changes: 21 additions & 0 deletions spec/features/proposals_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,27 @@
end
end

context "Show on mobile screens" do

before do
Capybara.page.driver.browser.manage.window.resize_to(640, 480)
end

after do
Capybara.page.driver.browser.manage.window.maximize
end

scenario "Show support button sticky at bottom", :js do
proposal = create(:proposal)
visit proposal_path(proposal)

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

scenario "Show YouTube video" do
Expand Down

0 comments on commit 7abeb59

Please sign in to comment.