PageSourceSearch

https://nangs.org/modules/mod_jak2filter/assets/js/jak2filter.js?v=2

js nangs.org collected 2026-09-24 18:56:52 UTC 17,987 bytes, 584 lines download raw bytes

1/**
2 * ------------------------------------------------------------------------
3 * JA K2 Filter Module for J25 & J3.4
4 * ------------------------------------------------------------------------
5 * Copyright (C) 2004-2011 J.O.O.M Solutions Co., Ltd. All Rights Reserved.
6 * @license - GNU/GPL, http://www.gnu.org/licenses/gpl.html
7 * Author: J.O.O.M Solutions Co., Ltd
8 * Websites: http://www.joomlart.com - http://www.joomlancers.com
9 * ------------------------------------------------------------------------
10 */
11function jak2DisplayExtraFields (moduleid, obj, selected_group) {
12	var group = obj.attr('rel') ? obj.attr('rel') : '';
13	var value = obj.val();
14	var parent = obj.parents('.ja-k2filter');
15	var parentid = parent.attr('id');
16	
17	jQuery('#'+parentid+' .exfield').each(function(){
18		var item = jQuery(this);
19		var magicid = jQuery('#m'+item.attr('id'));
20		if(magicid.length){
21			if(item.hasClass('opened')) {
22				item.removeClass('opened');
23				item.addClass('closed');
24				magicid.hide();
25			}
26		}
27	});
28
29	if((value != 0 && group != '') || selected_group) {
30		if(group == '') {
31			group = selected_group;
32		}
33		jQuery('#'+parentid).find('.heading-group').each(function() {
34			var item = jQuery(this);
35			if(item.hasClass('heading-group-'+group)) {
36				item.removeClass('ui-accordion-disabled ui-state-disabled');
37				if(!item.hasClass('ui-state-active')) {
38					var accor = jQuery('#ja-extra-field-accordion-'+moduleid);
39					accor.accordion('activate', item);
40				}
41			} else {
42				//clear value of extra fields in group that not associated with selected category
43				item.addClass('ui-accordion-disabled ui-state-disabled');
44				jaK2Reset(moduleid, item.next('.ui-accordion-content'), false);
45			}
46		});
47	} else {
48		jQuery('#'+parentid).find('.heading-group').removeClass('ui-accordion-disabled ui-state-disabled');
49	}
50}
51
52function jaK2Reset(moduleId, container, submitform)
53{
54	//var form = jQuery('#'+formId);
55	if(typeof(container) == 'string') {
56		container = jQuery('#'+container);
57	}
58	//reset input
59	container.find('input[type=text], textarea').val('');
60
61	//radio, checkbox
62	container.find(':checked').each(function(){
63		jQuery(this).removeAttr('checked');
64	});
65
66	//reset magic select
67	container.find('.ja-magic-select ul li').each(function()
68	{
69		jQuery(this).removeClass('selected');
70	});
71	container.find('.ja-magic-select-container').each(function()
72	{
73		jQuery(this).html('');
74	});
75
76	// reset depend filter.
77	container.find('select').each(function() {
78		var item = jQuery(this);
79		var multiple = item.attr('multiple');
80		var fval = '';
81		if (!multiple) {
82			fval = item.context.options[0].value;
83		}
84		item.val(fval).trigger("liszt:updated");
85	});
86	
87	container.find('input.jak2dependarray, input.jak2dependtxt').val('');
88
89	//reset range slider
90	container.find('[name$="_jacheck"]').each(function() {
91		var el = jQuery(this);
92		var sliders = jQuery('#slider_'+el.attr('id').replace('_jacheck', ''));
93		if(sliders) {
94			var val = this.value.split('|');
95			sliders.slider('values', 0, val[0]);
96			sliders.slider('values', 1, val[1]);
97		}
98	});
99
100	//hide custom date ranger box
101	container.find('#ja-custom-daterange-'+moduleId).hide();
102
103	//remove order subclass
104	container.find('.fssorts').remove();
105
106	//submit form?
107	if(submitform) {
108		if(container.prop('tagName').toLowerCase() != 'form') {
109			var form = container.parents('form');
110		} else {
111			var form = container;
112		}
113		var autofilter = form.find('[name="btnSubmit"]').length;
114		if(!autofilter) {
115			if(typeof(form.submit) == 'function') {
116				form.trigger('filter.submit');
117			}
118		}
119	}
120}
121
122function jaMagicInit(lid, fid) {
123
124	jQuery('#'+lid+' li').each(function(idx, item){
125		if(jQuery(item).hasClass('selected')) {
126			jaMagicAddElement(lid, fid, jQuery(item).html(), jQuery(item).attr('rel'));
127		}
128	});
129
130	jQuery('#'+lid+' li.active').each(function(idx, item){
131		jQuery(item).on('click', function() {
132			var elm = jQuery(this);
133			var id = elm.attr('rel');
134			if(!id) return;
135			
136			if(elm.hasClass('selected')) {
137				elm.removeClass('selected');
138				jQuery('#'+lid+'-'+id).remove();
139			} else {
140				elm.addClass('selected');
141				jaMagicAddElement(lid, fid, elm.html(), id);
142			}
143			var autofilter = jQuery('#'+lid).attr('data-autofilter');
144			if(autofilter == 1) {
145				jQuery('#'+lid).parents('form').trigger('filter.submit');
146			}
147		});
148		
149	});
150}
151
152function jaMagicAddElement(lid, fid, label, id) {
153	var container = jQuery('#'+lid+'-container');
154	var elm = [
155		'<span id="'+lid+'-'+id+'">',
156			label + '<input type="hidden" name="'+fid+'[]" value="'+id+'" />',
157		'</span>'
158	].join('');
159	
160	var elmRemove = '<span rel="'+id+'" class="remove" title="Remove"></span>';
161
162	elm = jQuery(elm);
163	elmRemove = jQuery(elmRemove);
164
165	elmRemove.on('click', function() {
166		var lid = jQuery(this).parent().attr('id').replace(/^((?:[a-z0-9_]+\-){2}[a-z0-9_]*).*/, '$1');
167		jQuery('#'+lid+' li[rel="'+jQuery(this).attr('rel')+'"]').removeClass('selected');
168		jQuery(this).parent().remove();
169		var autofilter = jQuery('#'+lid).attr('data-autofilter');
170		if(autofilter == 1) {
171			jQuery('#'+lid).parents('form').trigger('filter.submit');
172		}
173	});
174
175	elm.append(elmRemove);
176	container.append(elm);
177}
178
179function jaMagicSelect(controller, lid) {
180	controller = jQuery(controller);
181	if(controller.hasClass('opened')) {
182		controller.removeClass('opened');
183		controller.addClass('closed');
184		jQuery('#'+lid).hide();
185	} else {
186		controller.removeClass('closed');
187		controller.addClass('opened');
188		jQuery('#'+lid).show();
189	}
190}
191function jaMagicSelectClose(controller, lid) {
192	controller = jQuery(controller);
193	var controllerparent = jQuery('#'+lid).parent().find('.select');
194	if(controllerparent.hasClass('opened')) {
195		controllerparent.removeClass('opened');
196		controllerparent.addClass('closed');
197	} else {
198		controllerparent.removeClass('closed');
199		controllerparent.addClass('opened');
200	}
201	jQuery('#'+lid).hide();	
202}
203
204function jak2AjaxSubmit(form, K2SitePath, cache) {
205	var formid = jQuery(form).attr('id');
206	//if Container K2 does not exist, submit form to redirect to K2 Filter result page
207	if(jQuery('#k2Container').length) {
208		jak2AjaxStart();
209		var data = jQuery(form).serialize();
210		if (cache[data]) {
211			jak2AjaxHandle(cache[data], K2SitePath, cache, formid);
212		} else {
213			jQuery.ajax({
214				type: "POST",
215				url: jQuery(form).attr('action'),
216				data: data,
217				success: function(text){
218					cache[data] = text;
219					jak2AjaxHandle(text, K2SitePath, cache, formid);
220				}
221			});
222		}
223	} else {
224		jQuery(form).find('input[name="tmpl"]').val('');
225		jQuery(form).submit();
226	}
227}
228
229function jak2AjaxStart() {
230	if(!jQuery('#jak2-loading').length) {
231		jQuery('body').append('<div id="jak2-loading">Loading</div>');
232	}
233	jQuery('#jak2-loading').css({'display': 'block'});
234}
235
236function jak2GetUrlSharing(form, updateLocation){
237	var params = jQuery(form).serialize();
238	params = params.replace('task=search&', 'task=shareurl&');
239	params = params.replace('&tmpl=component', '');
240	jQuery.ajax({
241		type: "POST",
242		url: jQuery(form).attr('action'),
243		data: params,
244		success: function(shareurl){
245			if (updateLocation) {
246				history.replaceState({}, null, shareurl);
247			} else {
248				jQuery(form).find('.jak2shareurl a').attr('href', shareurl);
249			}
250		}
251	});
252}
253
254function jak2AjaxPagination(container, K2SitePath, cache) {
255	var pages = container.find('ul.pagination-list li a');
256	if(!pages.length) {
257		pages = container.find('.k2Pagination ul li a');
258	}
259	pages.each(function(){
260		jQuery(this).click(function(event) {
261			event.preventDefault();
262			jak2AjaxStart();
263			var url = jQuery(this).attr('href');
264			if (!url.match(/tmpl=component/)) {
265				url = url + '&tmpl=component';
266			}
267
268			var prop = url.replace('&tmpl=component', '');
269			if (cache[prop]) {
270				jak2AjaxHandle(cache[prop], K2SitePath, cache);	
271			} else {
272				jQuery.ajax({
273					type: "GET",
274					url: url,
275					success: function(text){
276						cache[prop] = text;
277						jak2AjaxHandle(text, K2SitePath, cache);
278					}
279				});
280			}
281			return false;
282		});
283	});
284}
285
286function jak2Highlight(container, searchword) {
287	if(typeof(jQuery.fn.highlight) == 'function' && searchword != undefined) {
288		searchword = searchword.replace(/[<>#\\]/, '');
289		//remove excluded words
290		searchword = searchword.replace(/\-\s*(intitle\:|intext\:|inmetadata\:|inmedia\:|inall\:)?\s*("[^"]"|[^\s]+)/g,'');
291		//remove special keywords
292		searchword = searchword.replace(/(intitle\:|intext\:|inmetadata\:|inmedia\:|inall\:)/g,'');
293
294		var pattern = /(?:"[^"]+"|[^\s]+)/gi;
295		var matches = searchword.match(pattern);
296		if(matches) {
297			for(i=0; i<matches.length; i++) {
298				var word = matches[i].replace(/"/g, '');
299				if(word != '' && word != 'OR') {
300					container.highlight(word);
301				}
302			}
303		}
304	}
305}
306function jak2AjaxHandle(text, K2SitePath, cache, formid) {
307	var container = jQuery('#k2Container');
308	var message_container = jQuery('#system-message-container');
309	var html = jQuery('<div>
309' + text + '</div>');
310	var content = html.find('#k2Container');
311	var content_message = html.find('#system-message-container');
312
313	// update module counter by ajax.
314	if (formid) {
315		var moduleContent = html.find('#ja-module-content').text();
316		if (moduleContent) {
317			var moduleHtml = '<div>' + JSON.parse(moduleContent).content + '</div>';
318			var $form = jQuery('#' + formid);
319			var $resultForm = jQuery(moduleHtml).find('#'+formid);
320			var $resultRadio = $resultForm.find('input[type=radio].exfield');
321			var $resultCheckbox = $resultForm.find('input[type=checkbox].exfield');
322			var $resultInputs = $resultRadio.add($resultCheckbox);
323
324			$resultInputs.each(function(idx, elm) {
325				var $input = jQuery(elm);
326				var id = $input.attr('id');
327				var $inputText = $input.siblings('span.input-text');
328				var text = $inputText.text();
329				
330				$form.find('input#' + id).siblings('span.input-text').text(text);
331			});
332
333			var $resultMagicItems = $resultForm.find('ul li.magic-item');
334			
335			$resultMagicItems.each(function(idx, elm) {
336				var $elm = jQuery(elm);
337				var id = $elm.attr('id');
338				var text = $elm.text();
339
340				$form.find('ul li#'+id).text(text);
341			});
342
343			var $resultSelects = $resultForm.find('select.select-filter');
344
345			$resultSelects.each(function(idx, elm) {
346				var $elm = jQuery(elm);
347				var id = $elm.attr('id');
348				var $resultOptions = $elm.find('option');
349				var $select = $form.find('select#' + id);
350
351				$resultOptions.each(function(i, opt) {
352					var $opt = jQuery(opt);
353					var rVal = $opt.val();
354					var text = $opt.text();
355					var $option = $select.find('option[value="'+rVal+'"]');
356
357					if ($option.length) {
358						$option.text(text);
359					}
360				});
361
362				$select.trigger('liszt:updated');
363			});
364		}
365	}
366
367	if(content.length) {
368	    // update item list content
369		container.html(content.html());
370		// update system message if exists
371		message_container.html(content_message.html());
372		//paging
373		jak2AjaxPagination(container, K2SitePath, cache);
374
375		//rating
376		container.find('.itemRatingForm a').click(function(event){
377			event.preventDefault();
378			var itemID = jQuery(this).attr('data-id');
379			var log = jQuery('#itemRatingLog' + itemID).empty().addClass('formLogLoading');
380			var rating = jQuery(this).html();
381			jQuery.ajax({
382				url: K2SitePath+"index.php?option=com_k2&view=item&task=vote&format=raw&user_rating=" + rating + "&itemID=" + itemID,
383				type: 'get',
384				success: function(response){
385					log.removeClass('formLogLoading');
386					log.html(response);
387					jQuery.ajax({
388						url: K2SitePath+"index.php?option=com_k2&view=item&task=getVotesPercentage&format=raw&itemID=" + itemID,
389						type: 'get',
390						success: function(percentage){
391							jQuery('#itemCurrentRating' + itemID).css('width', percentage + "%");
392							setTimeout(function(){
393								jQuery.ajax({
394									url: K2SitePath+"index.php?option=com_k2&view=item&task=getVotesNum&format=raw&itemID=" + itemID,
395									type: 'get',
396									success: function(response){
397										log.html(response);
398									}
399								});
400							}, 2000);
401						}
402					});
403				}
404			});
405		});
406
407		//highlight search team in result
408		jak2Highlight(container, jQuery('.ja-k2filter input[name="searchword"]').val());
409	} else {
410		container.html('No Item found!');
411	}
412	jQuery('#jak2-loading').css({'display': 'none'});
413	jQuery('html, body').animate({scrollTop: container.offset().top});
414}
415
416function jaK2ShowDaterange(obj, range) {
417	if(jQuery(obj).val() == 'range') {
418		jQuery(range).show();
419	} else {
420		jQuery(range).hide();
421	}
422}
423
424function createwarning ($obj) {
425	if ($obj.parents('.subclass').find('.jak2-error').length) {
426		$obj.parents('.subclass').find('.jak2-error').show();
427	} else {
428		// create if not exists.
429		$obj.parents('.subclass').find('.group-label').first().after('<div class="jak2-error">'+$required_warning+'</div>');
430	}
431}
432
433function checkrequired(params, mid) {
434	var $obj, $form, $check, $input, $warning, multiboxcheck;
435	if (params == 0) return true;
436	$form = jQuery('#'+mid);
437	var $mid = mid.replace('jak2filter-form-','');
438	if (params == 1) {
439		// at least 1 field must chosen.
440		$input = $form.find('input[type="text"], textare, select, input[type="radio"], input[type="checkbox"], .ja-magic-select-container, input[name$="jacheck"]');
441		$check = false;
442		$input.each(function(){
443			$obj = jQuery(this);
444			if ($obj.attr('type') == 'text') {
445				if (jQuery(this).val() != '') $check=true;
446				if ($obj.parents('.subclass').find('select').attr('multiple') == 'multiple') $check=false; //reset check if select multipe.
447			}
448			if ($obj.attr('type') == 'hidden') {
449				if ($obj.val() != $obj.prev().val()) $check=true;
450			}
451			if ($obj.prop("tagName") == 'SELECT') {
452				// select type
453				if ($obj[0].selectedIndex !== 0 && $obj[0].selectedIndex !== -1) $check=true;
454			}
455			if ($obj.attr('type') == 'checkbox' || $obj.attr('type') == 'radio')
456				if ($obj.is(':checked') == true) $check=true;
457			
458			if ($obj.hasClass('ja-magic-select-container')) {
459				$input = $obj.find('input[type="hidden"]');
460				if ($input.length!==0) $check=true;
461			}
462			if ($check==true) return false; // if at least 1 had value then we stop the each
463		});
464		if ($check == false) {
465			$form.find('.onewarning').show();
466		} else {
467			$form.find('.onewarning').hide();
468		}
469		return $check;
470	} else {
471		// user defined chosen.
472		$check = [];
473		for (i=0;i<params.length;i++) {
474			$obj = $form.find('input[name="'+params[i]+'_to"], input[name="'+params[i]+'_from"], input[name="'+params[i]+'"], input[name="'+params[i]+'_txt"], input[name="'+params[i]+'[]"], select[name="'+params[i]+'_txt"], select[name="'+params[i]+'"], select[name="'+params[i]+'[]"], textarea[name="'+params[i]+'"], div#mg-'+$mid+'-'+params[i]+'-container');
475			if ($obj.length == 0) continue; // continue if the field does not exists.
476			$warning = false;
477		
478			if ($obj.attr('type') == 'text') {
479				//text field, date field.
480				if ($obj.length > 1) {
481					if ($obj.eq(0).val() == '' && $obj.eq(1).val() == '') {
482						$check.push(false);
483						$warning = true;
484					}
485				} else {
486					if ($obj.val() == '') {
487						$check.push(false);
488						$warning = true;
489					}
490				}
491			}
492		
493			if ($obj.attr('type') == 'hidden') {
494				// jadepend field.
495				if ($obj.val() == '') {
496					$check.push(false);
497					$warning = true;
498				}
499			}
500		
501			if ($obj.length > 1) {
502				// checkbox, radio.
503				if ($obj.eq(0).attr('type') == 'checkbox' || $obj.eq(0).attr('type') == 'radio') {
504					multiboxcheck = false;
505					$obj.each(function(i, el){
506						if (multiboxcheck == false)
507							multiboxcheck = el.checked;
508					});
509					$check.push(multiboxcheck);
510					$warning = multiboxcheck == false ? true : false;
511				}
512			}
513
514			if ($obj.prop("tagName") == 'SELECT') {
515				// select type
516				if ($obj.attr('multiple') == 'multiple') {
517					// multiple
518					if (!$obj.find('option:selected').length) {
519						$check.push(false);
520						$warning = true;
521					}
522				} else {
523					// single
524					if ($obj[0].selectedIndex === 0) { // single & multip select.
525						$check.push(false);
526						$warning = true;
527						// should check for date range here then return true if we put all the field.
528					}
529				}
530				
531			
532				// check for select type with date range.
533			}
534
535			if ($obj.prev().hasClass('ui-slider')) {
536				// slider type.
537				if ($obj.val() == $obj.next().val()) {
538					$check.push(false);
539					$warning = true;
540				}
541			}
542
543			// we find magic select seperate.
544			if ($obj.hasClass('ja-magic-select-container')) {
545				$input = $obj.find('input[type="hidden"]');
546				if ($input.length===0) {
547					$check.push(false);
548					$warning = true;
549				}
550			}
551
552			if ($warning===true) {
553				// return warning here.
554				createwarning($obj);
555			} else {
556				// hide warning if form ok.
557				$obj.parents('.subclass').find('.jak2-error').remove();
558			}
559		}
560		for (var i=0;i<$check.length;i++) {
561			if ($check[i] == false) {
562				return false;
563			}
564		}
565		return true;
566	}
567}
568
569function expandOption(numb, _id, shtxt) {
570	jQuery('ul#jak2filter'+_id+' .subclass').each(function() {
571		if (jQuery(this).find('label.lb-checkbox').length > numb) {
572			jQuery(this).find('label.lb-checkbox:gt('+(numb-1)+')').hide();
573			jQuery(this).append('<label class="ex-showmore">'+shtxt+'</label>');
574		}
575		if (jQuery(this).find('label.radio').length > numb) {
576			jQuery(this).find('label.radio:gt('+(numb-1)+')').hide();
577			jQuery(this).append('<label class="ex-showmore">'+shtxt+'</label>');
578		}
579	});
580	jQuery('ul#jak2filter'+_id+' .ex-showmore').off().on('click', function() {
581		jQuery(this).parent().find('label').show();
582		jQuery(this).remove();
583	});
584}

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.