Skip to content

Commit

Permalink
Fix aspect ratio / Other fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JoonasAapro committed Apr 18, 2024
1 parent 52aaaf2 commit 34706bd
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 19 deletions.
20 changes: 14 additions & 6 deletions app/controllers/decidim/iframe/iframe_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,32 @@ def iframe
def element
case content_height
when "16:9"
"<iframe id=\"iFrame\" class=\"aspect-ratio-16-9\" src=\"#{attributes.src}\" width=\"#{content_width}\"
frameborder=\"#{attributes.frameborder}\"></iframe>"
"<iframe id=\"iFrame\" class=\"aspect-ratio-16\" src=\"#{attributes.src}\" width=\"#{content_width}\"
frameborder=\"#{frameborder?}\"></iframe>"
when "4:3"
"<iframe id=\"iFrame\" class=\"aspect-ratio-4-3\" src=\"#{attributes.src}\" width=\"#{content_width}\"
frameborder=\"#{attributes.frameborder}\"></iframe>"
"<iframe id=\"iFrame\" class=\"aspect-ratio-4\" src=\"#{attributes.src}\" width=\"#{content_width}\"
frameborder=\"#{frameborder?}\"></iframe>"
when "auto"
"<iframe id=\"iFrame\" src=\"#{attributes.src}\" width=\"#{content_width}\"
frameborder=\"#{attributes.frameborder}\"></iframe>"
frameborder=\"#{frameborder?}\"></iframe>"
when "manual_pixel"
"<iframe id=\"iFrame\" src=\"#{attributes.src}\" width=\"#{content_width}\"
height=\"#{attributes.height_value}px\"frameborder=\"#{attributes.frameborder}\"></iframe>"
height=\"#{attributes.height_value}px\"frameborder=\"#{frameborder?}\"></iframe>"
end
end

def attributes
@attributes ||= current_component.settings
end

def frameborder?
if attributes.frameborder
"1"
else
"0"
end
end

def content_height
attributes.content_height
end
Expand Down
7 changes: 7 additions & 0 deletions app/packs/stylesheets/decidim/iframe/iframe.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.aspect-ratio-16 {
aspect-ratio: 16/9;
}

.aspect-ratio-4 {
aspect-ratio: 4 / 3;
}
2 changes: 1 addition & 1 deletion app/views/decidim/iframe/iframe/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<% end %>
</style>

<div class="iframe<%= " row" if viewport_width? %>">
<div class="iframe<%= " row column" if viewport_width? %>">
<%= iframe %>
</div>

Expand Down
2 changes: 2 additions & 0 deletions config/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
Decidim::Webpacker.register_entrypoints(
decidim_iframe: "#{base_path}/app/packs/entrypoints/decidim_iframe.js"
)

Decidim::Webpacker.register_stylesheet_import("stylesheets/decidim/iframe/iframe")
8 changes: 4 additions & 4 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ en:
before using the automatic height option. Read more about how to support
this library from the iframe-resizer documentation.
content_height_options:
'16:9': '16:9'
'4:3': '4:3'
'16:9': '16:9 aspect ratio'
'4:3': '4:3 aspect ratio'
auto: Automatic height
manual_pixel: Manual height in pixels
content_width: Content width
content_width_options:
full_width: Full width
manual_percentage: Manual width as a percentage
manual_pixel: Manual width in pixels
frameborder: Content frameborder
frameborder: Add border around the iframe
height_value: Height value
no_margins: No margins
no_margins: Remove margins around the iframe
resize_iframe: Resize Iframe
resize_iframe_options:
manual: Resize manually
Expand Down
8 changes: 4 additions & 4 deletions config/locales/fi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ fi:
tukeminen ennen automaattisen korkeuden säädön käyttöä. Katso iframe-resizer
dokumentaatio lukeaksesi lisää tämän kirjaston tukemisesta.
content_height_options:
"16:9": "16:9"
"4:3": "4:3"
"16:9": "16:9 kuvasuhde"
"4:3": "4:3 kuvasuhde"
auto: Automaattinen korkeus
manual_pixel: Korkeus pikseleissä
frameborder: Sisällön kehys
frameborder: Lisää kehys iframe -elementille
height_value: Korkeusarvo
no_margins: Ei reunoja
no_margins: Poista reunat iframe -elementiltä
resize_iframe: Iframe -elementin koko
resize_iframe_options:
responsive: Automaattinen koko
Expand Down
8 changes: 4 additions & 4 deletions config/locales/sv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ sv:
library before using the automatic height option. Read more about how to support this library from the
iframe-resizer documentation.
content_height_options:
"16:9": "16:9"
"4:3": "4:3"
"16:9": "16:9 aspect ratio"
"4:3": "4:3 aspect ratio"
auto: Automatic height
manual_pixel: Manual height in pixels
frameborder: Content frameborder
frameborder: Add border around the iframe
height_value: Height value
no_margins: No margins
no_margins: Remove margins around the iframe
resize_iframe: Resize Iframe
resize_iframe_options:
manual: Resize manually
Expand Down

0 comments on commit 34706bd

Please sign in to comment.