Skip to content

Commit

Permalink
Use picture tag for bg image
Browse files Browse the repository at this point in the history
  • Loading branch information
gertimon committed Apr 3, 2017
1 parent 3fb8e76 commit 4bbc5fe
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
18 changes: 18 additions & 0 deletions app/models/elastic_slider_panel_widget.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,22 @@ def self.valid_container_classes
[ElasticSliderWidget]
end

def transform_for_desktop(width)
if container.slider_height.to_i > 100
image.binary.transform(width: width, height: self.height, fit: :crop, crop: :center)
else
image.binary.transform(width: width)
end
end

def fallback_transform
if container.slider_height.to_i > 100
return { width: 1920, height: self.height, fit: :crop, crop: :center }
end
end

def height
h = container.slider_height.to_i
h > 100 ? h+200 : image.meta_data[:height] # 50vh, 100vh is dynamic, no height calculation possible
end
end
19 changes: 18 additions & 1 deletion app/views/elastic_slider_panel_widget/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
<div class="item <%= widget.additional_classes(params) %>">
<%= scrivito_image_tag widget, :image %>
<picture>
<source media='(max-width: 400px) and (orientation: portrait)'
sizes='100vw'
srcset='<%= widget.image.binary.transform(width: 400, height: widget.height, fit: :crop, crop: :center).url %>'>

<source media='(max-width: 768px)'
sizes='100vw'
srcset='<%= widget.image.binary.transform(width: 768, height: widget.height, fit: :crop, crop: :center).url %>'>

<source media='(min-width: 668px) and (max-width: 991px)'
sizes='100vw'
srcset='<%= widget.transform_for_desktop(991).url %>'>

<source media='(min-width: 991px) and (max-width: 1200px)'
sizes='100vw'
srcset='<%= widget.transform_for_desktop(1200).url %>'>
<%= scrivito_image_tag widget, :image, {class: 'img-responsive'}, transform: widget.fallback_transform %>
</picture>
<div class="carousel-caption">
<div class="content">
<%= scrivito_tag :div, widget, :panel_content %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/elastic_slider_widget/details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

<h3>Panels</h3>
<%= scrivito_tag :div, widget, :panels %>
<% end %>
<% end %>
2 changes: 1 addition & 1 deletion lib/scrivito_elastic_slider_widget/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ScrivitoElasticSliderWidget
VERSION = "0.92.0"
VERSION = "0.92.1"
end

0 comments on commit 4bbc5fe

Please sign in to comment.