PageSourceSearch

https://www.sitam-ab.com/wp-content/themes/thegem/js/thegem-header.js?ver=5.12.3.1

js sitam-ab.com collected 2026-09-26 16:25:33 UTC 21,078 bytes, 709 lines download raw bytes

1(function($) {
2
3	function HeaderAnimation(el, options) {
4		this.el = el;
5		this.$el = $(el);
6		this.options = {
7			startTop: 1
8		};
9		$.extend(this.options, options);
10		this.initialize();
11	}
12
13	HeaderAnimation.prototype = {
14		initialize: function() {
15			var self = this;
16			this.$page = $('#page').length ? $('#page') : $('body');
17			this.$wrapper = $('#site-header-wrapper');
18			this.$topArea = $('#top-area');
19			this.topAreaInSiteHeader = $('#site-header #top-area').length > 0;
20			this.$headerMain = $('.header-main', this.$el);
21			this.hasAdminBar = document.body.className.indexOf('admin-bar') != -1;
22			this.adminBarOffset = 0;
23			this.adminBarHeight = 0;
24			this.topOffset = 0;
25			this.oldScrollY = 0;
26			this.isResponsive = null;
27			this.isResponsiveOld = null;
28			this.elHeight = this.$el.outerHeight();
29			this.elHeightOld = this.$el.outerHeight();
30			this.headerInited = false;
31			this.windowWidth = window.innerWidth;
32
33			this.hideWrapper = this.$wrapper.hasClass('site-header-wrapper-transparent');
34			this.videoBackground = $('.page-title-block .gem-video-background').length && $('.page-title-block .gem-video-background').data('headerup');
35
36			if(this.$el.hasClass('header-on-slideshow') && $('#main-content > *').first().is('.gem-slideshow, .block-slideshow')) {
37				this.$wrapper.css({position: 'absolute'});
38			}
39
40			if(this.$el.hasClass('header-on-slideshow') && $('#main-content > *').first().is('.gem-slideshow, .block-slideshow')) {
41				this.$wrapper.addClass('header-on-slideshow');
42			} else {
43				this.$el.removeClass('header-on-slideshow');
44			}
45
46			if(this.videoBackground) {
47				this.$el.addClass('header-on-slideshow');
48				this.$wrapper.addClass('header-on-slideshow');
49			}
50
51			this.initHeader();
52
53			$(document).ready(function() {
54				self.updateAdminBarInfo();
55				self.updateStartTop();
56			});
57
58			$(window).on('scroll', function() {
59				self.scrollHandler();
60			});
61
62			if ($('#thegem-perspective').length) {
63				this.$page.on('scroll', function() {
64					self.scrollHandler();
65				});
66			}
67
68			$(window).resize(function() {
69				setTimeout(function() {
70					if (self.windowWidth != $(window).width()) {
71						self.initHeader();
72						self.scrollHandler();
73						self.windowWidth = $(window).width();
74					}
75				}, 0);
76			});
77
78			//load header fix
79			if (document.readyState === 'complete') {
80				self.$el.addClass('ios-load');
81			} else {
82				var oldWindowLoad = window.onload;
83				window.onload = function() {
84					if (oldWindowLoad) {
85						oldWindowLoad()
86					}
87					self.$el.addClass('ios-load');
88				}
89			}
90		},
91
92		initHeader: function() {
93			this.isResponsiveOld = this.isResponsive;
94			this.isResponsive = window.isResponsiveMenuVisible();
95			this.elHeightOld = this.elHeight;
96			this.elHeight = this.$el.outerHeight();
97
98			if (this.isResponsive) {
99				this.$el.addClass('shrink-mobile');
100			} else {
101				this.$el.removeClass('shrink-mobile');
102			}
103
104			this.updateAdminBarInfo();
105			this.updateStartTop();
106			if (this.isResponsive != this.isResponsiveOld || this.elHeight != this.elHeightOld) {
107				this.initializeStyles();
108			}
109		},
110
111		updateAdminBarInfo: function() {
112			if (this.hasAdminBar) {
113				this.adminBarHeight = $('#wpadminbar').outerHeight();
114				this.adminBarOffset = this.hasAdminBar && $('#wpadminbar').css('position') == 'fixed' ? parseInt(this.adminBarHeight) : 0;
115			}
116		},
117
118		updateStartTop: function() {
119			if (this.$topArea.length && this.$topArea.is(':visible') && !this.topAreaInSiteHeader) {
120				this.options.startTop = this.$topArea.outerHeight();
121			} else {
122				this.options.startTop = 1;
123			}
124
125			if (this.hasAdminBar && this.adminBarOffset == 0) {
126				this.options.startTop += this.adminBarHeight;
127			}
128		},
129
130		setMargin: function($img) {
131			var $small = $img.siblings('img.small'),
132				w = 0;
133
134			if (this.$headerMain.hasClass('logo-position-right')) {
135				w = $small.width();
136			} else if (this.$headerMain.hasClass('logo-position-center') || this.$headerMain.hasClass('logo-position-menu_center')) {
137				w = $img.width();
138				var smallWidth = $small.width(),
139					offset = (w - smallWidth) / 2;
140
141				w = smallWidth + offset;
142				$small.css('margin-right', offset + 'px');
143			}
144			if (!w) {
145				w = $img.width();
146			}
147			$small.css('margin-left', '-' + w + 'px');
148			$img.parent().css('min-width', w + 'px');
149
150			$small.show();
151		},
152
153		initializeStyles: function() {
154			var self = this;
155
156			if (this.$headerMain.hasClass('logo-position-menu_center')) {
157				var $img = $('#primary-navigation .menu-item-logo a .logo img.default', this.$el);
158			} else {
159				var $img = $('.site-title .site-logo a .logo img', this.$el);
160			}
161
162			if (!$img.length) {
163				self.initializeHeight();
164			} else if ($img[0].complete) {
165				self.setMargin($img);
166				self.initializeHeight();
167			} else {
168				$img.on('load error', function() {
169					self.setMargin($img);
170					self.initializeHeight();
171				});
172			}
173		},
174
175		initializeHeight: function() {
176			if (this.hideWrapper) {
177				this.headerInited = true;
178				return false;
179			}
180
181			that = this;
182
183			setTimeout(function() {
184				var shrink = that.$el.hasClass('shrink');
185				if (shrink) {
186					that.$el.removeClass('shrink').addClass('without-transition');
187				}
188				var elHeight = that.$el.outerHeight();
189
190				//load header fix
191				if (navigator.userAgent.match(/(iPod|iPhone|iPad)/)) {
192					that.$wrapper.css('min-height', elHeight);
193				} else {
194					that.$wrapper.height(elHeight);
195				}
196
197				if (shrink) {
198					that.$el.addClass('shrink').removeClass('without-transition');
199				}
200				that.headerInited = true;
201			}, 50);
202		},
203
204		scrollHandler: function() {
205			if (!this.headerInited || window.gemSettings.fullpageEnabled || $('body').hasClass('vc_editor')) {
206				return;
207			}
208
209			var self = this,
210				scrollY = this.getScrollY();
211
212			if (scrollY >= this.options.startTop) {
213				if (this.isResponsive && this.$wrapper.hasClass('sticky-header-on-mobile-disabled') && scrollY < this.options.startTop + $('#site-header-wrapper').height()) {
214					return;
215				}
216				if (!this.$el.hasClass('shrink')) {
217					var shrinkClass = 'shrink fixed';
218					if (window.gemSettings.fillTopArea) {
219						shrinkClass += ' fill';
220					}
221					if (this.$wrapper.hasClass('sticky-header-on-mobile-disabled')) {
222						shrinkClass += '  hidden hide-immediately';
223					}
224					this.$el.addClass(shrinkClass);
225					//$('.hamburger-group').not('.hamburger-size-small-original').addClass('hamburger-size-small');
226					//$('.perspective-toggle, .overlay-toggle').not('.toggle-size-small-original').addClass('toggle-size-small');
227				}
228				var top = 0;
229				if (this.$page[0].scrollTop > 0) {
230					top += this.$page[0].scrollTop;
231				} else {
232					if (this.hasAdminBar) {
233						top += this.adminBarOffset;
234					}
235				}
236
237				this.$el.css({
238					top: top != 0 ? top : ''
239				});
240			} else {
241				if (this.$el.hasClass('shrink')) {
242					this.$el.removeClass('shrink fixed');
243					//$('.hamburger-group').not('.hamburger-size-small-original').removeClass('hamburger-size-small');
244					//$('.perspective-toggle, .overlay-toggle').not('.toggle-size-small-original').removeClass('toggle-size-small');
245				}
246				if (this.hasAdminBar) {
247					this.$el.css({
248						top: ''
249					});
250				}
251			}
252
253			if (this.isResponsive && !this.$wrapper.hasClass('sticky-header-on-mobile')) {
254				if (!$('.mobile-menu-slide-wrapper.opened').length && !$('#primary-menu.dl-menuopen').length && !$('.menu-overlay.active').length) {
255					var hideScroll = 300;
256					if (this.$wrapper.hasClass('sticky-header-on-mobile-disabled')) {
257						hideScroll = 0;
258					}
259					if (scrollY - this.oldScrollY > 0 && scrollY > hideScroll && !this.$el.hasClass('hidden')) {
260						self.$el.addClass('hidden');
261					}
262					if (scrollY - this.oldScrollY < 0 && this.$el.hasClass('hidden')) {
263						if (this.$el.hasClass('hide-immediately')) {
264							self.$el.removeClass('hide-immediately');
265						} else {
266							self.$el.removeClass('hidden');
267						}
268					}
269				} else {
270					self.$el.removeClass('hidden');
271				}
272			}
273
274			this.oldScrollY = scrollY;
275		},
276
277		getScrollY: function() {
278			return window.pageYOffset || document.documentElement.scrollTop + this.$page[0].scrollTop;
279		},
280	};
281
282	$.fn.headerAnimation = function(options) {
283		options = options || {};
284		return new HeaderAnimation(this.get(0), options);
285	};
286
287	$.fn.headerAnimationOnlyMobile = function() {
288		if(!this.length) return ;
289		var $header = $(this),
290			$window = $(window),
291			isSticked = false,
292			stickAfter = 100,
293			cloneHTML = '',
294			$adminBar = $('#wpadminbar'),
295			headerHeight = $header.parent()[0].offsetHeight,
296			adminBarHeight = $adminBar.length > 0 ? $adminBar[0].offsetHeight : 0,
297			previousScroll;
298
299			stickAfter = headerHeight + adminBarHeight;
300
301
302		$window.on('resize', function() {
303			if(window.isResponsiveMenuVisible()) {
304				$header.parent().addClass('header-sticky-prepared').css({
305					paddingTop: headerHeight
306				});
307			} else {
308				$header.parent().removeClass('header-sticky-prepared').css({
309					paddingTop: ''
310				});
311			}
312		}).trigger('resize');
313
314		$window.on('scroll', function() {
315			var after = stickAfter;
316			var currentScroll = $window.scrollTop();
317			var windowHeight = $window.height();
318			var documentHeight = $(document).height();
319
320			if (currentScroll > after) {
321				stickHeader();
322			} else {
323				unstickHeader();
324			}
325
326			var startAfter = 100;
327
328			if(window.isResponsiveMenuVisible()) {
329				if (previousScroll - currentScroll > 0 && currentScroll > after) {
330					$header.addClass('header-scroll-up');
331					$header.removeClass('header-scroll-down');
332				} else if (currentScroll - previousScroll > 0 && currentScroll + windowHeight !== documentHeight && currentScroll > (after + startAfter)) {
333					$header.addClass('header-scroll-down');
334					$header.removeClass('header-scroll-up');
335				} else if (currentScroll <= after) {
336					$header.removeClass('header-scroll-down');
337					$header.removeClass('header-scroll-up');
338				} else if (currentScroll + windowHeight >= documentHeight - 5) {
339					$header.addClass('header-scroll-up');
340					$header.removeClass('header-scroll-down');
341				}
342			}
343
344			previousScroll = currentScroll;
345		});
346
347		function stickHeader() {
348			if (isSticked) {
349				return;
350			}
351
352			if($header.hasClass('header-sticky-template') && !window.isResponsiveMenuVisible()) {
353				return;
354			}
355
356			isSticked = true;
357			$header.addClass('header-sticked');
358		}
359
360		function unstickHeader() {
361			if (!isSticked) {
362				return;
363			}
364
365			isSticked = false;
366			$header.removeClass('header-sticked');
367		}
368	}
369
370	$('#site-header.animated-header').headerAnimation();
371	$('.sticky-header-on-mobile #site-header:not(.animated-header)').headerAnimationOnlyMobile();
372
373	$('.menu-item-search a').on('click', function(e){
374		e.preventDefault();
375		if ($(this).closest('.menu-item-fullscreen-search-mobile').length &&
376			$('.primary-navigation').hasClass('responsive')) {
377			return;
378		}
379		if($(this).closest('.overlay-menu-wrapper.active').length) {
380			var $primaryMenu = $('#primary-menu');
381			$primaryMenu.addClass('overlay-search-form-show');
382
383			if ($primaryMenu.hasClass('no-responsive')) {
384				$primaryMenu.addClass('animated-minisearch');
385			}
386
387			setTimeout(function() {
388				$(document).on('click.menu-item-search-close', 'body', function(e) {
389					if(!$(e.target).is('.menu-item-search .minisearch *')) {
390						var $primaryMenu = $('#primary-menu');
391
392						if ($primaryMenu.hasClass('animated-minisearch')) {
393							$primaryMenu.removeClass('animated-minisearch');
394
395							setTimeout(function() {
396								$primaryMenu.removeClass('overlay-search-form-show');
397								$(document).off('click.menu-item-search-close');
398							}, 700);
399
400						} else {
401							$primaryMenu.removeClass('overlay-search-form-show');
402							$(document).off('click.menu-item-search-close');
403						}
404					}
405				});
406			}, 500);
407		} else {
408			$('.menu-item-search').toggleClass('active');
409		}
410
411		if(!$('#primary-navigation').hasClass('overlay-active')) {
412			$('#searchform-input').focus();
413		}
414	});
415
416	$(document).ready(function () {
417
418		var localCache = {
419			data: {},
420			remove: function (url) {
421				delete localCache.data[url];
422			},
423			exist: function (url) {
424				return localCache.data.hasOwnProperty(url) && localCache.data[url] !== null;
425			},
426			get: function (url) {
427				return localCache.data[url];
428			},
429			set: function (url, cachedData, callback) {
430				localCache.remove(url);
431				localCache.data[url] = cachedData;
432				if (typeof callback === "function") callback(cachedData);
433			}
434		};
435
436		if (navigator.appVersion.indexOf("Win")!=-1) {
437			$('body').addClass('platform-Windows');
438		}
439
440		const $fullscreenSearch = $('.thegem-fullscreen-search[data-id="header-search"]'),
441			$fullscreenSearchInput = $('.thegem-fullscreen-searchform-input', $fullscreenSearch),
442			$fullscreenSearchResults = $fullscreenSearch.find('.sf-result'),
443			$fullscreenSearchClose = $fullscreenSearch.find('.sf-close');
444
445		let ajax, ajaxActive = false;
446
447		const fullscreenSearchTop = () => {
448			var searchTop;
449			if ($('#page').hasClass('vertical-header') && $(window).width() > 979) {
450				searchTop = 0;
451			} else if ($('#site-header').hasClass('fixed')) {
452				searchTop = $('#site-header').outerHeight();
453			} else {
454				searchTop = $('#site-header').offset().top + $('#site-header').outerHeight() - $(window).scrollTop();
455			}
456			$fullscreenSearch.css('top', searchTop);
457		};
458
459		$('.menu-item-fullscreen-search a, .menu-item-fullscreen-search-mobile a').on('click', function(e){
460			let searchMenuItem = $(this).parents('.menu-item-search');
461			if (searchMenuItem.hasClass('menu-item-fullscreen-search-mobile') &&
462				!searchMenuItem.hasClass('menu-item-fullscreen-search') &&
463				!$('.primary-navigation').hasClass('responsive')) {
464				return;
465			}
466
467			e.preventDefault();
468			fullscreenSearchTop();
469
470			$fullscreenSearch.toggleClass('active');
471
472			if (ajaxActive) {
473				ajax.abort();
474				ajaxActive = false;
475			}
476
477			$fullscreenSearchInput.val('');
478
479			if ($('#site-header').hasClass('fixed')) {
480				setTimeout(function () {
481					$fullscreenSearchInput.focus();
482				}, 500);
483			} else {
484				if ($(window).scrollTop() == 0) {
485					$('html, body').stop().animate({
486						scrollTop: 0
487					}, 500);
488				}
489				$fullscreenSearchInput.focus();
490			}
491
492			$fullscreenSearchResults.find('.preloader-new').remove();
493			$fullscreenSearchResults.find('.result-sections').html('');
494
495			let scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
496			$('.header-background, .top-area, .block-content, #page-title').css('padding-right', scrollbarWidth);
497
498			$('body').toggleClass('fullscreen-search-opened');
499
500			$('#thegem-perspective.modalview .perspective-menu-close').trigger('click');
501
502			if ($('.primary-navigation').hasClass('responsive')) {
503				$('.menu-toggle').trigger('click');
504			}
505
506			if ($(window).width() > 767) {
507				$('.overlay-toggle').trigger('click');
508			}
509
510			if ($(window).width() > 979) {
511				$('.hamburger-toggle').trigger('click');
512				$('.vertical-toggle').trigger('click');
513			}
514		});
515
516		$fullscreenSearchClose.on('click', function(e){
517			e.preventDefault();
518			$('.menu-item-fullscreen-search').removeClass('active');
519			$fullscreenSearch.removeClass('active');
520			$('.header-background, .top-area, .block-content, #page-title').css('padding-right', 0);
521			$('body').removeClass('fullscreen-search-opened');
522			if (ajaxActive) {
523				ajax.abort();
524				ajaxActive = false;
525			}
526			$fullscreenSearchInput.val('');
527			$fullscreenSearchResults.find('.preloader-new').remove();
528			$fullscreenSearchResults.find('.result-sections').html('');
529		});
530
531		$(document).on('keyup', function(e) {
532			if (e.key === "Escape") {
533				$('.fullscreen-search .sf-close').trigger('click');
534			}
535		});
536
537		if ($fullscreenSearch.hasClass('ajax-search')) {
538
539			const $ajaxSearchParams = $('#ajax-search-params'),
540				postTypes = $ajaxSearchParams.data('post-types'),
541				postTypesPpp = $ajaxSearchParams.data('post-types-ppp'),
542				resultTitle = $ajaxSearchParams.data('result-title'),
543				showAllText = $ajaxSearchParams.data('show-all');
544
545			const ajaxSearch = (query) => {
546
547				if (!$fullscreenSearchInput.hasClass('styled')) {
548					let styles = $fullscreenSearchInput.data('styles');
549					styles.forEach(function (style) {
550						$('head').append('<link rel="stylesheet" type="text/css" href="' + style + '">');
551					});
552					$fullscreenSearchInput.addClass('styled');
553				}
554
555				if (ajaxActive) {
556					ajax.abort();
557				} else {
558					$fullscreenSearchResults.prepend('<div class="preloader-new"><div class="preloader-spin"></div></div>');
559				}
560
561				ajax = $.ajax({
562					type: 'post',
563					url: thegem_scripts_data.ajax_url,
564					data: {
565						action: 'thegem_ajax_search',
566						search: query,
567						post_types: postTypes,
568						post_types_ppp: postTypesPpp,
569						result_title: resultTitle,
570						show_all_text: showAllText,
571					},
572					beforeSend: function () {
573						if (localCache.exist(query)) {
574							$fullscreenSearchResults.find('.preloader-new').remove();
575							$fullscreenSearchResults.find('.result-sections').html(localCache.get(query));
576							return false;
577						} else {
578							ajaxActive = true;
579						}
580					},
581					success: function (response) {
582						ajaxActive = false;
583						$fullscreenSearchResults.find('.preloader-new').remove();
584						$fullscreenSearchResults.find('.result-sections').html(response);
585						localCache.set(query, response);
586					}
587				});
588			};
589
590			$fullscreenSearchInput.on( 'keyup', function() {
591				let query = $(this).val();
592
593				if (query.length > 2) {
594					ajaxSearch(query);
595				} else {
596					if (ajaxActive) {
597						ajax.abort();
598						ajaxActive = false;
599					}
600					$fullscreenSearchResults.find('.preloader-new').remove();
601					$fullscreenSearchResults.find('.result-sections').html('');
602				}
603				return false;
604			});
605
606			$('.top-search-item', $fullscreenSearch).on( 'click', function(e) {
607				e.preventDefault();
608				var query = $(this).data('search');
609				ajaxSearch(query);
610				$fullscreenSearchInput.val(query);
611				return false;
612			});
613		}
614
615
616
617		const $verticalMinisearchAjax = $('.vertical-minisearch.menu-item-ajax-search');
618
619		if ($verticalMinisearchAjax.length) {
620
621			const $ajaxSearchParams = $('#ajax-search-params'),
622				postTypes = $ajaxSearchParams.data('post-types'),
623				postTypesPpp = $ajaxSearchParams.data('post-types-ppp'),
624				$miniSearchForm = $('#searchform', $verticalMinisearchAjax),
625				$miniSearchSubmitIcon = $('.sf-submit-icon', $verticalMinisearchAjax),
626				$miniSearchInput = $('.sf-input', $verticalMinisearchAjax),
627				$miniSearchResults = $('.ajax-minisearch-results', $verticalMinisearchAjax);
628
629			const ajaxMiniSearch = (query) => {
630
631				if (ajaxActive) {
632					ajax.abort();
633				}
634				$miniSearchForm.addClass('ajax-loading');
635
636				ajax = $.ajax({
637					type : 'post',
638					url : thegem_scripts_data.ajax_url,
639					data : {
640						action : 'thegem_ajax_search_mini',
641						search : query,
642						post_types : postTypes,
643						post_types_ppp : postTypesPpp,
644					},
645					beforeSend: function() {
646						if (localCache.exist(query)) {
647							$miniSearchForm.removeClass('ajax-loading');
648							$miniSearchResults.html( localCache.get(query) );
649							return false;
650						} else {
651							ajaxActive = true;
652						}
653					},
654					success: function( response ) {
655						ajaxActive = false;
656						$miniSearchResults.html( response );
657						$miniSearchForm.removeClass('ajax-loading');
658						localCache.set(query, response);
659					}
660				});
661			};
662
663			const clearAjaxMinisearch = () => {
664				$miniSearchInput.val('');
665				$miniSearchResults.html('');
666				$miniSearchSubmitIcon.removeClass('clear');
667				$miniSearchForm.removeClass('ajax-loading');
668				if (ajaxActive) {
669					ajax.abort();
670					ajaxActive = false;
671				}
672			};
673
674			$miniSearchInput.on( 'keyup', function() {
675				let query = $(this).val();
676
677				if (query.length > 0) {
678					$miniSearchSubmitIcon.addClass('clear');
679				} else {
680					$miniSearchSubmitIcon.removeClass('clear');
681				}
682
683				if (query.length > 2) {
684					ajaxMiniSearch(query);
685				} else {
686					if (ajaxActive) {
687						ajax.abort();
688						ajaxActive = false;
689					}
690					$miniSearchResults.html('');
691					$miniSearchForm.removeClass('ajax-loading');
692				}
693				return false;
694			});
695
696			$miniSearchSubmitIcon.on('click', function () {
697				if ($(this).hasClass('clear')) {
698					clearAjaxMinisearch();
699				}
700			});
701
702			$('.hamburger-toggle, #thegem-perspective .perspective-menu-close, .vertical-toggle').click(function() {
703				clearAjaxMinisearch();
704			});
705
706		}
707	});
708
709})(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.