PageSourceSearch

https://wedaremarketing.com/wp-content/plugins/if-so/public/js/if-so-public.js?ver=1.9.3.1

js wedaremarketing.com collected 2026-10-08 13:12:00 UTC 11,838 bytes, 328 lines download raw bytes

1var ifso_viewed_triggers = {};
2
3var ifso_scope = {
4	evalScriptsFromHTML :function(html){
5		if(typeof(jQuery) !== 'function')
6			return false;
7
8		var el = document.createElement('div');
9		jQuery(el).append(html);
10		var scripts = '';
11		jQuery(el).find('script').each(function(index){
12			scripts += this.innerHTML;
13		});
14		eval.call(null, scripts);	//Indirect eval call - execute in global scope - (1,eval)(scripts);
15	},
16	createCookie : function(name, value, days) {
17		var expires;
18		if (days) {
19			var date = new Date();
20			date.setTime(date.getTime()+(days*24*60*60*1000));
21			expires = "; expires="+date.toGMTString();
22		}
23		else {
24			expires = "";
25		}
26		document.cookie = name+"="+value+expires+"; path=/";
27	},
28	getCookie : function(c_name) {
29		var c_value = document.cookie,
30			c_start = c_value.indexOf(" " + c_name + "=");
31		if (c_start == -1) c_start = c_value.indexOf(c_name + "=");
32		if (c_start == -1) {
33			c_value = null;
34		} else {
35			c_start = c_value.indexOf("=", c_start) + 1;
36			var c_end = c_value.indexOf(";", c_start);
37			if (c_end == -1) {
38				c_end = c_value.length;
39			}
40			c_value = unescape(c_value.substring(c_start, c_end));
41		}
42		return c_value;
43	},
44};
45
46var ajax_triggers_loaded = document.createEvent('Event');
47ajax_triggers_loaded.initEvent('ifso_ajax_triggers_loaded', true, true);
48ifso_scope.DispatchTriggersLoaded  =  function () {document.dispatchEvent(ajax_triggers_loaded);ifso_scope.DispatchAjaxContentLoaded();};
49
50var ajax_conditions_loaded = document.createEvent('Event');
51ajax_conditions_loaded.initEvent('ifso_ajax_conditions_loaded', true, true);
52ifso_scope.DispatchStandaloneCondLoaded  =  function () {document.dispatchEvent(ajax_conditions_loaded);ifso_scope.DispatchAjaxContentLoaded();};
53
54var ajax_content_loaded = document.createEvent('Event');
55ajax_content_loaded.initEvent('ifso_ajax_content_loaded', true, true);
56ifso_scope.DispatchAjaxContentLoaded  =  function () {document.dispatchEvent(ajax_content_loaded);};
57
58
59(function( $ ) {
60	'use strict';
61
62	$(document).ready(function () {
63		function if_so_public(){
64			for(var ifso_scope_member_name in ifso_scope ){
65				if(typeof(ifso_scope_member_name) !=='undefined' && typeof(ifso_scope[ifso_scope_member_name])!=='undefined'){
66					this[ifso_scope_member_name] = ifso_scope[ifso_scope_member_name];
67				}
68			}
69		}
70
71		if_so_public.prototype = {
72			lookForLoadLaterTriggers : function(defer=false,ignoreAtts=true){
73				var _this = this;
74				var ret = [];
75				var tags = $('IfSoTrigger');
76				tags.each(function(index,el){
77					var tid = el.getAttribute('tid');
78					var ajaxAttsStr = JSON.stringify(_this.lookForAttrsForAjax(el));
79					var deferAttr =  el.getAttribute('defer');
80					if((deferAttr===null && !defer) ||  (deferAttr!==null && defer)){
81						if(null!== tid){
82							if($.inArray(tid,ret)<0 && (ignoreAtts || ajaxAttsStr==='{}')){
83								ret.push(tid);
84							}
85							else if(!ignoreAtts && ajaxAttsStr!=='{}' && $.inArray(ajaxAttsStr,ret)<0){
86								ret.push({...JSON.parse(ajaxAttsStr), 'id':tid});
87							}
88						}
89					}
90				});
91				return ret;
92			},
93
94			replaceLoadLaterTriggers : function(defer = false){
95				var toReplace = this.lookForLoadLaterTriggers(defer,false);
96				var _this = this;
97				if (toReplace.length>0){
98					this.sendAjaxReq('render_ifso_shortcodes',{triggers:toReplace,pageload_referrer:referrer_for_pageload},function(ret){	//Referrer from if-so public
99						if(ret && ret!== null){
100							try{
101								var data = JSON.parse(ret);
102								$.each(data, function(tid,tval){
103									var tagsInDom = _this.lookForTriggerTags(tid);
104									tagsInDom.each(function(i,tag){
105										tag.outerHTML = tval;
106										_this.evalScriptsFromHTML(tval);
107									})
108								});
109								ifso_scope.DispatchTriggersLoaded();
110							}
111							catch(e){
112								console.error('Error fetching if-so triggers!');
113								console.error(e);
114							}
115						}
116					})
117				}
118			},
119
120			lookForStandaloneConditions : function(tags){
121				var ret = [];
122				tags.each(function(index,el){
123					var _content = el.getAttribute('content');
124					var _default = el.getAttribute('default');
125					var _rule = el.getAttribute('rule');
126					var _hash = el.getAttribute('hash');
127					var _data = {'content':_content,'default':_default,'rule':_rule,'hash':_hash};
128					ret.push(_data);
129				});
130				return ret;
131			},
132
133			replaceStandaloneConditions : function(){
134				var elements = $('IfSoCondition');
135				var toReplace = this.lookForStandaloneConditions(elements);
136				var _this = this;
137				if(toReplace.length>0){
138					this.sendAjaxReq('render_ifso_shortcodes',{triggers:JSON.stringify(toReplace),pageload_referrer:referrer_for_pageload,is_standalone_condition:true},function(ret){	//Referrer from if-so public
139						try{
140							var data = JSON.parse(ret);
141							$.each(data, function(id,val){
142								elements[id].outerHTML = val;
143								_this.evalScriptsFromHTML(val);
144							});
145							ifso_scope.DispatchStandaloneCondLoaded();
146						}
147						catch(e){
148							console.error('Error fetching if-so standalone conditions!');
149							console.error(e);
150						}
151					});
152				}
153			},
154
155			lookForDKI : function(tags){
156				var ret = [];
157				tags.each(function(index,el){
158					var _dkiAtts = el.getAttribute('dkiAtts');
159					ret.push(_dkiAtts);
160				});
161				return ret;
162			},
163
164			replaceDkiElements : function(){
165				var dkiElements = $('IfSoDKI');
166				var toReplace = this.lookForDKI(dkiElements);
167				if(toReplace.length>0){
168					this.sendAjaxReq('render_ifso_shortcodes',{triggers:JSON.stringify(toReplace),pageload_referrer:referrer_for_pageload,is_dki:true},function(ret){	//Referrer from if-so public
169						try{
170							var data = JSON.parse(ret);
171							$.each(data, function(id,val){
172								dkiElements[id].outerHTML = val;
173							});
174						}
175						catch(e){
176							console.error('Error fetching if-so DKI!');
177							console.error(e);
178						}
179					});
180				}
181			},
182
183			sendAjaxReq : function(action, data, cb) {
184				data['action'] = action;
185				data['nonce'] = ifso_nonce;
186				//data['page_url'] = ifso_page_url;
187				data['page_url'] = window.location.href;
188
189				$.post(ajaxurl, data, function(response) {
190					if (cb)
191						cb(response);
192				});
193			},
194
195			deleteCookie : function( name ) {
196				document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/;";
197			},
198
199			initialize_last_viewed_globals : function(){
200				var cookie = this.getCookie('ifso_last_viewed');
201				try{
202					var cookieObj = JSON.parse(cookie);
203					ifso_viewed_triggers = cookieObj;
204				}
205				catch(err){console.log('ERR! ' + err)}
206			},
207
208			ifso_analytics_do_conversion : function(conversions){
209				var params = {an_action:'doConversion',postid:666, viewed_triggers:JSON.stringify(ifso_viewed_triggers),conversions:JSON.stringify(conversions)};
210				this.sendAjaxReq('ifso_analytics_req',params, function(){});
211			},
212
213			ifso_google_analytcis_events_run : function(){
214				if(!isAnalyticsOn || typeof(gtag)==='undefined' || $('ifsoTriggerAnalyticsEvent').length<=0)
215					return;
216				$.each($('ifsoTriggerAnalyticsEvent'),function(key,value){
217					var event_name = value.getAttribute('event_name');
218					try{var el_event_data = JSON.parse(value.getAttribute('event_data'));}
219					catch (err){el_event_data = {};}
220					var event_data = null;
221					if(event_name==='ifso-trigger-viewed'){
222						var ev_version_name = typeof(el_event_data['version_name'])!=='undefined' && el_event_data['version_name']!==null  ? el_event_data['version_name'] : '';
223						event_data = {ifso_trigger_id:el_event_data['trigger'],ifso_trigger_version:el_event_data['version'],event_label:'ifso-content-viewed'} ;
224						if(ev_version_name!=='')
225							event_data['ifso_trigger_version_name']  = ev_version_name;
226						event_data['event_category'] = 'if-so';
227					}
228					if(event_name==='custom'){
229						var event_data = {};
230						$.each(el_event_data,function(e_attr,e_val){
231							if(e_attr==='ga4_event_type')
232								event_name = e_val;
233							else
234								event_data[e_attr] = e_val;
235						});
236					}
237					if(event_data!==null)
238						gtag('event', event_name,event_data);
239					value.remove();
240				});
241			},
242			lookForAttrsForAjax : function (elem){
243				var ret = {};
244				$.each(ifso_attrs_for_ajax,function (key,value){
245					if(elem.getAttribute(value)!==null)
246						ret[value] = elem.getAttribute(value);
247				});
248				return ret;
249			},
250			lookForTriggerTags : function(trigger){
251				if(isNaN(trigger)){
252					var trigger_atts = JSON.parse(trigger);
253					var tagsSelector = 'IfSoTrigger[tid="'+trigger_atts.id+'"]';
254					Object.keys(trigger_atts).forEach(function (val){if(val!=='id') tagsSelector += '[' + val + '="' + trigger_atts[val] + '"]'});
255				}
256				else{
257					var tagsSelector = 'IfSoTrigger[tid="'+trigger+'"]';
258					ifso_attrs_for_ajax.forEach(function (val){tagsSelector += ':not([' + val + '])';})
259				}
260				return $(tagsSelector);
261			}
262		};
263
264		var ifso_public_instance = new if_so_public();
265
266		ifso_public_instance.replaceLoadLaterTriggers(false);
267		var replace_defered  = function(){
268			ifso_public_instance.replaceLoadLaterTriggers(true);
269			$(document).unbind("click keydown keyup mousemove",replace_defered);
270		};
271		$(document).on('click keydown keyup mousemove',replace_defered);
272		ifso_public_instance.replaceStandaloneConditions();
273		$(document).on('ifso_ajax_conditions_loaded',ifso_public_instance.replaceStandaloneConditions.bind(ifso_public_instance));
274		ifso_public_instance.replaceDkiElements();
275
276		ifso_public_instance.ifso_google_analytcis_events_run();
277		$(document).on('ifso_ajax_content_loaded',ifso_public_instance.ifso_google_analytcis_events_run);
278
279
280		if(isPageVisitedOn || isVisitCountEnabled){	//Passed form if-so public
281			ifso_public_instance.sendAjaxReq('ifso_add_page_visit', {ifso_count_visit:parseInt(isVisitCountEnabled),isfo_save_page_visit:parseInt(isPageVisitedOn)}, function(response){});
282		}
283
284		if(isAnalyticsOn){	//Passed from if-so public
285			ifso_public_instance.initialize_last_viewed_globals();
286			if(ifso_public_instance.getCookie('ifso_viewing_triggers')) ifso_public_instance.sendAjaxReq('ifso_anal
286ytics_req',{postid:666,an_action:'ajaxViews',data:ifso_public_instance.getCookie('ifso_viewing_triggers') });
287
288			if($('.ifso-conversion-complete').length>0){
289				var conversions = [];
290				$.each($('.ifso-conversion-complete'),function(key,value){
291					if(value.getAttribute('completed')!==null) return;
292					var allowed_attr = value.getAttribute('allowed_triggers');
293					var disallowed_attr = value.getAttribute('disallowed_triggers');
294					var once_per_attr = value.getAttribute('once_per_time');
295					var name_attr = value.getAttribute('ifso_name');
296					var conversion = {allowed:[],disallowed:[]};
297					if(allowed_attr!=null && allowed_attr != 'all')
298						conversion.allowed = allowed_attr.split(',');
299					if(disallowed_attr!=null)
300						conversion.disallowed = disallowed_attr.split(',');
301					if(once_per_attr!==null && name_attr!==null){
302						conversion.once_per_time = once_per_attr;
303						conversion.name = name_attr
304					}
305					conversions.push(conversion);
306					value.setAttribute('completed',1);
307				});
308				if(conversions.length>0) ifso_public_instance.ifso_analytics_do_conversion(conversions);
309			}
310		}
311
312
313		//Bounce mechanism - not in use for now
314		/*if(getCookie('ifso_bounce')){
315            sendAjaxReq('ifso_analytics_req',{an_action:'decrementField',postid:ifso_last_viewed_trigger.triggerid, versionid:ifso_last_viewed_trigger.versionid, field:'bounce'}, function(){
316                deleteCookie('ifso_bounce')
317            });
318        }
319		window.addEventListener('beforeunload',function(e){
320		    if(!getCookie('ifso_bounce')){
321				createCookie('ifso_bounce');
322                sendAjaxReq('ifso_analytics_req',{an_action:'incrementField',postid:ifso_last_viewed_trigger.triggerid, versionid:ifso_last_viewed_trigger.versionid, field:'bounce'}, function(){});
323            }
324
325		});*/
326	});
327})( jQuery );
328

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.