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