Skip to content

Commit

Permalink
D8CORE-7194 Embed codes with captions respect 100% widths on iframes
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Nov 7, 2024
1 parent a3b380e commit 94fddf9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions themes/stanford_basic/dist/js/behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ window.Drupal.behaviors.stanford_basic = {
// Attach Drupal Behavior.
attach: function attach(context, settings) {
(function ($, once) {
// If some embed code contains a caption, make sure the figure respects
// the iframe width of 100%.
$('figure', context).each(function () {
var $iframeWithin = $('iframe', this);
var iframeWidth = $iframeWithin.attr('width');
if ($iframeWithin.length && (!iframeWidth || iframeWidth === '100%')) {
$(this).css('width', '100%');
}
});

// Validate there is a skip link anchor for the main content. If not,
// default to #page-content.
var $title = $('h1', context);
Expand Down
11 changes: 11 additions & 0 deletions themes/stanford_basic/src/js/stanford_basic.behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ export default {
// Attach Drupal Behavior.
attach(context, settings) {
(function ($, once) {

// If some embed code contains a caption, make sure the figure respects
// the iframe width of 100%.
$('figure', context).each(function() {
const $iframeWithin = $('iframe', this);
const iframeWidth = $iframeWithin.attr('width');
if ($iframeWithin.length && (!iframeWidth || iframeWidth === '100%')) {
$(this).css('width', '100%');
}
})

// Validate there is a skip link anchor for the main content. If not,
// default to #page-content.
const $title = $('h1', context);
Expand Down

0 comments on commit 94fddf9

Please sign in to comment.