PageSourceSearch

https://www.allotment-garden.org/shop/wp-content/plugins/maxbuttons-pro/js/maxbuttons-pro-front.js?ver=9.8.0

js allotment-garden.org collected 2026-10-01 11:43:15 UTC 6,744 bytes, 316 lines download raw bytes

1
2jQuery(document).ready(function($){
3
4	var viewCookieName = 'mb-views';
5	var viewCookie;
6
7	function mbProInit()
8	{
9		viewCookie = mbGetCookie(viewCookieName);
10
11		elements = document.querySelectorAll('.maxbutton[data-mbga],[data-maxbuttoncounter] ');
12
13		elements.forEach(function (domObj)
14		{
15			 domObj.addEventListener('click', mbClickEvent);
16		});
17
18
19		var buttons = document.querySelectorAll('[data-maxbuttoncounter]');
20		if (buttons.length > 0)
21		{
22			 values = [];
23
24			 buttons.forEach( function (el, index, listObj) {
25				 		 values.push(el) // mbTrackButtonLoad(value);
26			 });
27
28			 mbTrackButtonLoad(values);
29		}
30
31	}
32
33	function mbTrackButtonLoad(values)
34	{
35			var buttonData = [];
36			var postData = {};
37
38			postData.plugin_action = 'addView';
39			postData.action = 'mbcounter';
40
41			for (i = 0; i < values.length; i++)
42			{
43				  var element = values[i];
44					var data = getPageData(element);
45					var page_code = data.page_code;
46
47					if (element.offsetParent == null)
48					{
49						 MBonVisible(element, mbTrackButtonLoad);
50						 continue;
51					}
52
53					if (! data.page_code)
54					{
55						 console.error('Issue with PageCode - not recording');
56						 continue;
57					}
58
59
60				  if (viewCookie.indexOf(page_code) > -1)
61					{
62						 continue;
63					}
64
65					buttonData.push(data);
66
67			}
68
69			if (buttonData.length == 0)
70				return;  // no need for calls
71
72			postData.buttonData = buttonData;
73
74					 	var xhr = $.post(maxButtonsFront.ajaxURL, postData)
75						.done(function()
76						{
77							var cookieSave = false;
78
79							for (i = 0; i < postData.buttonData.length; i++)
80							{
81								page_code = postData.buttonData[i].page_code;
82
83								if (viewCookie.indexOf(page_code) == -1)
84								{
85				 					viewCookie.push(page_code);
86									cookieSave = true;
87								}
88							}
89							// Save here, because of async hobbies of Ajax. If any issues arise around double-sending, it's here.
90							if (cookieSave)
91							{
92
93								mbSetCookie(viewCookieName, viewCookie);
94							}
95
96						})
97						.fail(function()
98						{
99								console.error('Button AddView failed to send', postData );
100						});
101	}
102
103	function mbClickEvent(event)
104	{
105		 var target = event.target;
106
107		 if (! target.classList.contains('maxbutton'))
108		 {
109			  var i = 0;
110				while(!target.classList.contains('maxbutton'))
111				{
112					 var target = target.parentElement;
113					 i++;
114					 if (i > 5)
115					 {
116						 console.error('Unexpected click event without parent maxbutton container');
117						 break;
118					 }
119				}
120		 }
121
122 		 if (target.getAttribute('download') == null)
123 		 {
124 		 	 event.preventDefault();
125 		 }
126
127		 if (typeof target.dataset.maxbuttoncounter !== 'undefined')
128		 {
129		 	 mbTrackClick(target, target.dataset.maxbuttoncounter);
130		 }
131		if  (typeof target.dataset.mbga !== 'undefined')
132		{
133			  mbTrackGAEvent(target, target.dataset.mbga);
134		}
135
136 	   var href = target.href;
137		 var linkTarget = target.getAttribute('target');
138
139		 if (target.getAttribute('download') !== null)
140		 {
141			  return true;
142			  // doing nothing should trigger the download as it should.
143		 }
144		 else
145		 {
146		   	openLink(href, linkTarget);
147		 }
148
149	}
150
151	function mbTrackClick(target, data)
152	{
153		var buttonData = [];
154		var postData = {};
155
156		postData.plugin_action = 'addClick';
157		postData.action = 'mbcounter';
158
159  	var data = getPageData(target);
160		buttonData.push(data);
161		postData.buttonData = buttonData;
162
163		data.plugin_action = 'addClick';
164
165		 $.ajax(maxButtonsFront.ajaxURL,
166			 	{
167					data: postData,
168					async: false,
169					type: 'POST'
170				}
171		 );
172	}
173
174	function getPageData(button)
175	{
176			var data = {};
177
178			var counter = page = false;
179			if (button.dataset.maxbuttoncounter)
180				 counter = JSON.parse(button.dataset.maxbuttoncounter);
181			if (button.dataset.maxbuttonpage)
182				 page = JSON.parse(button.dataset.maxbuttonpage);
183
184			if (button.dataset.notexisting)
185				 existing = button.dataset.nonexisting;
186
187			if (counter !== false && page !== false)
188			{
189					data.button_id = counter.button_id;
190					data.check = counter.check;
191
192					var url = counter.url;
193					if (url.indexOf('javascript') >= 0)
194					{
195						 if (url.indexOf('void') >= 0)
196						 {
197							   url = 'empty';
198						 }
199					}
200
201					data.url = url;
202
203				  data.page_id = page.id;
204					data.page_type = page.type;
205
206					// sort of the unique identifier.
207					data.page_code = "" + data.button_id + data.page_type + data.page_id + data.check;
208			}
209
210			return data;
211	}
212
213	function mbGetCookie(cName) {
214			var c = Cookies.get(cName);
215			if (c)
216				return JSON.parse(c);
217			else
218				return [];
219	}
220
221	function mbSetCookie(cName, data)
222	{
223		  Cookies.set(cName, JSON.stringify(data));
224
225	}
226
227	function openLink(href, target)
228	{
229				if(href)
230				{
231					if (typeof target !== 'undefined' && target != '' && target !== null)
232						window.open(href, target);
233					else
234						window.location = href;
235				}
236	}
237
238	function mbTrackGAEvent(target, rawData) //mbTrackEvent(event,id, cat, action, label, value, noninteraction)
239	{
240		var data = JSON.parse(rawData);
241
242	 	var cat = data.cat;
243	 	var action = data.action;
244	 	var label = data.label;
245	 	var value = data.value;
246	 	var noninteraction = data.noninteraction;
247
248 		var linkTarget = $(this).prop('target');
249		var tracked = false;
250
251		if (typeof gtag == 'function')
252		{
253				gtag('event', action, {
254			  	'event_category': cat,
255			  	'event_label': label,
256			  	'value': value,
257					'noninteraction' : noninteraction,
258			});
259			tracked = true;
260
261		}
262		else if (typeof ga == 'function')
263		{
264			if (typeof dataLayer == 'object') // GTM
265			{
266
267				dataLayer.push ({ 'event': 'event',
268					'eventCategory': cat,
269					    'eventAction': action,
270					    'eventLabel': label,
271				});
272				tracked = true;
273			}
274			else
275			{
276		       ga(function (tracker)
277		   	   {
278		            tracker.send('event', cat, action, label,value, {'nonInteraction' : noninteraction} );
279		   	   });
280					 tracked = true;
281			}
282		}
283		else if (typeof __gaTracker == 'function')  // yoast analytics uses another var.
284		{
285			__gaTracker('send', 'event', cat, action, label, value, {'nonInteraction' : noninteraction} );
286			tracked = true;
287
288		}
289		else if (typeof _gaq == 'object') // GA classic
290		{
291			_gaq.push(['_trackEvent', cat, action, label, value, noninteraction]);
292			tracked = true;
293		}
294
295		if (tracked === false)
296		{
297			 console.error('Maxbuttons PRO: No Google Analytics tracker found, not recording click. This is caused by not having the tracker code loaded or browser has tracker blockers');
298		}
299  } // function
300
301
302	function MBonVisible(element, callback) {
303		new IntersectionObserver(function (entries, observer) {
304			entries.forEach(function (entry) {
305				if (entry.intersectionRatio > 0) {
306					callback([element]);
307					observer.disconnect();
308				}
309			});
310		}).observe(element);
311	}
312
313
314
315	mbProInit();
316}); // jquery

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.