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
b327700d
Commit
b327700d
authored
3 years ago
by
Matthias Adrowski
Browse files
Options
Downloads
Patches
Plain Diff
[TASK] Remove old js dependency
parent
5e85eb79
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!6
TYPO3 11
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Resources/Public/JavaScript/youtubeLightbox.js
+0
-93
0 additions, 93 deletions
Resources/Public/JavaScript/youtubeLightbox.js
with
0 additions
and
93 deletions
Resources/Public/JavaScript/youtubeLightbox.js
deleted
100644 → 0
+
0
−
93
View file @
5e85eb79
/**
* JavaScript module for the sg-youtube plugin
*
* @deprecated since version 4.4.0 and will be removed in 5.0.0
*/
module
.
exports
=
function
()
{
'
use strict
'
;
const
$
=
require
(
'
jquery
'
);
require
(
'
magnific-popup
'
);
/**
* Initialize the whole Popup setup
*/
function
init
(
section
)
{
$
(
`
${
section
||
''
}
.sg-youtube-item`
).
each
(
function
(
index
,
item
)
{
let
$youtubeItem
=
$
(
item
),
viewportWidth
=
Math
.
max
(
document
.
documentElement
.
clientWidth
||
0
,
window
.
innerWidth
||
0
);
if
((
$youtubeItem
.
data
(
'
disable-lightbox
'
)
&&
viewportWidth
>=
680
)
||
(
$youtubeItem
.
data
(
'
disable-lightbox-mobile
'
)
&&
viewportWidth
<
680
)
)
{
$youtubeItem
.
on
(
'
click
'
,
replaceThumbnailWithVideo
);
}
else
{
$youtubeItem
.
magnificPopup
({
type
:
'
iframe
'
,
iframe
:
{
patterns
:
{
youtube
:
{
index
:
'
youtube.com/
'
,
id
:
function
(
url
)
{
return
prepareVideoUrl
(
url
);
},
src
:
'
//www.youtube-nocookie.com/embed/%id%
'
}
}
}
});
}
});
}
/**
* Replaces the given element behind the event with a youtube video.
*
* @param {Event} event
*/
function
replaceThumbnailWithVideo
(
event
)
{
event
.
preventDefault
();
let
$youtubeItem
=
$
(
event
.
currentTarget
);
// This needs to be done, because the height of inline elements is always 0, if on auto...
$youtubeItem
.
css
(
'
display
'
,
'
block
'
);
let
queryString
=
prepareVideoUrl
(
$youtubeItem
.
attr
(
'
href
'
)),
$thumbnailElement
=
$youtubeItem
.
find
(
'
.sg-youtube-image
'
),
width
=
$thumbnailElement
.
outerWidth
()
+
'
px
'
,
height
=
$thumbnailElement
.
outerHeight
()
+
'
px
'
;
$thumbnailElement
.
replaceWith
(
'
<div class="sg-youtube-item sg-card-shadow"
'
+
'
style="height:
'
+
height
+
'
; width:
'
+
width
+
'
;"><iframe
'
+
'
width="
'
+
width
+
'
" height="
'
+
height
+
'
"
'
+
'
src="https://www.youtube-nocookie.com/embed/
'
+
queryString
+
'
" frameborder="0"
'
+
'
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
'
+
'
allowfullscreen></iframe></div>
'
);
}
/**
* Prepares the given url, or returns null.
*
* @param {string} url
* @return {string|null}
*/
function
prepareVideoUrl
(
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
'
;
}
init
();
};
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