Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sg_youtube
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TYPO3
sg_youtube
Commits
555a715e
Commit
555a715e
authored
3 years ago
by
Michael Kessler
Browse files
Options
Downloads
Patches
Plain Diff
[TASK] Add disable lightbox functionality
parent
97f27e4b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Resources/Public/JavaScript/sgYoutubeLightbox.js
+62
-0
62 additions, 0 deletions
Resources/Public/JavaScript/sgYoutubeLightbox.js
with
62 additions
and
0 deletions
Resources/Public/JavaScript/sgYoutubeLightbox.js
+
62
−
0
View file @
555a715e
...
...
@@ -8,7 +8,69 @@ export default class SgYoutubeLightbox {
* Initializes the LightboxManager with the necessary parameters.
*/
constructor
()
{
const
youtubeItems
=
document
.
querySelectorAll
(
'
.sg-youtube-item
'
);
const
isMobile
=
window
.
matchMedia
(
'
(max-width: 679px)
'
).
matches
;
youtubeItems
.
forEach
((
item
)
=>
{
if
(
item
.
dataset
.
disableLightboxMobile
===
'
1
'
&&
isMobile
||
item
.
dataset
.
disableLightbox
===
'
1
'
&&
!
isMobile
)
{
item
.
classList
.
remove
(
'
sg-youtube-item
'
);
item
.
addEventListener
(
'
click
'
,
this
.
disableLightbox
.
bind
(
this
));
}
});
LightboxManager
.
init
({
type
:
'
video
'
,
glightbox
:
{
selector
:
'
.sg-youtube-item
'
}});
}
/**
* Replace the image with an iframe
*
* @param event
*/
disableLightbox
(
event
)
{
event
.
preventDefault
();
const
item
=
event
.
currentTarget
;
item
.
classList
.
add
(
'
no-lightbox
'
);
const
videoId
=
this
.
getVideoIdFromUrl
(
item
.
href
);
const
videoImage
=
item
.
querySelector
(
'
.sg-video__image
'
);
const
height
=
videoImage
.
offsetHeight
;
const
width
=
videoImage
.
offsetWidth
;
const
iframe
=
document
.
createElement
(
'
iframe
'
);
iframe
.
width
=
width
;
iframe
.
height
=
height
;
iframe
.
style
.
border
=
'
none
'
;
iframe
.
allowFullscreen
=
true
;
iframe
.
allow
=
'
accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture
'
;
iframe
.
src
=
`https://www.youtube-nocookie.com/embed/
${
videoId
}
`
;
item
.
replaceChild
(
iframe
,
videoImage
);
}
/**
* Prepares the given url, or returns null.
*
* @param {string} url
* @return {string|null}
*/
getVideoIdFromUrl
(
url
)
{
let
matches
=
url
.
match
(
/watch
\?
v=
(
.*
)
&list=
(
.*
)
/
);
if
(
!
matches
)
{
// check if the list parameter is missing
matches
=
url
.
match
(
/watch
\?
v=
([^
?&
]
*
)
/
);
if
(
!
matches
)
{
return
null
;
}
}
let
[,
videoString
]
=
matches
,
queryParameterSeparator
=
'
?
'
;
if
(
matches
[
2
])
{
videoString
+=
'
?list=
'
+
matches
[
2
];
queryParameterSeparator
=
'
&
'
;
}
return
videoString
+
queryParameterSeparator
+
'
autoplay=1&rel=0
'
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment