PageSourceSearch

https://www.weidmann-group.com/wp-content/plugins/logic-hop/public/js/ajax-methods.js?ver=3.9.4

js weidmann-group.com collected 2026-09-30 16:12:13 UTC 19,114 bytes, 650 lines download raw bytes

1
2function LogicHop (data) {
3	this.data = data;
4	this.payload = {};
5
6	if ( ! this.data.js_track ) {
7		this.setCookie( this.data.cookie );
8	}
9}
10
11LogicHop.prototype.addPayloadData = function ( key, data ) {
12	this.payload[key] = data;
13};
14
15LogicHop.prototype.setCookie = function ( c ) {
16	if ( c != null ) {
17		var cookie = c.name + '=' + c.value;
18		cookie += ';path=' + c.path;
19		cookie += ';expires=' + c.expires;
20		cookie += ';domain=' + c.domain;
21		cookie += ';samesite=lax';
22		if ( c.secure ) {
23			cookie += ';secure';
24		}
25		document.cookie = cookie;
26		this.data.cookie_set = c.value;
27	}
28};
29
30LogicHop.prototype.getCookie = function ( name ) {
31	if ( this.data.cookie_set ) {
32		return this.data.cookie_set;
33	}
34	var v = document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)');
35  return ( v ) ? v[2] : null;
36};
37
38LogicHop.prototype.parseLogic = function () {
39	var self = this;
40
41	if ( this.data.js_track && this.data.anti_flicker ) {
42		this.flicker_timeout = setTimeout( this.pageTimeout.bind( this ), this.data.anti_flicker_timeout )
43	}
44
45	self.data.send 				= (self.data.js_track) ? true : false;
46	self.data.conditions 		= [];
47	self.data.conditions_json 	= [];
48	self.data.variables 		= [];
49	self.data.referrer 			= ('referrer' in document) ? document.referrer : '';
50
51	jQuery('.logichop-js').each(function () {
52
53		var cid = jQuery(this).attr('data-cid');
54		var json = jQuery(this).attr('data-condition');
55		var data_var = jQuery(this).attr('data-var');
56		if (cid) {
57			self.data.send = true;
58			if (jQuery.inArray(cid, self.data.conditions) == -1) {
59				self.data.conditions.push(cid);
60			}
61		}
62		if (json) {
63			self.data.send = true;
64			if (jQuery.inArray(json, self.data.conditions_json) == -1) {
65				self.data.conditions_json.push(json);
66			}
67		}
68
69		if (data_var && self.data.js_vars) {
70			self.data.send = true;
71			if (jQuery.inArray(data_var, self.data.variables) == -1) {
72				self.data.variables.push(data_var);
73			}
74		}
75	});
76
77	if (self.data.send) {
78		var post_data = self.getQueryStrings();
79		post_data.action = 'logichop_parse_logic';
80		post_data.uncache = new Date().valueOf();
81		post_data.data = self.data;
82		post_data.logichop_cookie = self.getCookie( self.data.cookie_name );
83		post_data.nonce = self.data.nonce;
84		post_data.URL = window.location.pathname;
85		post_data.payload = self.payload;
86
87		jQuery.ajax({
88			type: 'POST',
89			dataType: 'json',
90			url: self.data.ajaxurl,
91			data: post_data,
92			cache: false,
93			success: function (data) {
94				if (data.success) {
95					self.setCookie( data.cookie );
96					self.data.loaded = true;
97					self.checkPageGoals();
98					if (data.redirect) window.location = data.redirect;
99					if (data.conditions.length > 0) self.displayConditions(data.conditions);
100					if (data.conditions_json.length > 0) self.displayConditionsJson(data.conditions_json);
101					if (data.variables.length > 0) self.displayVariables(data.variables);
102					if (typeof data.header_css != 'undefined' && data.header_css != '') {
103						jQuery('#logichop_header_css').append(data.header_css);
104					}
105					if (typeof data.css != 'undefined' && data.css != '') {
106						jQuery('body').addClass(data.css);
107					}
108					if (typeof data.css_preview != 'undefined') {
109						self.data.css_preview = data.css_preview;
110					}
111					self.pageRendered();
112				}
113			}
114		});
115	} else {
116		self.pageRendered();
117	}
118};
119
120LogicHop.prototype.displayConditions = function (conditions) {
121	var self = this;
122	for (var i = 0; i < conditions.length; i++) {
123		jQuery('.logichop-js[data-cid="' + conditions[i].cid + '"]').each(function () {
124			var el = jQuery(this);
125			var not = el.attr('data-not');
126			var condition = conditions[i].condition;
127			if (not === 'true') {
128				condition = !condition;
129			}
130			if (condition) {
131				var event = (el.attr('data-event')) ? el.attr('data-event').toLowerCase() : '';
132
133				el.addClass(el.attr('data-css-add')).removeClass(el.attr('data-css-remove'));
134
135				if (event == 'hide') el.hide();
136				if (event == 'show') el.show();
137				if (event == 'toggle') el.toggle();
138				if (event == 'slideup') el.slideUp();
139				if (event == 'slidedown') el.slideDown();
140				if (event == 'slidetoggle') el.slideToggle();
141				if (event == 'fadein') el.fadeIn();
142				if (event == 'fadeout') el.fadeOut();
143				if (event == 'fadetoggle') el.fadeToggle();
144
145				if (event == 'callback') {
146					var callback = window[el.attr('data-callback')];
147					if (typeof callback === 'function') {
148						var args = [el];
149						callback.apply(null, args);
150					}
151				}
152
153				if ( jQuery( el ).is( ':visible' ) ) {
154					jQuery( el ).addClass( 'logichop-visible' );
155				}
156			}
157		});
158	}
159};
160
161LogicHop.prototype.displayConditionsJson = function (conditions_json) {
162	for (var i = 0; i < conditions_json.length; i++) {
163		jQuery('.logichop-js[data-hash="' + conditions_json[i].hash + '"]').each(function () {
164			var el = jQuery(this);
165			var event = (el.attr('data-event')) ? el.attr('data-event').toLowerCase() : '';
166
167			if (!event) el.show();
168			if (event == 'show') el.show();
169			if (event == 'hide') el.hide();
170			if (event == 'toggle') el.toggle();
171			if (event == 'slideup') el.slideUp();
172			if (event == 'slidedown') el.slideDown();
173			if (event == 'slidetoggle') el.slideToggle();
174			if (event == 'fadein') el.fadeIn();
175			if (event == 'fadeout') el.fadeOut();
176			if (event == 'fadetoggle') el.fadeToggle();
177
178			if ( jQuery( el ).is( ':visible' ) ) {
179				jQuery( el ).addClass( 'logichop-visible' );
180			}
181		});
182	}
183};
184
185LogicHop.prototype.displayVariables = function (vars) {
186	var self = this;
187	for (var i = 0; i < vars.length; i++) {
188		if (vars[i].data_var && typeof vars[i].value != "undefined") {
189			jQuery('.logichop-js[data-var="' + vars[i].data_var + '"]').each(function () {
190				var el = jQuery(this);
191				var type = (el.attr('data-type')) ? el.attr('data-type').toLowerCase() : false;
192				var event = (el.attr('data-event')) ? el.attr('data-event').toLowerCase() : '';
193				var charcase = (el.attr('data-case')) ? el.attr('data-case').toLowerCase() : false;
194				var spaces = (el.attr('data-spaces')) ? el.attr('data-spaces').toLowerCase() : false;
195				var prepend = (el.attr('data-prepend')) ? el.attr('data-prepend') : false;
196				var append = (el.attr('data-append')) ? el.attr('data-append') : false;
197				var _default = (el.attr('data-default')) ? el.attr('data-default') : false;
198
199				if ( ! type && el.get(0).tagName == 'A' ) {
200					type = 'href';
201				} else if ( ! type && el.get(0).tagName == 'IMG' ) {
202					type = 'src';
203				} else if ( ! type && el.get(0).tagName == 'INPUT' ) {
204					type = 'value';
205				} else if ( ! type ) {
206					type = 'replace';
207				}
208
209				if ( vars[i].value != null || _default !== false ) {
210					var value = vars[i].value;
211
212					if ( value == null ) {
213						value = _default;
214					}
215
216					if (charcase) {
217						if (value) {
218							value = value.textf(charcase);
219						}
220					}
221
222					if (spaces) value = value.replace(/ /g, spaces);
223
224					if (type == 'replace' || type == 'html') {
225						el.html(value).addClass(el.attr('data-css-add')).removeClass(el.attr('data-css-remove'));
226					}
227
228					if (type == 'append') {
229						el.append(value).addClass(el.attr('data-css-add')).removeClass(el.attr('data-css-remove'));
230					}
231
232					if (type == 'prepend') {
233						el.prepend(value).addClass(el.attr('data-css-add')).removeClass(el.attr('data-css-remove'));
234					}
235
236					if (type == 'text') {
237						el.text(value).addClass(el.attr('data-css-add')).removeClass(el.attr('data-css-remove'));
238					}
239
240					if (type == 'value') {
241						el.val(value).addClass(el.attr('data-css-add')).removeClass(el.attr('data-css-remove'));
242					}
243
244					if ( type == 'class' ) {
245						el.addClass( value );
246					}
247
248					if ( type == 'src' ) {
249						var src = el.attr( 'src' );
250						if ( src ) {
251							var new_src = src.replace( /#VAR#/, value );
252							el.attr( 'src', new_src );
253						}
254					}
255
256					if ( type == 'href' ) {
257						var href = el.attr( 'href' );
258						if ( href ) {
259							var new_href = href.replace( /#VAR#/, value );
260							el.attr( 'href', new_href );
261						}
262					}
263
264					if ( prepend ) el.prepend( prepend );
265					if ( append ) el.append( append );
266
267					if (event == 'hide') el.hide();
268					if (event == 'show') el.show();
269					if (event == 'toggle') el.toggle();
270					if (event == 'slideup') el.slideUp();
271					if (event == 'slidedown') el.slideDown();
272					if (event == 'slidetoggle') el.slideToggle();
273					if (event == 'fadein') el.fadeIn();
274					if (event == 'fadeout') el.fadeOut();
275					if (event == 'fadetoggle') el.fadeToggle();
276				}
277
278			});
279		}
280	}
281};
282
283LogicHop.prototype.checkPageGoals = function () {
284	var self = this;
285
286	jQuery('.logichop-goal').each(function () {
287		var goal = jQuery(this).val();
288		var condition = (jQuery(this).attr('data-condition')) ? jQuery(this).attr('data-condition') : false;
289		var condition_not = (jQuery(this).attr('data-not')) ? true : false;
290		var delete_goal = (jQuery(this).attr('data-delete')) ? true : false;
291		if (goal) {
292			self.updateGoal(goal, condition, condition_not, delete_goal);
293		}
294	});
295};
296
297LogicHop.prototype.enablePageGoals = function () {
298	var self = this;
299
300	jQuery('.logichop-click').on('click', get_goal);
301	jQuery('.logichop-dblclick').on('dblclick', get_goal);
302	jQuery('.logichop-mouseenter').on('mouseenter', get_goal);
303	jQuery('.logichop-mouseleave').on('mouseleave', get_goal);
304	jQuery('.logichop-keypress').on('keypress', get_goal);
305	jQuery('.logichop-keydown').on('keydown', get_goal);
306	jQuery('.logichop-keyup').on('keyup', get_goal);
307	jQuery('.logichop-submit').on('submit', get_goal);
308	jQuery('.logichop-change').on('change', get_goal);
309	jQuery('.logichop-focus').on('focus', get_goal);
310	jQuery('.logichop-blur').on('blur', get_goal);
311	jQuery('.logichop-load').on('load', get_goal);
312	jQuery('.logichop-resize').on('resize', get_goal);
313	jQuery('.logichop-scroll').on('scroll', get_goal);
314	jQuery('.logichop-unload').on('unload', get_goal);
315
316	function get_goal (event) {
317		var goal = jQuery(event.target).data('goal');
318		var delete_goal = (jQuery(this).attr('data-delete')) ? true : false;
319		if (goal) {
320			self.updateGoal(goal, false, false, delete_goal);
321		}
322	}
323
324	if (typeof self.data.goal_ev != 'undefined' && typeof self.data.goal_el != 'undefined' && typeof self.data.goal_js != 'undefined') {
325		jQuery(self.data.goal_el).on(self.data.goal_ev, function () {
326			self.updateGoal(self.data.goal_js);
327		});
328	}
329};
330
331LogicHop.prototype.getVariable = function (data_var) {
332	data_var = (typeof data_var !== 'undefined') ? data_var : false;
333
334	var self = this;
335	var post_data = {
336			action: 'logichop_data',
337			data_var: data_var,
338			uncache: new Date().valueOf(),
339			logichop_cookie: self.getCookie( self.data.cookie_name ),
340			nonce: self.data.nonce
341		};
342
343	return new Promise( function ( resolve, reject ) {
344		jQuery.ajax({
345			type: 'POST',
346			dataType: 'json',
347			url: self.data.ajaxurl,
348			data: post_data,
349			cache: false,
350			success: function ( data ) {
351				resolve( data );
352			},
353			error: function () {
354				reject( new Error( 'fail' ) );
355			}
356		});
357	});
358};
359
360LogicHop.prototype.getVariables = function () {
361	var self = this;
362	var post_data = {
363			action: 'logichop_data_debug',
364			uncache: new Date().valueOf(),
365			logichop_cookie: self.getCookie( self.data.cookie_name ),
366			nonce: self.data.nonce
367		};
368
369	return new Promise( function ( resolve, reject ) {
370		jQuery.ajax({
371			type: 'POST',
372			dataType: 'json',
373			url: self.data.ajaxurl,
374			data: post_data,
375			cache: false,
376			success: function ( data ) {
377				resolve( data );
378			},
379			error: function () {
380				reject( new Error( 'fail' ) );
381			}
382		});
383	});
384};
385
386LogicHop.prototype.checkCondition = function (condition, condition_true, condition_false) {
387	condition = (typeof condition !== 'undefined') ? condition : false;
388	condition_true = (typeof condition_true !== 'undefined') ? condition_true : null;
389	condition_false = (typeof condition_false !== 'undefined') ? condition_false : null;
390
391	var post_data = {
392			action: 'logichop_condition',
393			cid: condition,
394			uncache: new Date().valueOf(),
395			logichop_cookie: this.getCookie( this.data.cookie_name ),
396			nonce: this.data.nonce
397		};
398
399	jQuery.ajax({
400		type: 'POST',
401		dataType: 'json',
402		url: this.data.ajaxurl,
403		data: post_data,
404		cache: false,
405		success: function (data) {
406			if (data.success && data.condition) {
407				if ( condition_true !== null ) {
408					condition_true( condition );
409				}
410			} else {
411				if ( condition_false !== null ) {
412					condition_false( condition );
413				}
414			}
415		},
416		error: function () {
417			if ( condition_false !== null ) {
418				condition_false( condition );
419			}
420		}
421	});
422};
423
424LogicHop.prototype.updateGoal = function (goal, condition, condition_not, delete_goal) {
425	condition = (typeof condition !== 'undefined') ? condition : false;
426	condition_not = (typeof condition_not !== 'undefined') ? condition_not : false;
427	delete_goal = (typeof delete_goal !== 'undefined') ? delete_goal : false;
428
429	var post_data = {
430			action: 'logichop_goal',
431			goal: goal,
432			uncache: new Date().valueOf(),
433			logichop_cookie: this.getCookie( this.data.cookie_name ),
434			nonce: this.data.nonce
435		};
436	if (condition) post_data.condition = condition;
437	if (condition_not) post_data.condition_not = true;
438	if (delete_goal) post_data.delete_goal = true;
439
440	jQuery.ajax({
441		type: 'POST',
442		dataType: 'json',
443		url: this.data.ajaxurl,
444		data: post_data,
445		cache: false,
446		success: function (data) {
447			return true;
448		}
449	});
450};
451
452LogicHop.prototype.getQueryStrings = function () {
453	var match,
454        pl     = /\+/g,
455        search = /([^&=]+)=?([^&]*)/g,
456        decode = function (s) { return decodeURIComponent(s.replace(pl, ' ')); },
457        query  = window.location.search.substring(1);
458	var qs = {};
459    while (match = search.exec(query)) qs[decode(match[1])] = decode(match[2]);
460    return qs;
461};
462
463LogicHop.prototype.logicBarSetup = function () {
464	var self = this;
465
466	var inputs = document.querySelectorAll( '.logichop-logic-bar' );
467	inputs.forEach( function ( el, index, array ) {
468
469		var hash = el.getAttribute( 'data-hash' );
470		var delay = el.getAttribute( 'data-delay' );
471
472		if ( delay == 'none' ) {
473				self.logicBarPosition();
474		} else if ( delay == 'scroll' ) {
475			window.onscroll = function () {
476				self.logicBarDisplay( hash );
477			};
478		} else if ( delay == 'click' ) {
479			document.addEventListener( 'click', function ( e ) {
480				self.logicBarDisplay( hash );
481			} );
482		}  else if ( delay == 'exit' ) {
483			document.addEventListener( 'mouseout', function ( e ) {
484    		if ( e.toElement === null && e.relatedTarget === null ) {
485	        self.logicBarDisplay( hash );
486    		}
487			} );
488		} else {
489			var timeout = parseInt( delay );
490			if ( ! isNaN( timeout ) ) {
491				setTimeout( function () {
492					self.logicBarDisplay( hash );
493				}, timeout );
494			}
495		}
496	} );
497}
498
499LogicHop.prototype.logicBarDisplay = function ( hash ) {
500	var bar = document.getElementById( 'bar-' + hash );
501	var block = document.getElementById( 'block-' + hash );
502
503	if ( bar ) {
504		if ( bar.classList.contains( 'logic-bar-hide' ) ) {
505			bar.classList.remove( 'logic-bar-hide' );
506			this.logicBarPosition();
507			if ( block ) {
508				block.classList.remove( 'logic-bar-hide' );
509			}
510		}
511	}
512}
513
514LogicHop.prototype.logicBarPosition = function () {
515
516	jQuery( '.logichop-logic-bar:visible' ).each( function () {
517		if ( ! jQuery( this ).hasClass( 'logichop-logic-bar-popup' ) ) {
518			var margin = parseInt( jQuery( 'html' ).css( 'margin-top' ) );
519			var height = jQuery( this ).outerHeight();
520			jQuery( 'body' ).css( 'padding-top', height + 'px' );
521			jQuery( this ).css( 'top', margin + 'px' );
522		}
523	} );
524}
525
526LogicHop.prototype.logicBarDismiss = function () {
527	if (jQuery('.logichop-logic-bar').is(':visible')) {
528		jQuery('body').css('padding-top', 0);
529
530		if ( ! jQuery('.logichop-logic-bar').hasClass('logichop-logic-bar-popup') ) {
531			jQuery('.logichop-logic-bar').slideUp();
532		} else {
533			jQuery('.logichop-logic-bar').hide();
534			jQuery('.logichop-logic-bar-screen-block').fadeOut();
535		}
536	}
537}
538
539LogicHop.prototype.pageRendered = function () {
540	jQuery('.logichop-render-hide').removeClass('logichop-render-hide');
541	jQuery('.logichop-fade-in').fadeTo('fast', 1);
542	jQuery('.logichop-slide-down').slideDown();
543
544	if ( this.flicker_timeout ) {
545		clearTimeout( this.flicker_timeout );
546	}
547
548	this.logicBarSetup();
549
550	if (typeof logichop_page_rendered == 'function') {
551		logichop_page_rendered();
552	}
553};
554
555LogicHop.prototype.pageTimeout = function () {
556	jQuery('.logichop-render-hide').removeClass('logichop-render-hide');
557	jQuery('.logichop-fade-in').fadeTo('fast', 1);
558	jQuery('.logichop-slide-down').slideDown();
559
560	this.logicBarSetup();
561
562	if (typeof logichop_page_timeout == 'function') {
563		logichop_page_timeout();
564	}
565};
566
567if (typeof logichop.pid != 'undefined') {
568	var logichop = new LogicHop(logichop);
569
570	jQuery(document).ready(function () {
571		logichop.parseLogic();
572		logichop.enablePageGoals();
573
574		jQuery('.logic-bar-close, .logic-bar-dismiss, .logichop-logic-bar-screen-block').click('click', function(e){
575			logichop.logicBarDismiss();
576			e.preventDefault();
577		})
578	});
579}
580
581window.onresize = function () {
582	if (typeof logichop != 'undefined') {
583		logichop.logicBarPosition();
584	}
585}
586
587function logichop_var ( key ) {
588	if ( typeof logichop != 'undefined' && logichop.data.vars !==  null ) {
589		if ( typeof logichop.data.vars[ key ] != 'undefined' ) {
590			return logichop.data.vars[ key ];
591		}
592	}
593	return null;
594}
595
596function logichop_var_promise ( key ) {
597	if ( typeof logichop != 'undefined' ) {
598		return logichop.getVariable( key );
599	}
600	return null;
601}
602
603function logichop_condition (condition, condition_true, condition_false) {
604	condition = (typeof condition !== 'undefined') ? condition : false;
605	condition_true = (typeof condition_true !== 'undefined') ? condition_true : null;
606	condition_false = (typeof condition_false !== 'undefined') ? condition_false : null;
607	if (typeof logichop != 'undefined' && condition) {
608		logichop.checkCondition(condition, condition_true, condition_false);
609	}
610}
611
612function logichop_goal (goal, condition, condition_not) {
613	condition = (typeof condition !== 'undefined') ?  condition : false;
614	condition_not = (typeof condition_not !== 'undefined') ?  condition_not : false;
615	if (typeof logichop != 'undefined') {
616		logichop.updateGoal(goal, condition, condition_not);
617	}
618}
619
620function logichop_goal_delete (goal, condition, condition_not) {
621	condition = (typeof condition !== 'undefined') ?  condition : false;
622	condition_not = (typeof condition_not !== 'undefined') ?  condition_not : false;
623	if (typeof logichop != 'undefined') {
624		logichop.updateGoal(goal, condition, condition_not, true);
625	}
626}
627
628function logichop_debug () {
629	if ( typeof logichop != 'undefined' ) {
630		logichop.getVariables().then( function ( data ) { console.log( data ) } );
631	}
632}
633
634String.prototype.textf = function(type) {
635	if (type == 'lower') return this.toLowerCase();
636	if (type == 'upper') return this.toUpperCase();
637	if (type == 'words') return this.ucwords();
638	if (type == 'first') return this.capitalize();
639	return this;
640}
641
642String.prototype.ucwords = function() {
643	return this.toLowerCase().replace(/\b[a-z]/g, function(letter) {
644		return letter.toUpperCase();
645	});
646}
647
648String.prototype.capitalize = function() {
649	return this.charAt(0).toUpperCase() + this.slice(1);
650}

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.