Usage
This function runs automatically, so it is not called manually. Is this incorrect?
Examples
Automatically play a video when a Bootstrap modal opens.
jQuery(document).on('show.bs.modal', function(e){
vidID = jQuery(e.target).find('iframe').attr('id');
players.youtube[vidID].playVideo();
});
Source File
Located in /assets/js/modules/video.js on line 373.
No Hooks
This function does not have any filters or actions available. Request one?nebula.youtubeReady = function(e){
//If GA4 or GTM have already "claimed" a video, this function will not run for that video
if ( typeof videoProgress === 'undefined' ){
let videoProgress = {};
}
nebula.videos = nebula.videos || {}; //Always make sure this is defined
let id = nebula.getYoutubeID(e.target);
if ( id ){
if ( !nebula.videos.hasOwnProperty(id) ){ //If the video object doesn't use the Youtube video ID, make a new one by duplicating from the Iframe ID
nebula.videos[id] = nebula.videos[jQuery(e.target.getIframe()).attr('id')];
}
nebula.videos[id].title = nebula.getYoutubeTitle(e.target) ?? 'Unkown';
nebula.videos[id].duration = e.target.getDuration(); //The total duration of the video. Unit: Seconds
nebula.videos[id].current = e.target.getCurrentTime(); //The current position of the video. Units: Seconds
nebula.videos[id].percent = e.target.getCurrentTime()/e.target.getDuration(); //The percent of the current position. Multiply by 100 for actual percent.
}
};
Override
To override or disable this JavaScript function, simply redeclare it with the exact same function name. Remember: Some functionality is conditionally loaded via dynamic imports, so if your function is not overriding properly, try listening for a DOM event (described below).
For non-module import functions:
nebula.youtubeReady = function(){
//Write your own code here, leave it blank, or return false.
}
For dynamically imported module function overrides:
jQuery(window).on('load', function(){
nebula.youtubeReady = function(){
//Write your own code here, leave it blank, or return false.
}
});
Custom Nebula DOM events do also exist, so you could also try the following if the Window Load listener does not work:
jQuery(document).on('nebula_module_loaded', function(module){
//Note that the module variable is also available to know which module specifically was imported
if ( typeof nebula.youtubeReady === 'function' ){
nebula.youtubeReady = function(){
//Write your own code here, leave it blank, or return false.
}
}
});