Skip to content

Commit

Permalink
Add new handling fro handling slides visibility (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecslupu committed Apr 20, 2023
1 parent cb162e3 commit 7189257
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 15 deletions.
10 changes: 3 additions & 7 deletions app/cells/decidim/slider/homepage/main/show.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@

</div>
<div class="orbit-container">
<% slides.each_with_index do |content_block, index| %>
<% next unless content_block.manifest %>
<%= cell content_block.manifest.cell, content_block, context: { index: index } %>
<% end %>
<%= cells.map(&:call) %>
</div>
</div>
<nav class="orbit-bullets" aria-label="slider-navigation">
Expand All @@ -25,9 +22,8 @@
<span class="show-for-sr" data-slide-active-label><%= t("decidim.slider.homepage.main.current_slide") %></span>
</button>

<% (1...slides.size).to_a.each do |counter| %>
<button data-slide="<%= counter %>"><span class="show-for-sr"><%= t("decidim.slider.homepage.main.slide_details", count: 1+counter) %></span></button>
<% end %>
<%= cells.map(&:bullet).drop(1).join("\n") %>

<a class="orbit-next"><span class="show-for-sr"><%= t("decidim.slider.homepage.main.next_slide") %></span>
<%= icon "chevron-right", class: "icon--small", role: "img" %>
</a>
Expand Down
19 changes: 18 additions & 1 deletion app/cells/decidim/slider/homepage/main_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,25 @@ def show

private

def cells
return @cells if defined?(@cells)

@cells ||= []
index = 0
slides.each do |slide|
cl = cell(slide.manifest.cell, slide, context: { index: index })

next unless cl.renderable?

@cells.push(cl)
index += 1
end

@cells
end

def has_slides?
slides.any?
cells.map(&:renderable?).any?
end

def slides
Expand Down
1 change: 1 addition & 0 deletions app/cells/decidim/slider/tabs/generic/main/bullet.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<button data-slide="<%= index %>"><span class="show-for-sr"><%= t("decidim.slider.homepage.main.slide_details", count: 1+index) %></span></button>
24 changes: 24 additions & 0 deletions app/cells/decidim/slider/tabs/generic/main_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ module Slider
module Tabs
module Generic
class MainCell < Decidim::ViewModel
def bullet
return unless renderable?

render
end

def show
return unless renderable?

render
end

def index
context[:index]
end
Expand Down Expand Up @@ -51,6 +63,18 @@ def cache_hash
hash.push(model.cache_key_with_version)
hash.join(Decidim.cache_key_separator)
end

def asset
model.images_container.attached_uploader(uploader_name)
end

def renderable?
asset.attached?
end

def content_type
model.images_container.send(uploader_name).content_type
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/cells/decidim/slider/tabs/image/main/show.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="<% if index.zero? %>is-active<% end %> orbit-slide">
<div class="orbit-slide<% if index.zero? %> is-active<% end %>">
<div class="row ">
<div class="column orbit-figure">
<div class="row small-up-1 smallmedium-up-2">
Expand Down
6 changes: 5 additions & 1 deletion app/cells/decidim/slider/tabs/image/main_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ module Slider
module Tabs
module Image
class MainCell < ::Decidim::Slider::Tabs::Generic::MainCell
def uploader_name
:image
end

def image_url
model.images_container.attached_uploader(:image).path(variant: :big)
asset.path(variant: :big)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/cells/decidim/slider/tabs/video_text/main/show.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="row small-up-1 smallmedium-up-2">
<div class="column text-center">
<video aria-label="<%= accessibility_label %>" width="512" height="270" controls autoplay muted loop>
<source src="<%= video_url %>" type="<%= video_content_type %>">
<source src="<%= video_url %>" type="<%= content_type %>">
Your browser does not support the video tag.
</video>
</div>
Expand Down
8 changes: 4 additions & 4 deletions app/cells/decidim/slider/tabs/video_text/main_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ module Slider
module Tabs
module VideoText
class MainCell < ::Decidim::Slider::Tabs::Generic::MainCell
def video_url
model.images_container.attached_uploader(:video).path
def uploader_name
:video
end

def video_content_type
model.images_container.video.content_type
def video_url
asset.path
end
end
end
Expand Down

0 comments on commit 7189257

Please sign in to comment.