-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyoutube-player.js
executable file
·29 lines (20 loc) · 981 Bytes
/
youtube-player.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"use strict";
import './scss/youtube-player.scss';
export default function youtubePlayer(el) {
function fn(item, i, all) {
if (typeof item.parentNode !== 'undefined') {
const addElem = document.createElement('div'),
to = all || i === len - 1 ? addElem : addElem.cloneNode(true);
addElem.classList.add("js-youtube-player-embed");
item = item.parentNode.replaceChild(to, item);
to.appendChild(item);
item.classList.add("js-youtube-player-embed-item");
const url = item.getAttribute("src");
item.setAttribute("src", url);
}
}
const yt = 'youtube.com',
elemYotube = document.querySelectorAll(`${el} iframe[src*='${yt}'], ${el} iframe[src^='https://www.${yt}'], ${el} iframe[src^='//www.${yt}'], ${el} iframe[src^='//${yt}']`),
len = elemYotube.length;
return len ? Array.prototype.forEach.call(elemYotube, fn) : fn(elemYotube);
}