1/** 2 * Handles AJAX-based on-page-load functionality for Video Popup 3 * Triggers automatic popup display based on server-side conditions 4 * 5 * @author Alobaidi 6 * @since 2.0.0 7 */ 8 9 10/** 11 * Main execution block for on-page-load functionality 12 * Runs after DOM content is fully loaded and page resources are complete 13 */ 14document.addEventListener('DOMContentLoaded', function() { 15 window.addEventListener('load', () => { 16 17 /** 18 * Primary function that handles the AJAX request and popup display 19 * Validates configuration, makes AJAX call, and processes response 20 * @async 21 */ 22 async function VideoPopupOnPageLoad() { 23 24 if ( typeof theVideoPopupOplVars === 'undefined' ) { 25 console.log('onpage-load.js: theVideoPopupOplVars is not defined. AJAX request aborted.'); 26 return; 27 } 28 29 const currentId = theVideoPopupOplVars.current_id || 'none'; 30 const currentLocation = theVideoPopupOplVars.current_location || 'none'; 31 const userType = theVideoPopupOplVars.user_type || 'none'; 32 const ajaxAction = theVideoPopupOplVars.ajax_action || ''; 33 const ajaxUrl = theVideoPopupOplVars.ajax_url || ''; 34 const debugMode = theVideoPopupOplVars.debug && theVideoPopupOplVars.debug == 1 ? true : false; 35 36 if ( debugMode ) { 37 console.log(`onpage-load.js (on page load debug): Current ID by js parameter is "${currentId}".`); 38 console.log(`onpage-load.js (on page load debug): Current location by js parameter is "${currentLocation}".`); 39 console.log(`onpage-load.js (on page load debug): User type by js parameter is "${userType}".`); 40 console.log(`onpage-load.js (on page load debug): Ajax action by js parameter is "${ajaxAction}".`); 41 console.log(`onpage-load.js (on page load debug): Ajax URL by js parameter is "${ajaxUrl}".`); 42 console.log(''); // an empty line 43 } 44 45 if ( !currentId || !currentLocation || !userType || !ajaxAction || !ajaxUrl ) { 46 if ( debugMode ) { 47 console.log('onpage-load.js (on page load debug): Missing required data (currentId, currentLocation, userType, ajaxAction, or ajaxUrl). AJAX request aborted.'); 48 console.log('Suggested Solutions:'); 49 console.log(' 1. Remove the Video Popup plugin and reinstall it.'); 50 console.log(' 2. Clear the cache if you are using a caching plugin on your website.'); 51 } 52 return; 53 } 54 55 try { 56 const response = await fetch(ajaxUrl, { 57 method: 'POST', 58 headers: { 59 'Content-Type': 'application/x-www-form-urlencoded' 60 }, 61 body: 'action=' + encodeURIComponent(ajaxAction) + '¤t_id=' + encodeURIComponent(currentId) + '¤t_location=' + encodeURIComponent(currentLocation) + '&user_type=' + encodeURIComponent(userType) 62 }); 63 64 if ( !response.ok ) { 65 if ( debugMode ) { 66 console.log('onpage-load.js (on page load debug): Fetch failed with status ' + response.status); 67 } 68 return; 69 } 70 71 const textResponse = await response.text(); 72 73 if ( !textResponse ) { 74 console.log('Suggested Solutions:'); 75 console.log(' 1. Remove the Video Popup plugin and reinstall it.'); 76 console.log(' 2. Clear the cache if you are using a caching plugin on your website.'); 77 return; 78 } 79 80 if ( textResponse.trim() == 'no_options' ) { 81 console.log('onpage-load.js: No options.'); 82 console.log('Suggested Solutions:'); 83 console.log(' 1. Go to Video Popup > On Page Load > and click the "Save Changes" button.'); 84 console.log(' 2. Remove the Video Popup plugin and reinstall it.'); 85 console.log(' 3. Clear the cache if you are using a caching plugin on your website.'); 86 return; 87 } 88 89 if ( textResponse.trim() == 'opl_disabled' ) { 90 if ( debugMode ) { 91 console.log('onpage-load.js (on page load debug): On Page Load feature is disabled. Go to Video Popup > On Page Load > General Options, and enable it.'); 92 } 93 return; 94 } 95 96 if ( textResponse.trim() == 'no_url' ) { 97 if ( debugMode ) { 98 console.log('onpage-load.js (on page load debug): No video URL. Go to Video Popup > On Page Load > Video Settings, and enter a video URL.'); 99 } 100 return; 101 } 102
103 if ( textResponse.trim() == 'invalid_url' ) { 104 if ( debugMode ) { 105 console.log('onpage-load.js (on page load debug): Invalid video URL. Go to Video Popup > On Page Load > Video Settings, and enter a YouTube, Vimeo, or direct video URL (MP4 or WebM only).'); 106 } 107 return; 108 } 109 110 if ( textResponse.trim() == 'hide_by_cookie' ) { 111 if ( debugMode ) { 112 console.log('onpage-load.js (on page load debug): The video popup was prevented on page load by cookie.'); 113 console.log('onpage-load.js (on page load debug): You need to wait until the cookie expires, change the value of the "Cookie Expiry" field, or clear its value.'); 114 } 115 return; 116 } 117 118 const script = document.createElement('script'); 119 script.textContent = textResponse; 120 document.body.appendChild(script); 121 122 if ( debugMode ) { 123 console.log('=== Video Popup - On Page Load AJAX Debug - Start ==='); 124 console.log(textResponse); 125 console.log('=== Video Popup - On Page Load AJAX Debug - End ==='); 126 console.log(''); // an empty line 127 } 128 } catch (error) { 129 if (debugMode) { 130 console.log('onpage-load.js (on page load debug): Fetch request failed', error); 131 } 132 } 133 } 134 135 // Initialize the on-page-load process 136 VideoPopupOnPageLoad(); 137 }); 138});
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.