Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Merge requests
!5647
Add Javascript Intersection Observer to media oembed
Code
Review changes
Check out branch
Open in Workspace
Download
Patches
Plain diff
Expand sidebar
Open
Add Javascript Intersection Observer to media oembed
issue/drupal-3405593:3405593-add-intersection-observer-v2
into
10.2.x
Overview
0
Commits
1
Pipelines
1
Changes
3
Open
Add Javascript Intersection Observer to media oembed
Andrew Sipple
requested to merge
issue/drupal-3405593:3405593-add-intersection-observer-v2
into
10.2.x
Dec 1, 2023
Overview
0
Commits
1
Pipelines
1
Changes
3
Closes
#3405593
0
0
Merge request reports
Compare
10.2.x
10.2.x (HEAD)
and
latest version
latest version
9cb822d0
1 commit,
Dec 1, 2023
3 files
+
57
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
core/modules/media/js/media_embed_intersection_observer.js
0 → 100644
+
36
−
0
View file @ f8fee170
Edit in single-file editor
Open in Web IDE
/**
* @file
* Attaches the mediaEmbedIntersectionObserver behavior.
*/
((
Drupal
)
=>
{
Drupal
.
behaviors
.
mediaEmbedIntersectionObserver
=
{
attach
(
context
)
{
// Select all elements with the class '.media-oembed-content' and the 'data-src' attribute.
const
elements
=
context
.
querySelectorAll
(
'
.media-oembed-content[data-src]
'
,
);
// Check if matching elements exist.
if
(
elements
.
length
>
0
)
{
// Iterate over each matching element.
elements
.
forEach
((
frame
)
=>
{
// Create an IntersectionObserver to handle lazy loading.
const
observer
=
new
IntersectionObserver
((
entries
,
observer
)
=>
{
// Iterate over each intersection entry.
entries
.
forEach
((
entry
)
=>
{
// If the element is in view, set the 'src' attribute and stop observing.
if
(
entry
.
isIntersecting
)
{
frame
.
setAttribute
(
'
src
'
,
frame
.
dataset
.
src
);
observer
.
unobserve
(
entry
.
target
);
}
});
});
// Start observing the current element.
observer
.
observe
(
frame
);
});
}
},
};
})(
Drupal
);
Loading