PageSourceSearch

https://www.edtm.com/catalog/view/javascript/common.js

js edtm.com collected 2026-09-29 15:38:52 UTC 17,179 bytes, 561 lines download raw bytes

1function getURLVar(key) {
2	var value = [];
3
4	var query = String(document.location).split('?');
5
6	if (query[1]) {
7		var part = query[1].split('&');
8
9		for (i = 0; i < part.length; i++) {
10			var data = part[i].split('=');
11
12			if (data[0] && data[1]) {
13				value[data[0]] = data[1];
14			}
15		}
16
17		if (value[key]) {
18			return value[key];
19		} else {
20			return '';
21		}
22	}
23}
24
25function searchCourses() {
26    var q = document.getElementById('edtm-course-search').value.trim();
27    if (q) {
28        window.location.href =
29            'https://edtm-training.thinkific.com/collections?q=' +
30            encodeURIComponent(q);
31    }
32}
33
34$(document).ready(function() {
35	$('#edtm-course-search').autocomplete({
36	source: function(request, response) {
37	$.ajax({
38	url: 'index.php?route=api/course_search&q=' + encodeURIComponent(request),
39	dataType: 'json',
40	success: function(json) {
41	response(json);
42	}
43	});
44	},
45	 
46	select: function(item) {
47	window.location.href = item.value;
48	}
49	});
50	
51	if ($("input[name='product_id']").val()==129) {
52	$("input[name^='option[']").on('change',function(e) {
53		if ($("input[name^='option[']:checked").length>0) {
54			$('#button-cart').css('display','none');
55		} else {
56			$('#button-cart').css('display','block');
57		}
58	});
59	}
60	// Highlight any found errors
61	$('.text-danger').each(function() {
62		var element = $(this).parent().parent();
63
64		if (element.hasClass('form-group')) {
65			element.addClass('has-error');
66		}
67	});
68
69	// Currency
70	$('#form-currency .currency-select').on('click', function(e) {
71		e.preventDefault();
72
73		$('#form-currency input[name=\'code\']').val($(this).attr('name'));
74
75		$('#form-currency').submit();
76	});
77
78	// Language
79	$('#form-language .language-select').on('click', function(e) {
80		e.preventDefault();
81
82		$('#form-language input[name=\'code\']').val($(this).attr('name'));
83
84		$('#form-language').submit();
85	});
86
87	/* Search */
88	$('#search input[name=\'search\']').parent().find('button').on('click', function() {
89		var url = $('base').attr('href') + 'index.php?route=product/search';
90
91		var value = $('header #search input[name=\'search\']').val();
92
93		if (value) {
94			url += '&search=' + encodeURIComponent(value);
95		}
96
97		location = url;
98	});
99
100	$('#search input[name=\'search\']').on('keydown', function(e) {
101		if (e.keyCode == 13) {
102			$('header #search input[name=\'search\']').parent().find('button').trigger('click');
103		}
104	});
105
106	// Menu
107	$('#menu .dropdown-menu').each(function() {
108		var menu = $('#menu').offset();
109		var dropdown = $(this).parent().offset();
110
111		var i = (dropdown.left + $(this).outerWidth()) - (menu.left + $('#menu').outerWidth());
112
113		if (i > 0) {
114			$(this).css('margin-left', '-' + (i + 10) + 'px');
115		}
116	});
117
118	// Product List
119	$('#list-view').click(function() {
120		$('#content .product-grid > .clearfix').remove();
121
122		$('#content .row > .product-grid').attr('class', 'product-layout product-list col-xs-12');
123		$('#grid-view').removeClass('active');
124		$('#list-view').addClass('active');
125
126		localStorage.setItem('display', 'list');
127	});
128
129	// Product Grid
130	$('#grid-view').click(function() {
131		// What a shame bootstrap does not take into account dynamically loaded columns
132		var cols = $('#column-right, #column-left').length;
133
134		if (cols == 2) {
135			$('#content .product-list').attr('class', 'product-layout product-grid col-lg-6 col-md-6 col-sm-12 col-xs-12');
136		} else if (cols == 1) {
137			$('#content .product-list').attr('class', 'product-layout product-grid col-lg-4 col-md-4 col-sm-6 col-xs-12');
138		} else {
139			$('#content .product-list').attr('class', 'product-layout product-grid col-lg-3 col-md-3 col-sm-6 col-xs-12');
140		}
141
142		$('#list-view').removeClass('active');
143		$('#grid-view').addClass('active');
144
145		localStorage.setItem('display', 'grid');
146	});
147
148	if (localStorage.getItem('display') == 'list') {
149		$('#list-view').trigger('click');
150		$('#list-view').addClass('active');
151	} else {
152		$('#grid-view').trigger('click');
153		$('#grid-view').addClass('active');
154	}
155
156	// Checkout
157	$(document).on('keydown', '#collapse-checkout-option input[name=\'email\'], #collapse-checkout-option input[name=\'password\']', function(e) {
158		if (e.keyCode == 13) {
159			$('#collapse-checkout-option #button-login').trigger('click');
160		}
161	});
162
163	// tooltips on hover
164	$('[data-toggle=\'tooltip\']').tooltip({container: 'body'});
165
166	// Makes tooltips work on ajax generated content
167	$(document).ajaxStop(function() {
168		$('[data-toggle=\'tooltip\']').tooltip({container: 'body'});
169	});
170	var wwidth = $( window ).width();
171	if(wwidth < 768){
172       $(".nav > li[class='dropdown'] > a").each(function() {
173		$(this).removeAttr('data-hover');  
174		$(this).attr('data-toggle','dropdown');   
175		});
176	}
177});
178
179// Cart add remove functions
180var cart = {
181	'add': function(product_id, quantity) {
182		$.ajax({
183			url: 'index.php?route=checkout/cart/add',
184			type: 'post',
185			data: 'product_id=' + product_id + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1),
186			dataType: 'json',
187			beforeSend: function() {
188				$('#cart > button').button('loading');
189			},
190			complete: function() {
191				$('#cart > button').button('reset');
192			},
193			success: function(json) {
194				//$('.alert-dismissible, .text-danger').remove();
195
196				if (json['redirect']) {
197					location = json['redirect'];
198				}
199
200				if (json['success']) {
201					if (document.getElementById('common-home')) {
202					var style_segment = ' style="position:relative;top:10px;margin-left:12px"'; 
203                    $('#common-home').before('<div class="alert alert-success alert-dismissible"'+style_segment+'><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-bs-dismiss="alert"></button></div>');					
204					} else if ($('#product-category.has-banner').length>0) {
205					$('#column-left').after('<div class="col-md-9 col-xs-9 alert alert-success" style="float:left;display:inline-block;padding-left:calc(var(--bs-gutter-x) * .5);padding-right:calc(var(--bs-gutter-x) * .5)"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');				
206					} else {
207					$('#content').parent().before('<div class="alert alert-success" style="margin-left:12px"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');
208					}
209					// Need to set timeout otherwise it wont update the total
210					setTimeout(function () {
211						$('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '</span>');
212						$('.ronixa-cart-number').html('<span>' + json['total'].split(' item')[0] + '</span>');
213						$('.ronixa-price-amount').html(json['total'].split('- ')[1].split('.')[0]);
214					}, 100);
215					if ($('#product-category.has-banner').length>0) {
216					$('html, body').animate({ scrollTop: ($('#sorts').offset().top - 80) }, 'slow');
217					} else {
218					$('html, body').animate({ scrollTop: 0 }, 'slow');	
219					}
220					$('#cart > ul').load('index.php?route=common/cart/info ul li');
221				}
222			},
223			error: function(xhr, ajaxOptions, thrownError) {
224				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
225			}
226		});
227	},
228	'update': function(key, quantity) {
229		$.ajax({
230			url: 'index.php?route=checkout/cart/edit',
231			type: 'post',
232			data: 'key=' + key + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1),
233			dataType: 'json',
234			beforeSend: function() {
235				$('#cart > button').button('loading');
236			},
237			complete: function() {
238				$('#cart > button').button('reset');
239			},
240			success: function(json) {
241				// Need to set timeout otherwise it wont update the total
242				setTimeout(function () {
243					$('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '</span>');
244					$('.ronixa-cart-number').html('<span>' + json['total'].split(' item')[0] + '</span>');
245					$('.ronixa-price-amount').html(json['total'].split('- ')[1].split('.')[0]);
246				}, 100);
247
248				if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
249					location = 'index.php?route=checkout/cart';
250				} else {
251					$('#cart > ul').load('index.php?route=common/cart/info ul li');
252				}
253			},
254			error: function(xhr, ajaxOptions, thrownError) {
255				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
256			}
257		});
258	},
259	'remove': function(key) {
260		$.ajax({
261			url: 'index.php?route=checkout/cart/remove',
262			type: 'post',
263			data: 'key=' + key,
264			dataType: 'json',
265			beforeSend: function() {
266				$('#cart > button').button('loading');
267			},
268			complete: function() {
269				$('#cart > button').button('reset');
270			},
271			success: function(json) {
272				// Need to set timeout otherwise it wont update the total
273				setTimeout(function () {
274					$('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '</span>');
275					$('.ronixa-cart-number').html('<span>' + json['total'].split(' item')[0] + '</span>');
276					$('.ronixa-price-amount').html(json['total'].split('- ')[1].split('.')[0]);
277				}, 100);
278
279				if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
280					location = 'index.php?route=checkout/cart';
281				} else {
282					$('#cart > ul').load('index.php?route=common/cart/info ul li');
283				}
284			},
285			error: function(xhr, ajaxOptions, thrownError) {
286				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
287			}
288		});
289	}
290}
291
292var voucher = {
293	'add': function() {
294
295	},
296	'remove': function(key) {
297		$.ajax({
298			url: 'index.php?route=checkout/cart/remove',
299			type: 'post',
300			data: 'key=' + key,
301			dataType: 'json',
302			beforeSend: function() {
303				$('#cart > button').button('loading');
304			},
305			complete: function() {
306				$('#cart > button').button('reset');
307			},
308			success: function(json) {
309				// Need to set timeout otherwise it wont update the total
310				setTimeout(function () {
311					$('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '</span>');
312					$('.ronixa-cart-number').html('<span>' + json['total'].split(' item')[0] + '</span>');
313				}, 100);
314
315				if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
316					location = 'index.php?route=checkout/cart';
317				} else {
318					$('#cart > ul').load('index.php?route=common/cart/info ul li');
319				}
320			},
321			error: function(xhr, ajaxOptions, thrownError) {
322				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
323			}
324		});
325	}
326}
327
328var wishlist = {
329	'add': function(product_id) {
330		$.ajax({
331			url: 'index.php?route=account/wishlist/add',
332			type: 'post',
333			data: 'product_id=' + product_id,
334			dataType: 'json',
335			success: function(json) {
336				//$('.alert-dismissible').remove();
337
338				if (json['redirect']) {
339					location = json['redirect'];
340				}
341
342				if (json['success']) {
343					if ($('#product-category.has-banner').length>0) {
344					$('#column-left').after('<div class="col-md-9 col-xs-9 alert alert-success" style="float:left;display:inline-block;padding-left:calc(var(--bs-gutter-x) * .5);padding-right:calc(var(--bs-gutter-x) * .5)"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');				
345					} else {
346					$('#content').parent().before('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');
347					}
348				}
349
350				$('#wishlist-total span').html(json['total']);
351				$('#wishlist-total').attr('title', json['total']);
352					if ($('#product-category.has-banner').length>0) {
353					$('html, body').animate({ scrollTop: ($('#sorts').offset().top - 80) }, 'slow');
354					} else {
355					$('html, body').animate({ scrollTop: 0 }, 'slow');	
356					}
357			},
358			error: function(xhr, ajaxOptions, thrownError) {
359				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
360			}
361		});
362	},
363	'remove': function() {
364
365	}
366}
367
368var compare = {
369	'add': function(product_id) {
370		$.ajax({
371			url: 'index.php?route=product/compare/add',
372			type: 'post',
373			data: 'product_id=' + product_id,
374			dataType: 'json',
375			success: function(json) {
376				$('.alert-dismissible').remove();
377
378				if (json['success']) {
379					if ($('#product-category.has-banner').length>0) {
380					$('#column-left').after('<div class="col-md-9 col-xs-9 alert alert-success" style="float:left;display:inline-block;padding-left:calc(var(--bs-gutter-x) * .5);padding-right:calc(var(--bs-gutter-x) * .5)"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');				
381					} else {
382					$('#content').parent().before('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');
383					}
384
385					$('#compare-total').html(json['total']);
386
387					if ($('#product-category.has-banner').length>0) {
388					$('html, body').animate({ scrollTop: ($('#sorts').offset().top - 80) }, 'slow');
389					} else {
390					$('html, body').animate({ scrollTop: 0 }, 'slow');	
391					}
392				}
393			},
394			error: function(xhr, ajaxOptions, thrownError) {
395				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
396			}
397		});
398	},
399	'remove': function() {
400
401	}
402}
403
404/* Agree to Terms */
405$(document).delegate('.agree', 'click', function(e) {
406	e.preventDefault();
407
408	$('#modal-agree').remove();
409
410	var element = this;
411
412	$.ajax({
413		url: $(element).attr('href'),
414		type: 'get',
415		dataType: 'html',
416		success: function(data) {
417			html  = '<div id="modal-agree" class="modal">';
418			html += '  <div class="modal-dialog">';
419			html += '    <div class="modal-content">';
420			html += '      <div class="modal-header">';
421			html += '        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>';
422			html += '        <h4 class="modal-title">' + $(element).text() + '</h4>';
423			html += '      </div>';
424			html += '      <div class="modal-body">' + data + '</div>';
425			html += '    </div>';
426			html += '  </div>';
427			html += '</div>';
428
429			$('body').append(html);
430
431			$('#modal-agree').modal('show');
432		}
433	});
434});
435
436// Autocomplete */
437(function($) {
438	$.fn.autocomplete = function(option) {
439		return this.each(function() {
440			this.timer = null;
441			this.items = new Array();
442
443			$.extend(this, option);
444
445			$(this).attr('autocomplete', 'off');
446
447			// Focus
448			$(this).on('focus', function() {
449				this.request();
450			});
451
452			// Blur
453			$(this).on('blur', function() {
454				setTimeout(function(object) {
455					object.hide();
456				}, 200, this);
457			});
458
459			// Keydown
460			$(this).on('keydown', function(event) {
461				switch(event.keyCode) {
462					case 27: // escape
463						this.hide();
464						break;
465					default:
466						this.request();
467						break;
468				}
469			});
470
471			// Click
472			this.click = function(event) {
473				event.preventDefault();
474
475				value = $(event.target).parent().attr('data-value');
476
477				if (value && this.items[value]) {
478					this.select(this.items[value]);
479				}
480			}
481
482			// Show
483			this.show = function() {
484				var pos = $(this).position();
485
486				$(this).siblings('ul.dropdown-menu').css({
487					top: pos.top + $(this).outerHeight(),
488					left: pos.left
489				});
490
491				$(this).siblings('ul.dropdown-menu').show();
492			}
493
494			// Hide
495			this.hide = function() {
496				$(this).siblings('ul.dropdown-menu').hide();
497			}
498
499			// Request
500			this.request = function() {
501				clearTimeout(this.timer);
502
503				this.timer = setTimeout(function(object) {
504					object.source($(object).val(), $.proxy(object.response, object));
505				}, 200, this);
506			}
507
508			// Response
509			this.response = function(json) {
510				html = '';
511
512				if (json.length) {
513					for (i = 0; i < json.length; i++) {
514						this.items[json[i]['value']] = json[i];
515					}
516
517					for (i = 0; i < json.length; i++) {
518						if (!json[i]['category']) {
519							html += '<li data-value="' + json[i]['value'] + '"><a href="#">' + json[i]['label'] + '</a></li>';
520						}
521					}
522
523					// Get all the ones with a categories
524					var category = new Array();
525
526					for (i = 0; i < json.length; i++) {
527						if (json[i]['category']) {
528							if (!category[json[i]['category']]) {
529								category[json[i]['category']] = new Array();
530								category[json[i]['category']]['name'] = json[i]['category'];
531								category[json[i]['category']]['item'] = new Array();
532							}
533
534							category[json[i]['category']]['item'].push(json[i]);
535						}
536					}
537
538					for (i in category) {
539						html += '<li class="dropdown-header">' + category[i]['name'] + '</li>';
540
541						for (j = 0; j < category[i]['item'].length; j++) {
542							html += '<li data-value="' + category[i]['item'][j]['value'] + '"><a href="#">&nbsp;&nbsp;&nbsp;' + category[i]['item'][j]['label'] + '</a></li>';
543						}
544					}
545				}
546
547				if (html) {
548					this.show();
549				} else {
550					this.hide();
551				}
552
553				$(this).siblings('ul.dropdown-menu').html(html);
554			}
555
556			$(this).after('<ul class="dropdown-menu"></ul>');
557			$(this).siblings('ul.dropdown-menu').delegate('a', 'click', $.proxy(this.click, this));
558
559		});
560	}
561})(window.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.