summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-07-21 14:24:59 +0200
committererdgeist <erdgeist@erdgeist.org>2026-07-21 14:24:59 +0200
commitc14683fe37fabe06082f43e8bf67debc4cca7297 (patch)
tree10054588f053cf071a55df067180091d3388e05a /app
parent1912b8fbf0e1e1ea84a89c033e20e34235d19cce (diff)
Render asset credit inside the gallery lightbox correctly
GLightbox's own selector-based description feature never actually resolved a selector in three different attempts -- literal text, then a resolved-but-empty div, then apparently not firing at all against the installed (unversioned) build. Replaced with a small afterSlideLoad handler that reads a plain data-credit-selector attribute and copies the real element's HTML into the slide's description area directly, depending only on GLightbox handing back a real DOM node per slide -- a much smaller contract than trusting its own caption-resolution feature. Renamed the credit div's class from glightbox-desc, since that name is reserved by the library's own bundled CSS (display: none !important) and can't be reliably overridden from here. Also: distinguishes the credit line and the "N Bilder" caption from ordinary body text (italic, muted, matching .author_and_date's existing convention), and makes the lightbox's caption card follow the site's light/dark toggle via Canvas/CanvasText, since the library's bundled theme never adapts to it on its own.
Diffstat (limited to 'app')
-rw-r--r--app/controllers/related_assets_controller.rb1
-rw-r--r--app/helpers/content_helper.rb6
-rw-r--r--app/models/asset.rb4
-rw-r--r--app/views/content/_asset_credits.html.erb6
-rw-r--r--app/views/content/_headline_image.html.erb15
-rw-r--r--app/views/nodes/edit.html.erb1
6 files changed, 22 insertions, 11 deletions
diff --git a/app/controllers/related_assets_controller.rb b/app/controllers/related_assets_controller.rb
index da82cde..2fefaf7 100644
--- a/app/controllers/related_assets_controller.rb
+++ b/app/controllers/related_assets_controller.rb
@@ -26,6 +26,7 @@ class RelatedAssetsController < ApplicationController
26 id: related.id, 26 id: related.id,
27 asset_id: asset.id, 27 asset_id: asset.id,
28 name: asset.name, 28 name: asset.name,
29 has_credit: asset.has_credit?,
29 thumb_url: asset.upload.url(:thumb), 30 thumb_url: asset.upload.url(:thumb),
30 large_url: asset.upload.url(:large), 31 large_url: asset.upload.url(:large),
31 original_url: asset.upload.url, 32 original_url: asset.upload.url,
diff --git a/app/helpers/content_helper.rb b/app/helpers/content_helper.rb
index 5b67259..b3c6bad 100644
--- a/app/helpers/content_helper.rb
+++ b/app/helpers/content_helper.rb
@@ -153,7 +153,7 @@ module ContentHelper
153 153
154 def asset_credit(asset) 154 def asset_credit(asset)
155 return nil unless asset 155 return nil unless asset
156 return nil if asset.creator.blank? && asset.source_url.blank? && asset.license_key.blank? 156 return nil unless asset.has_credit?
157 157
158 license = AssetLicense.find(asset.license_key) 158 license = AssetLicense.find(asset.license_key)
159 159
@@ -173,4 +173,8 @@ module ContentHelper
173 full = license_text ? safe_join([attribution, license_text], ", ") : attribution 173 full = license_text ? safe_join([attribution, license_text], ", ") : attribution
174 safe_join([full, "."]) 174 safe_join([full, "."])
175 end 175 end
176
177 def glightbox_data(image, title)
178 "title: #{title.to_s.tr(';', ',')};"
179 end
176end 180end
diff --git a/app/models/asset.rb b/app/models/asset.rb
index 8bea1b3..4a295d8 100644
--- a/app/models/asset.rb
+++ b/app/models/asset.rb
@@ -15,4 +15,8 @@ class Asset < ApplicationRecord
15 def image? 15 def image?
16 IMAGE_CONTENT_TYPES.include?(upload_content_type) 16 IMAGE_CONTENT_TYPES.include?(upload_content_type)
17 end 17 end
18
19 def has_credit?
20 creator.present? || source_url.present? || license_key.present?
21 end
18end 22end
diff --git a/app/views/content/_asset_credits.html.erb b/app/views/content/_asset_credits.html.erb
index 85739d0..5959abd 100644
--- a/app/views/content/_asset_credits.html.erb
+++ b/app/views/content/_asset_credits.html.erb
@@ -1,11 +1,9 @@
1<% if @page.assets.images.any? %> 1<% if @page.assets.images.any? %>
2 <div id="asset_credits"> 2 <div id="asset_credits">
3 <% @page.assets.images.each do |image| %> 3 <% @page.assets.images.each do |image| %>
4 <% credit = asset_credit(image) %>
5 <% next unless credit %>
6 <div id="credit_for_asset_<%= image.id %>" 4 <div id="credit_for_asset_<%= image.id %>"
7 class="glightbox-desc<%= " headline_credit" if image == @headline_asset %>"> 5 class="asset_credit_block<%= " headline_credit" if image == @headline_asset %>">
8 <%= credit %> 6 <%= asset_credit(image) %>
9 </div> 7 </div>
10 <% end %> 8 <% end %>
11 </div> 9 </div>
diff --git a/app/views/content/_headline_image.html.erb b/app/views/content/_headline_image.html.erb
index c764d22..e7b821b 100644
--- a/app/views/content/_headline_image.html.erb
+++ b/app/views/content/_headline_image.html.erb
@@ -5,8 +5,9 @@
5 image_tag(@headline_asset.upload.url(:headline)), 5 image_tag(@headline_asset.upload.url(:headline)),
6 @headline_asset.upload.url, 6 @headline_asset.upload.url,
7 :class => "glightbox", 7 :class => "glightbox",
8 :data => { :gallery => "page-#{@page.node.id}", :title => @headline_asset.name, 8 :data => { :gallery => "page-#{@page.node.id}",
9 :description => "#credit_for_asset_#{@headline_asset.id}" } 9 :glightbox => glightbox_data(@headline_asset, @headline_asset.name),
10 :"credit-selector" => (@headline_asset.has_credit? ? "#credit_for_asset_#{@headline_asset.id}" : nil) }
10 ) %> 11 ) %>
11 <% if gallery_images.size > 1 %> 12 <% if gallery_images.size > 1 %>
12 <div class="right"><%= "#{gallery_images.size} #{t(:images)}" %></div> 13 <div class="right"><%= "#{gallery_images.size} #{t(:images)}" %></div>
@@ -15,14 +16,16 @@
15 <%= link_to "#{gallery_images.size} #{t(:images)}, #{t(:open_gallery)}", 16 <%= link_to "#{gallery_images.size} #{t(:images)}, #{t(:open_gallery)}",
16 gallery_images.first.upload.url, 17 gallery_images.first.upload.url,
17 :class => "glightbox right", 18 :class => "glightbox right",
18 :data => { :gallery => "page-#{@page.node.id}", :title => gallery_images.first.name, 19 :data => { :gallery => "page-#{@page.node.id}",
19 :description => "#credit_for_asset_#{gallery_images.first.id}" } %> 20 :glightbox => glightbox_data(gallery_images.first, gallery_images.first.name),
21 :"credit-selector" => (gallery_images.first.has_credit? ? "#credit_for_asset_#{gallery_images.first.id}" : nil) } %>
20<% end %> 22<% end %>
21 23
22<% gallery_images.each do |image| %> 24<% gallery_images.each do |image| %>
23 <% next if image == @headline_asset %> 25 <% next if image == @headline_asset %>
24 <% next if !@headline_asset && image == gallery_images.first %> 26 <% next if !@headline_asset && image == gallery_images.first %>
25 <%= link_to "", image.upload.url, :class => "glightbox", :style => "display: none", 27 <%= link_to "", image.upload.url, :class => "glightbox", :style => "display: none",
26 :data => { :gallery => "page-#{@page.node.id}", :title => image.name, 28 :data => { :gallery => "page-#{@page.node.id}",
27 :description => "#credit_for_asset_#{image.id}" } %> 29 :glightbox => glightbox_data(image, image.name),
30 :"credit-selector" => (image.has_credit? ? "#credit_for_asset_#{image.id}" : nil) } %>
28<% end %> 31<% end %>
diff --git a/app/views/nodes/edit.html.erb b/app/views/nodes/edit.html.erb
index da682f0..07b42d4 100644
--- a/app/views/nodes/edit.html.erb
+++ b/app/views/nodes/edit.html.erb
@@ -86,6 +86,7 @@
86 data-large-url="<%= related.asset.upload.url(:large) %>" 86 data-large-url="<%= related.asset.upload.url(:large) %>"
87 data-original-url="<%= related.asset.upload.url %>" 87 data-original-url="<%= related.asset.upload.url %>"
88 data-name="<%= related.asset.name %>" 88 data-name="<%= related.asset.name %>"
89 data-has-credit="<%= related.asset.has_credit? %>"
89 data-headline="<%= related.headline? %>" 90 data-headline="<%= related.headline? %>"
90 class="<%= "is_headline" if related.headline? %>"> 91 class="<%= "is_headline" if related.headline? %>">
91 <span class="related_asset_handle"><%= icon("grip-vertical", library: "tabler", "aria-hidden": true) %></span> 92 <span class="related_asset_handle"><%= icon("grip-vertical", library: "tabler", "aria-hidden": true) %></span>