1export function init(){ 2 var tag = document.createElement('script'); 3 4 tag.src = "https://www.youtube.com/iframe_api"; 5 var firstScriptTag = document.getElementsByTagName('script')[0]; 6 firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); 7 8 if (window.YT){ 9 initPlayers(); 10 } else { 11 window.onYouTubeIframeAPIReady = initPlayers; 12 } 13} 14 15function initPlayers() { 16 [].forEach.call(document.getElementsByClassName('youtube_wrapper'), 17 (element) => { 18 if (!element.parentNode.classList.contains('initialized')){ 19 element.container = element.parentNode; 20 element.container.player = new YT.Player("video_player_" + element.container.dataset.id, { 21 videoId: element.container.dataset.id, 22 events: { 23 onReady: function(){ 24 element.container.removeEventListener('click', togglePlayer); 25 element.container.addEventListener('click', togglePlayer); 26 element.parentNode.classList.add('initialized'); 27 } 28 } 29 }); 30 } 31 }); 32} 33 34function togglePlayer(event) { 35 var element = this; 36 [].forEach.call(document.getElementsByClassName('youtube_container'), 37 (e) => { 38 if (e != element && e.classList.contains('initialized')){ 39 e.classList.remove('playing'); 40 e.player.stopVideo(); 41 } 42 }); 43 element.classList.toggle('playing'); 44 element.player.playVideo(); 45};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.