Skip to content

Commit

Permalink
feat(embed): add optional alt tag to placeholder
Browse files Browse the repository at this point in the history
This is desirable for web use.

When no alt value is provided, the alt tag will not be shown (same as current behaviour).

Co-authored-by: Marco 'Lubber' Wienkoop <c64@lubber.de>
  • Loading branch information
hugopeek and lubber-de authored Mar 2, 2024
1 parent 18b5554 commit a5363fb
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/definitions/modules/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,12 @@

createPlaceholder: function (placeholder) {
var
icon = module.get.icon()
icon = module.get.icon(),
alt = module.get.alt()
;
placeholder = placeholder || module.get.placeholder();
$module.html(templates.placeholder(placeholder, icon));
module.debug('Creating placeholder for embed', placeholder, icon);
$module.html(templates.placeholder(placeholder, icon, alt));
module.debug('Creating placeholder for embed', placeholder, icon, alt);
},

createEmbed: function (url) {
Expand Down Expand Up @@ -203,6 +204,9 @@
placeholder: function () {
return settings.placeholder || $module.data(metadata.placeholder);
},
alt: function () {
return settings.alt || $module.data(metadata.alt);
},
icon: function () {
return settings.icon || ($module.data(metadata.icon) !== undefined
? $module.data(metadata.icon)
Expand Down Expand Up @@ -288,6 +292,7 @@
.removeData(metadata.id)
.removeData(metadata.icon)
.removeData(metadata.placeholder)
.removeData(metadata.alt)
.removeData(metadata.source)
.removeData(metadata.url)
;
Expand Down Expand Up @@ -557,6 +562,8 @@
source: false,
url: false,
id: false,
placeholder: false,
alt: false,

// standard video settings
autoplay: 'auto',
Expand All @@ -579,6 +586,7 @@
id: 'id',
icon: 'icon',
placeholder: 'placeholder',
alt: 'alt',
source: 'source',
url: 'url',
},
Expand Down Expand Up @@ -654,7 +662,7 @@
+ ' width="100%" height="100%"'
+ ' msallowFullScreen allowFullScreen></iframe>';
},
placeholder: function (image, icon) {
placeholder: function (image, icon, alt) {
var
html = '',
deQuote = $.fn.embed.settings.templates.deQuote
Expand All @@ -663,7 +671,7 @@
html += '<i class="' + deQuote(icon) + ' icon"></i>';
}
if (image) {
html += '<img class="placeholder" src="' + deQuote(image) + '">';
html += '<img class="placeholder" src="' + deQuote(image) + (alt ? '" alt="' + deQuote(alt) : '') + '">';
}

return html;
Expand Down

0 comments on commit a5363fb

Please sign in to comment.