HEX
Server: Apache
System: Linux webd003.cluster128.gra.hosting.ovh.net 6.18.42-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Wed Aug 5 15:59:48 CEST 2026 x86_64
User: slyfwmm (169339)
PHP: 8.1.34
Disabled: _dyuweyrj4,_dyuweyrj4r,dl
Upload Files
File: /home/s/l/y/slyfwmm/dallavitae/OLD_WP/wp-content/themes/skrollex/assets/js/widgets/youtube-bg.js
"use strict"; var $ = jQuery;
module.exports = function(){
	var tools = require('../tools/tools.js');
	var $youtubeBgs = $(".youtube-bg");
	if($youtubeBgs.length <1){
		return;
	}
	if(tools.isMobile){
		$youtubeBgs.each(function(){
			var $youtubeBg = $(this);
			var alt = $youtubeBg.data('alternative');
			if(alt){
				var $img = $('<img alt class="bg" src="'+alt+'"/>');
				$youtubeBg.after($img).remove();
			}
		});
		return;
	}
	var dones = [];
	$youtubeBgs.each(function(i){
		var $youtubeBg = $(this);
		var elId = $youtubeBg.attr('id');
		if(!elId) {
			elId = 'youtube-bg-'+i;
			$youtubeBg.attr('id', elId);
		}
		$youtubeBg.addClass('loading-func').data('loading', function(done){
			dones[elId] = done;
		});
	});
	var tag = document.createElement('script');
	tag.src = "https://www.youtube.com/iframe_api";
	var firstScriptTag = document.getElementsByTagName('script')[0];
	firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
	window.onYouTubeIframeAPIReady = function(){
		$youtubeBgs.each(function(){
			var $youtubeBg = $(this);
			var videoId = $youtubeBg.data('video');
			var vol = $youtubeBg.data('volume');
			var mute = $youtubeBg.data('mute');
			var elId = $youtubeBg.attr('id');
			var isNotDone = true;
			var player = new YT.Player(elId, {
				videoId: videoId,
				playerVars: {html5: 1, controls: 0, 'showinfo': 0, 'modestbranding': 1, 'rel': 0, 'allowfullscreen': true, 'iv_load_policy': 3, wmode: 'transparent' },
				events: {
					onReady: function(event){
						var resize = function(){
							var $iFrame = $(event.target.getIframe());
							var windowW = $(window).width();
							var windowH = $(window).height();
							var iFrameW = $iFrame.width();
							var iFrameH = $iFrame.height();
							var ifRatio = iFrameW/iFrameH;
							var wRatio = windowW/windowH;
							var vRatio = (function(){
								var r = $youtubeBg.data('ratio');
								return r === undefined ? ifRatio : eval(r);
							})(); 
							var setSize = function(vw, vh){
								var ifw, ifh;
								if(ifRatio > vRatio){
									ifh = Math.ceil(vh);
									ifw = Math.ceil(ifh * ifRatio);
								}else{
									ifw = Math.ceil(vw);
									ifh = Math.ceil(ifw / ifRatio);
								}
								$iFrame.css({
									width:  ifw+'px',
									height: ifh+'px',
									top: Math.round((windowH - ifh)/2)+'px',
									left: Math.round((windowW - ifw)/2)+'px',
								});
							}
							if(wRatio > vRatio){
								var vw = windowW;
								var vh = vw/vRatio;
								setSize(vw, vh);
							}else{
								var vh = windowH;
								var vw = vh * vRatio;
								setSize(vw, vh);
							}
						};
						$(window).resize(resize);
						resize();
						event.target.setPlaybackQuality('highres');
						if(vol !== undefined) event.target.setVolume(vol);
						if(mute === 'yes' || mute === undefined) event.target.mute();
						event.target.playVideo();
					},
					onStateChange: function(event){
						if(isNotDone && event.data === YT.PlayerState.PLAYING){
							isNotDone = false;
							(dones[elId])();
						}else if(event.data === YT.PlayerState.ENDED){
							event.target.playVideo();
						}
					},
					onError: function(event){
						if(isNotDone){
							isNotDone = false;
							(dones[elId])();
							console.log('YouTube Error: ' + event.data + ', video ID: ' + videoId);
						}
					}
				}
			});
		});	
	};
};