PageSourceSearch

https://zadarska-zupanija.hr/templates/shaper_helixultimate/js/main.js

js zadarska-zupanija.hr collected 2026-09-24 19:29:45 UTC 20,598 bytes, 732 lines download raw bytes

1/**
2 * @package Helix Ultimate Framework
3 * @author JoomShaper https://www.joomshaper.com
4 * @copyright Copyright (c) 2010 - 2023 JoomShaper
5 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or Later
6 */
7
8// Preloader
9jQuery(window).on('load', function () {
10	if (jQuery('.sp-loader-with-logo').length > 0) {
11
12		move();
13	}
14	jQuery('.sp-pre-loader').fadeOut(500, function () {
15		jQuery(this).remove();
16	});
17});
18
19/**
20 * Move the progress bar
21 */
22function move() {
23	var elem = document.getElementById('line-load');
24	var width = 1;
25	var id = setInterval(frame, 10);
26	function frame() {
27		if (width >= 100) {
28			clearInterval(id);
29		} else {
30			width++;
31			elem.style.width = width + '%';
32		}
33	}
34
35}
36
37jQuery(function ($) {
38
39	/**
40	 * Helix settings data
41	 *
42	 */
43	var settings = Joomla.getOptions('data') || {};
44
45	/**
46	 * sticky header
47	 *
48	 * @param {string} className the header className
49	 */
50	var handleStickiness = function (className, offsetTop) {
51		if ($('body:not(.layout-edit-iframe)').hasClass(className)) {
52			var $header = $('#sp-header');
53			var headerHeight = $header.outerHeight();
54			var $stickyHeaderPlaceholder = $('.sticky-header-placeholder');
55			let $stickyOffset = '100';
56
57			if (settings.header !== undefined && settings.header.stickyOffset !== undefined) {
58				$stickyOffset = settings.header.stickyOffset || '100';
59			}
60
61			var stickyHeader = function () {
62				var scrollTop = $(window).scrollTop();
63				if (scrollTop >= offsetTop + Number($stickyOffset)) {
64					$header.addClass('header-sticky');
65					$stickyHeaderPlaceholder.height(headerHeight);
66				} else {
67					if ($header.hasClass('header-sticky')) {
68						$header.removeClass('header-sticky');
69						$stickyHeaderPlaceholder.height('inherit');
70					}
71				}
72			};
73
74			stickyHeader();
75			$(window).scroll(function () {
76				stickyHeader();
77			});
78
79			if ($('body').hasClass('layout-boxed')) {
80				var windowWidth = $header.parent().outerWidth();
81				$header.css({ 'max-width': windowWidth, left: 'auto' });
82			}
83		} else {
84			var $header = $('#sp-header');
85			if ($header.hasClass('header-sticky')) {
86				$header.removeClass('header-sticky');
87			}
88			$(window).off('scroll');
89		}
90	};
91
92	/**
93	 * Calculate the header offset based on the
94	 * backend preview iframe site and real site.
95	 *
96	 * @return  integer The offset value
97	 */
98	function getHeaderOffset() {
99		/**
100		 * Real site header offset top
101		 *
102		 */
103		let $header = $('#sp-header');
104		let stickyHeaderTop = $header.offset().top;
105
106		/**
107		 * Backend edit preview iframe header offset top
108		 *
109		 */
110		let $backHeader = $('body.back-panel').find('#sp-header');
111		let backPanelStickyHeaderTop = null;
112
113		/**
114		 * If the class .back-panel exists,
115		 * that means this is from backend preview frame,
116		 * then get the offset top, as it varies with the original one.
117		 *
118		 */
119		if ($backHeader.length > 0) {
120			backPanelStickyHeaderTop = $backHeader.offset().top;
121		}
122
123		// By Default the header offset is the original header top
124		let headerOffset = stickyHeaderTop;
125
126		/**
127		 * If back panel sticky header top has value rather than null
128		 * that means the device type is changes from desktop to table or mobile or vice-versa.
129		 * If value found then subtract the settings topbar height from the offset top.
130		 *
131		 */
132		if (backPanelStickyHeaderTop !== null) {
133			headerOffset = backPanelStickyHeaderTop - settings.topbarHeight;
134			headerOffset = headerOffset < 0 ? stickyHeaderTop : headerOffset;
135		}
136
137		return headerOffset;
138	}
139
140	const headerExist = $('#sp-header');
141	if (headerExist.length > 0) {
142		handleStickiness('sticky-header', getHeaderOffset());
143	}
144
145	// go to top
146	$(window).scroll(function () {
147		if ($(this).scrollTop() > 100) {
148			$('.sp-scroll-up').fadeIn();
149		} else {
150			$('.sp-scroll-up').fadeOut(400);
151		}
152	});
153
154	$('.sp-scroll-up').click(function () {
155		$('html, body').animate(
156			{
157				scrollTop: -60,
158			},
159			600
160		);
161		return false;
162	});
163
164	//mega menu
165	$('.sp-megamenu-wrapper').parent().parent().css('position', 'static').parent().css('position', 'relative');
166	$('.sp-menu-full').each(function () {
167		$(this).parent().addClass('menu-justify');
168	});
169
170
171
172	$('#offcanvas-toggler, .offcanvas-toggler-secondary, .offcanvas-toggler-full').on('click', function (event) {
173		event.preventDefault();
174		openOffcanvas();
175	});
176
177	// Close handlers
178	$('.close-offcanvas, .offcanvas-overlay').on('click', function (event) {
179		event.preventDefault();
180		closeOffcanvas();
181	});
182
183	// Open function
184	function openOffcanvas() {
185		$('.offcanvas-init').addClass('offcanvas-active full-offcanvas');
186		$(document.body).css('overflow', 'hidden');
187
188		// Make offcanvas interactive
189		$('.offcanvas-menu')
190			.removeAttr('inert')
191			.attr('tabindex', '0');
192
193		// Set focus to close button (better for accessibility)
194		setTimeout(() => {
195			$('.close-offcanvas').focus();
196		}, 100);
197
198		// Add keyboard trap
199		$(document).on('keydown.offcanvas', handleOffcanvasKeyboard);
200	}
201
202	// Close function
203	function closeOffcanvas() {
204		$('.offcanvas-init').removeClass('offcanvas-active full-offcanvas');
205		$(document.body).css('overflow', '');
206
207		// Make offcanvas non-interactive
208		$('.offcanvas-menu')
209			.attr('inert', '')
210			.attr('tabindex', '-1');
211
212		// Return focus to the trigger
213		$('#offcanvas-toggler').focus();
214
215		// Remove keyboard trap
216		$(document).off('keydown.offcanvas');
217	}
218
219	// Keyboard trap handler on offcanvas
220	function handleOffcanvasKeyboard(e) {
221		if (!$('.offcanvas-init').hasClass('offcanvas-active')) return;
222
223		const $offcanvas = $('.offcanvas-menu');
224		const focusable = 'a[href], button, input, textarea, select, [tabindex="0"]';
225		const $focusable = $offcanvas.find(focusable).filter(':visible');
226
227		// Escape key closes
228		if (e.key === 'Escape') {
229			e.preventDefault();
230			closeOffcanvas();
231			return;
232		}
233
234		// Tab key containment
235		if (e.key === 'Tab') {
236			const $first = $focusable.first();
237			const $last = $focusable.last();
238
239			if (!$offcanvas[0].contains(document.activeElement)) {
240				e.preventDefault();
241				$first.focus();
242				return;
243			}
244
245			if (e.shiftKey && document.activeElement === $first[0]) {
246				e.preventDefault();
247				$last.focus();
248			} else if (!e.shiftKey && document.activeElement === $last[0]) {
249				e.preventDefault();
250				$first.focus();
251			}
252		}
253	}
254
255	// Prevent focus on inert elements
256	$(document).on('focusin', function (e) {
257		if ($(e.target).closest('[inert]').length) {
258			e.preventDefault();
259			$('#offcanvas-toggler').focus();
260		}
261	});
262
263	// Load inert polyfill if needed
264	if (!('inert' in document.createElement('div'))) {
265		const inertPolyfill = document.createElement('script');
266		inertPolyfill.src = 'https://cdn.jsdelivr.net/npm/[email protected]/inert.min.js';
267		document.head.appendChild(inertPolyfill);
268	}
269
270	// Modal Menu
271	if ($('#modal-menu').length > 0) {
272		let $modalToggler = $('#modal-menu-toggler');
273		let $modalMenu = $('#modal-menu');
274		let $body = $('body');
275
276		$modalToggler.on('click', function (e) {
277			e.preventDefault();
278			$modalMenu.toggleClass('active');
279			$body.toggleClass('modal-menu-active');
280			$(this).toggleClass('active');
281		});
282
283		// modal menu close with escape
284		$(document).keyup(function (e) {
285			if (e.key == 'Escape') {
286				$modalMenu.removeClass('active');
287				$modalToggler.removeClass('active');
288				$body.removeClass('modal-menu-active');
289			}
290		});
291	}
292
293	// Tooltip
294	const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"], .hasTooltip'));
295	tooltipTriggerList.map(function (tooltipTriggerEl) {
296		return new bootstrap.Tooltip(tooltipTriggerEl, {
297			html: true
298		});
299	});
300
301	// Popover
302	const popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"], .hasPopover'));
303	popoverTriggerList.map(function (popoverTriggerEl) {
304		return new bootstrap.Popover(popoverTriggerEl);
305	});
306
307	// Article Ajax voting
308	$('.article-ratings .rating-star').on('click', function (event) {
309		event.preventDefault();
310		var $parent = $(this).closest('.article-ratings');
311
312		var request = {
313			option: 'com_ajax',
314			template: template,
315			action: 'rating',
316			rating: $(this).data('number'),
317			article_id: $parent.data('id'),
318			format: 'json',
319		};
320
321		$.ajax({
322			type: 'POST',
323			data: request,
324			beforeSend: function () {
325				$parent.find('.fa-spinner').show();
326			},
327			success: function (response) {
328				var data = $.parseJSON(response);
329				$parent.find('.ratings-count').text(data.message);
330				$parent.find('.fa-spinner').hide();
331
332				if (data.status) {
333					$parent.find('.rating-symbol').html(data.ratings);
334				}
335
336				setTimeout(function () {
337					$parent.find('.ratings-count').text('(' + data.rating_count + ')');
338				}, 3000);
339			},
340		});
341	});
342
343	//  Cookie consent
344	$('.sp-cookie-allow').on('click', function (event) {
345		event.preventDefault();
346
347		var date = new Date();
348		date.setTime(date.getTime() + 30 * 24 * 60 * 60 * 1000);
349		var expires = '; expires=' + date.toGMTString();
350		document.cookie = 'spcookie_status=ok' + expires + '; path=/';
351
352		$(this).closest('.sp-cookie-consent').fadeOut();
353	});
354
355	$('.btn-group label:not(.active)').click(function () {
356		var label = $(this);
357		var input = $('#' + label.attr('for'));
358
359		if (!input.prop('checked')) {
360			label.closest('.btn-group').find('label').removeClass('active btn-success btn-danger btn-primary');
361			if (input.val() === '') {
362				label.addClass('active btn-primary');
363			} else if (input.val() == 0) {
364				label.addClass('active btn-danger');
365			} else {
366				label.addClass('active btn-success');
367			}
368			input.prop('checked', true);
369			input.trigger('change');
370		}
371		var parent = $(this).parents('#attrib-helix_ultimate_blog_options');
372		if (parent) {
373			showCategoryItems(parent, input.val());
374		}
375	});
376	$('.btn-group input[checked=checked]').each(function () {
377		if ($(this).val() == '') {
378			$('label[for=' + $(this).attr('id') + ']').addClass('active btn btn-primary');
379		} else if ($(this).val() == 0) {
380			$('label[for=' + $(this).attr('id') + ']').addClass('active btn btn-danger');
381		} else {
382			$('label[for=' + $(this).attr('id') + ']').addClass('active btn btn-success');
383		}
384		var parent = $(this).parents('#attrib-helix_ultimate_blog_options');
385		if (parent) {
386			parent.find('*[data-showon]').each(function () {
387				$(this).hide();
388			});
389		}
390	});
391
392	function showCategoryItems(parent, value) {
393		var controlGroup = parent.find('*[data-showon]');
394
395		controlGroup.each(function () {
396			var data = $(this).attr('data-showon');
397			data = typeof data !== 'undefined' ? JSON.parse(data) : [];
398			if (data.length > 0) {
399				if (typeof data[0].values !== 'undefined' && data[0].values.includes(value)) {
400					$(this).slideDown();
401				} else {
402					$(this).hide();
403				}
404			}
405		});
406	}
407
408	$(window).on('scroll', function () {
409		var scrollBar = $('.sp-reading-progress-bar');
410		if (scrollBar.length > 0) {
411			var s = $(window).scrollTop(),
412				d = $(document).height(),
413				c = $(window).height();
414			var scrollPercent = (s / (d - c)) * 100;
415			const position = scrollBar.data('position');
416			if (position === 'top') {
417				// var sticky = $('.header-sticky');
418				// if( sticky.length > 0 ){
419				//     sticky.css({ top: scrollBar.height() })
420				// }else{
421				//     sticky.css({ top: 0 })
422				// }
423			}
424			scrollBar.css({ width: `${scrollPercent}%` });
425		}
426	});
427
428	// Error Alert close issue fix for Joomla 3
429	var observer = new MutationObserver(function (mutations) {
430		$('#system-message-container .alert .close').attr('data-bs-dismiss', 'alert');
431	});
432	var target = document.querySelector('#system-message-container');
433	observer.observe(target, {
434		attributes: true
435	});
436
437
438});
439
440
441// Handle accessibility on off-canvas dropdown menus
442jQuery(function ($) {
443	const menuSelector = '.menu-deeper.menu-parent';
444	const togglerSelector = '.menu-toggler';
445	const childSelector = '.menu-child';
446
447	// Toggle submenu open/close
448	function toggleSubmenu($item, open = null) {
449		const $submenu = $item.children(childSelector);
450		const isOpen = $item.hasClass('menu-parent-open');
451
452		if (open === null) open = !isOpen;
453
454		if (open) {
455			$item.addClass('menu-parent-open').attr('aria-expanded', 'true');
456			$submenu.slideDown(150);
457		} else {
458			$item.removeClass('menu-parent-open').attr('aria-expanded', 'false');
459			$submenu.slideUp(150);
460		}
461	}
462
463	// Prevent event bubbling from toggler to link
464	$(document).on('click', togglerSelector, function (event) {
465		event.preventDefault();
466		event.stopPropagation();
467		const $item = $(this).closest(menuSelector);
468		const isOpen = $item.hasClass('menu-parent-open');
469		toggleSubmenu($item, !isOpen);
470	});
471
472	// Handle menu link click or Enter/Space key
473	$(document).on('click keydown', `${menuSelector} > a`, function (event) {
474		if (event.type === 'click' || event.key === 'Enter' || event.key === ' ') {
475			event.preventDefault();
476			const $item = $(this).closest(menuSelector);
477			const isOpen = $item.hasClass('menu-parent-open');
478			toggleSubmenu($item, !isOpen);
479		}
480	});
481
482	// Handle arrow key navigation
483	$(document).on('keydown', `${menuSelector} > a`, function (event) {
484		const $currentItem = $(this).closest('li');
485		const $siblings = $currentItem.parent().children('li:visible');
486		const index = $siblings.index($currentItem);
487
488		if (event.key === 'ArrowDown') {
489			event.preventDefault();
490			// If submenu is open, focus first child link
491			const $submenu = $currentItem.children(childSelector);
492			if ($submenu.length && $currentItem.hasClass('menu-parent-open')) {
493				const $firstChildLink = $submenu.children('li:visible').find('a').first();
494				if ($firstChildLink.length) {
495					$firstChildLink.focus();
496					return;
497				}
498			}
499			// Otherwise, move to next sibling
500			$siblings.eq((index + 1) % $siblings.length).find('a').first().focus();
501		} else if (event.key === 'ArrowUp') {
502			event.preventDefault();
503			// Move to previous sibling
504			$siblings.eq((index - 1 + $siblings.length) % $siblings.length).find('a').first().focus();
505		} else if (event.key === 'ArrowRight') {
506			// Open nested submenu if present
507			const $submenu = $currentItem.children(childSelector);
508			if ($submenu.length) {
509				event.preventDefault();
510				toggleSubmenu($currentItem, true);
511				const $firstChildLink = $submenu.children('li:visible').find('a').first();
512				if ($firstChildLink.length) {
513					$firstChildLink.focus();
514				}
515			}
516		} else if (event.key === 'ArrowLeft' || event.key === 'Escape') {
517			event.preventDefault();
518			// Close only the current open dropdown
519			toggleSubmenu($currentItem, false);
520			$currentItem.children('a').first().focus();
521		}
522	});
523
524	// Handle arrow key navigation inside submenu
525	$(document).on('keydown', `${childSelector} > li > a`, function (event) {
526		const $currentItem = $(this).closest('li');
527		const $siblings = $currentItem.parent().children('li:visible');
528		const index = $siblings.index($currentItem);
529
530		if (event.key === 'ArrowDown') {
531			event.preventDefault();
532			$siblings.eq((index + 1) % $siblings.length).find('a').first().focus();
533		} else if (event.key === 'ArrowUp') {
534			event.preventDefault();
535			$siblings.eq((index - 1 + $siblings.length) % $siblings.length).find('a').first().focus();
536		} else if (event.key === 'ArrowRight') {
537			// Open nested submenu if present
538			const $submenu = $currentItem.children(childSelector);
539			if ($submenu.length) {
540				event.preventDefault();
541				toggleSubmenu($currentItem, true);
542				const $firstChildLink = $submenu.children('li:visible').find('a').first();
543				if ($firstChildLink.length) {
544					$firstChildLink.focus();
545				}
546			}
547		} else if (event.key === 'ArrowLeft' || event.key === 'Escape') {
548			event.preventDefault();
549			// Close submenu and focus parent
550			const $parentMenu = $currentItem.parents(menuSelector).first();
551			toggleSubmenu($parentMenu, false);
552			$parentMenu.children('a').first().focus();
553		}
554	});
555
556	// Close all menus when clicking outside
557	$(document).on('click', function (event) {
558		if (!$(event.target).closest('.menu-deeper').length) {
559			$(menuSelector).removeClass('menu-parent-open').attr('aria-expanded', 'false');
560			$(childSelector).slideUp(150);
561		}
562	});
563
564	//mark all menu-parents as aria-haspopup
565	$(menuSelector).attr('aria-haspopup', 'true').attr('aria-expanded', 'false');
566});
567
568// Handle accessibility on megamenu and profile dropdowns
569jQuery(function ($) {
570	const menuSelectors = '.sp-megamenu-parent > li, .sp-profile-wrapper';
571
572	$(menuSelectors).each(function () {
573		const $menuItem = $(this);
574		const $trigger = $menuItem.children('a, button');
575		const $dropdown = $menuItem.children('.sp-dropdown, .sp-profile-dropdown');
576
577		if ($dropdown.length) {
578			setupDropdownEvents($menuItem, $trigger, $dropdown);
579		}
580	});
581
582	bindNestedDropdowns('body');
583
584	function setupDropdownEvents($menuItem, $trigger, $dropdown) {
585		// Show on focus or mouseenter
586		$trigger.on('focus mouseenter', function () {
587			openMenu($menuItem, $dropdown);
588		});
589
590		$menuItem.on('mouseenter', function () {
591			openMenu($menuItem, $dropdown);
592		});
593
594		// Hide on focusout or mouseleave
595		$menuItem.on('mouseleave focusout', function () {
596			setTimeout(function () {
597				if (!$menuItem.find(':focus').length && !$menuItem.is(':hover')) {
598					closeMenu($menuItem, $dropdown);
599				}
600			}, 100);
601		});
602
603		// Keyboard trigger
604		$trigger.on('keydown', function (event) {
605			switch (event.key) {
606				case 'Enter':
607				case ' ':
608					event.preventDefault();
609					openMenu($menuItem, $dropdown);
610					break;
611				case 'ArrowDown':
612					event.preventDefault();
613					openMenu($menuItem, $dropdown);
614					focusFirstItem($dropdown);
615					break;
616				case 'Escape':
617					event.preventDefault();
618					closeMenu($menuItem, $dropdown);
619					$trigger.focus();
620					break;
621			}
622		});
623
624		// Prevent click from toggling menu
625		$trigger.on('click', function (event) {
626			// Only prevent default if dropdown exists
627			if ($dropdown.length) {
628				event.preventDefault();
629			}
630		});
631	}
632
633	function bindNestedDropdowns(containerSelector) {
634		$(containerSelector).find(' .sp-has-child').each(function () {
635			const $subItem = $(this);
636			const $trigger = $subItem.children('a, button');
637			const $subDropdown = $subItem.children('.sp-dropdown');
638
639			if ($subDropdown.length) {
640				setupDropdownEvents($subItem, $trigger, $subDropdown);
641				bindNestedDropdowns($subDropdown);
642			}
643		});
644	}
645
646	function openMenu($item, $dropdown) {
647		$dropdown.show();
648		// Only force display for .sp-profile-dropdown
649		if ($dropdown.hasClass('sp-profile-dropdown')) {
650			$dropdown.attr('style', 'display: block !important');
651		}
652		bindKeyboardNavigation($dropdown);
653	}
654
655	function closeMenu($item, $dropdown) {
656		$dropdown.hide();
657		// Reset style for .sp-profile-dropdown
658		if ($dropdown.hasClass('sp-profile-dropdown')) {
659			$dropdown.removeAttr('style');
660		}
661	}
662
663	function focusFirstItem($dropdown) {
664		const $focusable = $dropdown.find('a, button').filter(':visible');
665		if ($focusable.length) {
666			$focusable.first().focus();
667		}
668	}
669
670	function bindKeyboardNavigation($dropdown) {
671		const $items = $dropdown.find('a, button').filter(':visible');
672
673		$items.off('keydown').on('keydown', function (event) {
674			const currentIndex = $items.index(this);
675			let newIndex = -1;
676
677			if (event.key === 'ArrowDown') {
678				event.preventDefault();
679				newIndex = (currentIndex + 1) % $items.length;
680			} else if (event.key === 'ArrowUp') {
681				event.preventDefault();
682				newIndex = (currentIndex - 1 + $items.length) % $items.length;
683			} else if (event.key === 'Escape') {
684				event.preventDefault();
685
686				// Reset style for .sp-profile-dropdown
687				if ($dropdown.hasClass('sp-profile-dropdown')) {
688					$dropdown.removeAttr('style');
689				}
690
691				const $currentDropdown = $(this).closest('.sp-dropdown');
692				const $parentItem = $currentDropdown.parent(' .sp-has-child, .sp-megamenu-parent > li');
693
694				// Check if this is the root-level dropdown
695				const isRoot = $parentItem.parent().is('.sp-megamenu-parent, .sp-megamenu-parent > ul, nav');
696
697				if (isRoot) {
698					// Close all menus
699					$(menuSelectors).each(function () {
700						const $item = $(this);
701						closeMenu($item, $item.children('.sp-dropdown'));
702					});
703				} else {
704					// Close only current submenu and focus its trigger
705					const $trigger = $parentItem.children('a, button');
706					closeMenu($parentItem, $currentDropdown);
707					if ($trigger.length) {
708						$trigger.focus();
709					}
710				}
711				return;
712			}
713
714			if (newIndex > -1) {
715				$items.eq(newIndex).focus();
716			}
717		});
718	}
719
720	// Close all menus on outside click
721	$(document).on('click', function (event) {
722		if (!$(event.target).closest(menuSelectors).length) {
723			$(menuSelectors).each(function () {
724				const $item = $(this);
725				closeMenu($item, $item.children('.sp-dropdown'));
726			});
727		}
728	});
729
730});
731
732

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.