diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-14 17:06:59 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-14 18:30:40 +0200 |
| commit | 8847db139bef9dd8f9465c31438f16af13593267 (patch) | |
| tree | d192bd396ea74f89cd84aac22d79ef126aec6976 /public/javascripts/related_assets.js | |
| parent | ffb3c9987c2f820b99e8ad0ad56db8ae0324671c (diff) | |
Add inline image insertion for page bodies, plus a headline-conflict badge
Custom TinyMCE toolbar button opens a picker scoped to a page's own
attached images. Selecting one and a placement (full width, left,
right) inserts <a class="glightbox" data-gallery="page-N">
wrapping an <img>, sharing the existing headline-image lightbox
gallery. No native TinyMCE image dialog or resize handles --
placement is fixed to the three options via CSS classes only.
extended_valid_elements defines a and img explicitly and
symmetrically; valid_classes allows the placement classes and
glightbox specifically. content_style renders placement inside the
editing iframe, since ccc.css doesn't load there.
A pre-save pass removes any a.glightbox left without an img,
covering in-editor deletion regardless of how it happened.
Alt text comes from the asset's name, escaped.
A badge marks whichever attached image sits at position 0, since
_headline_image.html.erb always renders that position as the
page's automatic headline. Shown in the sidebar Images list and in
the picker grid.
Diffstat (limited to 'public/javascripts/related_assets.js')
| -rw-r--r-- | public/javascripts/related_assets.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/public/javascripts/related_assets.js b/public/javascripts/related_assets.js index 2955cbf..803332f 100644 --- a/public/javascripts/related_assets.js +++ b/public/javascripts/related_assets.js | |||
| @@ -5,6 +5,8 @@ related_assets = { | |||
| 5 | var createUrl = container.data("create-url"); | 5 | var createUrl = container.data("create-url"); |
| 6 | var list = $("#related_asset_list"); | 6 | var list = $("#related_asset_list"); |
| 7 | 7 | ||
| 8 | related_assets.update_headline_badge(list); | ||
| 9 | |||
| 8 | initSearchPicker({ | 10 | initSearchPicker({ |
| 9 | inputSelector: "#related_asset_search_term", | 11 | inputSelector: "#related_asset_search_term", |
| 10 | resultsSelector: "#related_asset_search_results", | 12 | resultsSelector: "#related_asset_search_results", |
| @@ -45,6 +47,7 @@ related_assets = { | |||
| 45 | url: ui.item.data("url"), | 47 | url: ui.item.data("url"), |
| 46 | data: "position=" + newPosition | 48 | data: "position=" + newPosition |
| 47 | }); | 49 | }); |
| 50 | related_assets.update_headline_badge(list); | ||
| 48 | } | 51 | } |
| 49 | }); | 52 | }); |
| 50 | 53 | ||
| @@ -55,11 +58,23 @@ related_assets = { | |||
| 55 | url: item.data("url"), | 58 | url: item.data("url"), |
| 56 | success: function() { | 59 | success: function() { |
| 57 | item.remove(); | 60 | item.remove(); |
| 61 | related_assets.update_headline_badge(list); | ||
| 58 | } | 62 | } |
| 59 | }); | 63 | }); |
| 60 | }); | 64 | }); |
| 61 | }, | 65 | }, |
| 62 | 66 | ||
| 67 | update_headline_badge: function(list) { | ||
| 68 | list.find(".related_asset_headline_badge").remove(); | ||
| 69 | var first = list.children("li").first(); | ||
| 70 | if (first.length) { | ||
| 71 | $("<span>", { | ||
| 72 | "class": "related_asset_headline_badge", | ||
| 73 | "title": "Shown automatically as this page's headline image" | ||
| 74 | }).text("Headline").insertBefore(first.find(".related_asset_remove")); | ||
| 75 | } | ||
| 76 | }, | ||
| 77 | |||
| 63 | attach: function(assetId, createUrl, list) { | 78 | attach: function(assetId, createUrl, list) { |
| 64 | $.ajax({ | 79 | $.ajax({ |
| 65 | type: "POST", | 80 | type: "POST", |
| @@ -69,9 +84,13 @@ related_assets = { | |||
| 69 | success: function(related) { | 84 | success: function(related) { |
| 70 | var item = $($("#related_asset_template").html().trim()); | 85 | var item = $($("#related_asset_template").html().trim()); |
| 71 | item.attr("data-url", related.url); | 86 | item.attr("data-url", related.url); |
| 87 | item.attr("data-large-url", related.large_url); | ||
| 88 | item.attr("data-original-url", related.original_url); | ||
| 89 | item.attr("data-name", related.name); | ||
| 72 | item.find("img").attr("src", related.thumb_url); | 90 | item.find("img").attr("src", related.thumb_url); |
| 73 | list.append(item); | 91 | list.append(item); |
| 74 | list.sortable("refresh"); | 92 | list.sortable("refresh"); |
| 93 | related_assets.update_headline_badge(list); | ||
| 75 | $("#related_asset_search_term").val(""); | 94 | $("#related_asset_search_term").val(""); |
| 76 | $("#related_asset_search_results").slideUp().empty(); | 95 | $("#related_asset_search_results").slideUp().empty(); |
| 77 | } | 96 | } |
