PageSourceSearch

https://reimaginepr.com/wp-content/plugins/ao-landing-pages/js/aops-lp-front.js?ver=1.10.2

js reimaginepr.com collected 2026-10-06 20:26:05 UTC 11,416 bytes, 397 lines download raw bytes

1/**
2 * Variables starting from "_" are global:
3 * 
4 * _dcq
5 * _submittedForm
6 * _landing_pages_opts
7 * _landing_page_popup_opts
8 * _optin_submit_method
9 * _wait_for_drip_response
10 * _drip_response
11 */
12
13
14jQuery(document).ready(function() {
15	
16	/* commented popup code
17	 * 
18	jQuery(".lp-link-wrapper").each(function(){
19		var $popupLink = jQuery(this);
20		var lp_id = $popupLink.attr('href');
21		
22		var lpRegexp = new RegExp("#lp_popup_",'g');
23		lp_id = lp_id.replace(lpRegexp,''); 
24		
25		var lp_popup_options = getLpPopupOptions(lp_id);
26		
27		if (lp_popup_options && lp_popup_options.iframe_url) {
28			var fancyboxIframeUrl = lp_popup_options.iframe_url;
29			
30			$popupLink.addClass('fancybox.iframe');
31			$popupLink.attr('data-fancybox-href', fancyboxIframeUrl);
32
33		}
34		else {
35			// make ajax call to get info about Landing Page
36			getAjaxInfo('aops_lp_get_info', {lp_id: lp_id}, function(data){
37				try {
38					var response = JSON.parse(data);
39					if (response.result === 'ok') {
40						var fancyboxIframeUrl = response.url;
41						
42						$popupLink.addClass('fancybox.iframe');
43						$popupLink.attr('data-fancybox-href', fancyboxIframeUrl);
44					}
45					else {
46						//console.log("aops_lp_get_info: " + lp_id + ', response: ', response);
47					}
48				}
49				catch (e) {
50					console.log('Exception while parsing AJAX received JSON:');
51					console.log(e);
52				}
53				
54			})
55		}
56	})
57	
58	jQuery(".lp-link-wrapper").fancybox({
59		type		: "iframe",
60		width		: "80%",
61		height		: "80%",
62		fitToView	: true,
63		autoScale   : false,
64		autoDimensions: false,
65		autoSize	: false,
66		closeClick	: false,
67		openEffect	: 'none',
68		closeEffect	: 'none',
69		tpl:	{
70			wrap     : '<div class="fancybox-wrap lp-popup" tabIndex="-1"><div class="fancybox-skin"><div class="fancybox-outer"><div class="fancybox-inner"></div></div></div></div>',
71			image    : '<img class="fancybox-image" src="{href}" alt="" />',
72			iframe   : '<iframe id="fancybox-frame{rnd}" name="fancybox-frame{rnd}" class="fancybox-iframe" frameborder="0" vspace="0" hspace="0"' + (navigator.userAgent.match(/msie/i) ? ' allowtransparency="true"' : '') + '></iframe>',
73			error    : '<p class="fancybox-error">Oops! The content you requested is missing.<br/>Contact us for help.</p>',
74			closeBtn : '<a title="Close" class="fancybox-item fancybox-close" href="javascript:;">&times;</a>',
75			next     : '<a title="Next" class="fancybox-nav fancybox-next" href="javascript:;"><span></span></a>',
76			prev     : '<a title="Previous" class="fancybox-nav fancybox-prev" href="javascript:;"><span></span></a>'
77		}
78	});
79
80   */
81  
82	// Setup form validation 
83	jQuery.validate({
84		// -- not needed yet -- form : '.lp-popup-form'
85		form : '.action-bar-top .lp-form, .action-bar-bottom .lp-form'
86	});
87	
88	
89	// not needed yet --> var $form = jQuery('.lp-popup-form');
90	var $top_form = jQuery('.action-bar-top .lp-form');
91	var $bottom_form = jQuery('.action-bar-bottom .lp-form');
92	
93	$top_form.find(".submit-button").blur(function(event){
94		$top_form.isValid();
95	});
96
97	$top_form.find(".submit-button").click(function(event){
98
99		_wait_for_drip_response = false;
100		_optin_submit_method = 'AJAX';
101		_submittedForm = $top_form;
102
103		sendFormData($top_form);
104
105		event.preventDefault();
106		return false;
107	});
108
109
110	$bottom_form.find(".submit-button").blur(function(event){
111		$bottom_form.isValid();
112	});
113
114	$bottom_form.find(".submit-button").click(function(event){
115
116		_wait_for_drip_response = false;
117		_optin_submit_method = 'AJAX';
118		_submittedForm = $bottom_form;
119
120		sendFormData($bottom_form);
121
122		event.preventDefault();
123		return false;
124	});
125		
126	if (jQuery("body#lp-body").length) { // check whether it is a LP
127
128		var lp_id = jQuery("body#lp-body").data('lp-id');
129		var lp_opts = getLpOptions(lp_id);
130		
131		// Remove Drip popup if corresponding option is set
132		if (lp_opts && lp_opts.disable_drip_popup === "1") { // note the "1" here. "1" must be treated as "true", "0" = "false".
133			setTimeout(function() { 
134				jQuery(".drip-tab-container").remove();
135			}, 1200);
136		}
137	};
138	
139	if (jQuery("body#lp-thankyou-body").length) { // check whether it is a Thank You page
140
141		var lp_id = jQuery("body#lp-thankyou-body").data('lp-id');
142		var lp_opts = getLpOptions(lp_id);
143		
144		// Remove Drip popup if corresponding option is set
145		if (lp_opts && lp_opts.disable_drip_popup === "1") { // note the "1" here. "1" must be treated as "true", "0" = "false".
146			setTimeout(function() { 
147				jQuery(".drip-tab-container").remove();
148			}, 1200);
149		}
150	};
151
152	
153	function getFormLpOptions($submittedForm) {
154		var $lp_id	= $submittedForm.find( "input[name='lp_id']" );
155		var lp_opts = false;
156		
157		if ($lp_id.length) {
158			lp_opts = getLpOptions($lp_id.val());
159		}
160		
161		return lp_opts;
162	}
163	
164	function getLpOptions(lp_id) {
165		var lp_opts = false;
166		
167		if (typeof(_landing_pages_opts) !== "undefined") {
168			if (typeof(_landing_pages_opts[lp_id]) !== "undefined") {
169				lp_opts = _landing_pages_opts[lp_id];
170			}
171		}		
172		return lp_opts;
173	}
174
175	function getLpPopupOptions(lp_id) {
176		var lp_popup_opts = false;
177		if (typeof(_landing_page_popup_opts) !== "undefined") {
178			if (typeof(_landing_page_popup_opts[lp_id]) !== "undefined") {
179				lp_popup_opts = _landing_page_popup_opts[lp_id];
180			}
181		}		
182		return lp_popup_opts;
183	}
184	
185	function sendFormData($submittedForm) {
186		//console.log($submittedForm);
187		
188		if ($submittedForm.is(':visible')) {
189			//console.log('$submittedForm is visible');
190			// Collect form fields
191			var $lp_id = $submittedForm.find( "input[name='lp_id']" );
192			var	$firstname = $submittedForm.find( "input[name='lp_firstname']" );
193			var $email = $submittedForm.find( "input[name='lp_email']" );
194			
195			if( $submittedForm.isValid() ) {
196				//console.log('$submittedForm is  valid');
197				
198				var valid_email = $email.hasClass("valid");
199				
200				// Check form validation
201				if (valid_email) {
202					//console.log('$submittedForm email is valid');
203
204					// Show Loading gif
205					// -- not needed yet -- $submittedForm.find(".lp-popup-loading").show();
206
207					// Get some values from elements on the page:
208					var	formData = {
209						lp_id: $lp_id.val(),
210						firstname: $firstname.val(),
211						email: $email.val()
212					};
213
214					var lp_opts = getFormLpOptions($submittedForm);
215
216					// if ThankYou page is enabled, opt-in form should sent POST to /thankyou)
217					// if ThankYou page is disabled, opt-in form shoould sent AJAX POST to Wordpress)
218
219					if (lp_opts && lp_opts.optin_submit_method) {
220						_optin_submit_method = lp_opts.optin_submit_method;
221					}
222
223					//console.log('optin_submit_method', optin_submit_method);
224
225					// Send the data to Drip
226					if (typeof(_dcq) !== 'undefined') {
227						//console.log('sendDripData',formData, lp_opts);
228						sendDripData(formData, lp_opts);
229					}
230
231					if (_optin_submit_method === 'AJAX') {
232						//console.log('sendAjaxData',formData);
233						// Send the data using AJAX. After AJAX call completion, will redirect if needed
234						sendAjaxData(formData, lp_opts);
235						// mailchimp submission will be handled by server
236						
237					}
238					else {
239						//console.log('POST');
240						waitForDripResponseAndSendPostData($submittedForm);
241						// mailchimp submission will be handled by server
242					}
243				}
244				else {
245					//console.log('$submittedForm email is not valid');
246				}
247			}
248			else {
249				//console.log('$submittedForm is not valid');
250			}
251		}
252	};
253	
254	function sendDripData(formData, lp_opts) {
255		_wait_for_drip_response = true;
256		_drip_response = false;
257		
258		if (lp_opts) { // We have landing page Drip options set 
259			
260			var drip_info = {
261				"success": processDripResponse, // callback: function to be called in case of success result of Drip request
262				"failure": processDripResponse	// callback: function to be called in case of failre
263			};
264
265			if (lp_opts.drip_tag !== "0") {
266				drip_info["tags"] = lp_opts.drip_tag;
267			}
268
269			if (lp_opts.custom_name_field) {
270				drip_info[lp_opts.custom_name_field] = formData.firstname;
271			}
272			else {
273				drip_info["first_name"] = formData.firstname;
274			}
275
276			drip_info["email"] = formData.email;
277
278			// Send form submission with defined parameters
279			_dcq.push(["identify", drip_info]);
280			//console.log('drip_info',drip_info);
281			
282			// Send custom event if needed
283			if (lp_opts.custom_event_enabled === "1") { // note the "1" here. "1" must be treated as "true", "0" = "false".
284				//console.log('lp_opts.custom_event_enabled');
285				_dcq.push(["track", lp_opts.custom_event_name]);
286			}
287			
288			// Subscribe to a campaign if specified						
289			if (lp_opts.campaign_id) {
290				//console.log('lp_opts.campaign_id', lp_opts.campaign_id, formData.email);
291				
292				_dcq.push(["subscribe", {
293					campaign_id: lp_opts.campaign_id, 
294					fields: { 
295						"email": formData.email,
296						"first_name":  formData.firstname
297					},
298					success: function(){ /*_drip_response = arguments[0]; console.log("subscribe success!", _drip_response); */ },
299					failure: function(){ /*_drip_response = arguments[0]; console.log("subscribe fail!", _drip_response); */ }
300				}]);
301				
302			}
303
304		}
305		else {
306			// Send form submission with default parameters
307			_dcq.push(["identify", {
308				"email": formData.email,
309				"first_name": formData.firstname,
310				"tags": [],
311				"success": processDripResponse,
312				"failure": processDripResponse
313			}]);
314		}
315		
316	}
317	
318	function sendAjaxData(formData, lp_opts) {
319		jQuery.post( ajax_object.ajaxurl, {
320			action: 'aops_lp_add_entry',
321			lp_id: formData.lp_id,
322			lp_firstname: formData.firstname,
323			lp_email: formData.email
324		}, function(data) {
325			jQuery('#flash-message').html("<div>Thank you!</div>").fadeIn(500).fadeOut(1000);
326			// -- not needed yet -- $submittedForm.find(".lp-popup-loading").hide();
327			// not needed yet --> jQuery.fancybox.close();
328			redirectIfNeeded(lp_opts);
329		} );
330	}
331	
332	function redirectIfNeeded(lp_opts) {
333		if (lp_opts.redirect_enabled === "1") { // note the "1" here. "1" must be treated as "true", "0" = "false".
334			window.location.href = lp_opts.redirect_url;
335		}
336	}
337	
338	function getAjaxInfo(ajax_action, ajax_data, callback) {
339		jQuery.post( ajax_object.ajaxurl, {
340			action: ajax_action,
341			data: ajax_data
342		}, function(data) {
343			callback(data);
344		});
345	}
346		
347	function processDripResponse() {
348		_drip_response = arguments[0];
349		_wait_for_drip_response = false;
350		
351		//console.log('processDripResponse',_drip_response);
352		if (_drip_response.success == true) {
353			//console.log('success');
354		}
355		else {
356			//console.log('error');
357		}
358		
359		if (_optin_submit_method === 'POST') {
360			waitForDripResponseAndSendPostData();
361		}
362	}
363	
364	function waitForDripResponseAndSendPostData() {
365		//console.log("waitForDripResponseAndSendPostData");
366		
367		var $submittedForm = _submittedForm;
368		//console.log(' waitForDripResponseAndSendPostData $submittedForm	',$submittedForm);
369		
370		var formIsSubmitted = false;
371		
372		if (_wait_for_drip_response) { // wait for 2 seconds ans submit form anyway
373			var drip_interval = setInterval(function() { 
374				//console.log('Wait For Drip:', _drip_response); 
375				if (_drip_response) {
376					//console.log('Got Drip response!', _drip_response); 
377					
378					$submittedForm.submit();
379					formIsSubmitted = true;
380					
381					clearInterval(drip_interval);
382				}
383			}, 200);
384			
385			setTimeout(function() { 
386				clearInterval(drip_interval);
387				if (!formIsSubmitted) {
388					$submittedForm.submit();	// submit form if it not yet submitted
389				}
390			}, 2000);
391		}
392		else { // Drip already responded, submit form
393			$submittedForm.submit();
394		}
395	}
396
397});

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.