PageSourceSearch

https://techtidningen.se/wp-content/themes/main_pauser/js/script.js?ver=1.7.6

js techtidningen.se collected 2026-09-29 06:56:20 UTC 60,501 bytes, 2,247 lines download raw bytes

1var ajaxurl = "";
2var adminajaxurl = "";
3
4/**************************
5* LAZY LOAD
6***************************/
7var bLazy = new Blazy();
8
9console.log("test");
10
11
12jQuery(document).ready(function($){
13	
14	//Fin scroll
15	$(document).on('click', 'a[href^="#"]', function (e) {
16		var target = $(this.getAttribute('href'));
17	
18		if (target.length) {
19		e.preventDefault();
20	
21		var headerHeight = $('#header').outerHeight() || 0;
22		var offset = headerHeight + 20;
23	
24		$('html, body').animate({
25			scrollTop: target.offset().top - offset
26		}, 500);
27		}
28	});
29	
30	
31	var FastLinks = (function ($) {
32	
33		var desktopBreakpoint = 1960;
34		var fixedTop = 120;
35		
36		function init(root) {
37			root = root || document;
38		
39			$(root).find('article.has_fastlinks').each(function () {
40		
41				var $article = $(this);
42		
43				// ⛔ hoppa över redan initierade artiklar
44				if ($article.data('fastlinks-initialized')) {
45					return;
46				}
47		
48				$article.data('fastlinks-initialized', true);
49		
50				buildFastlinks($article);
51				bindBehavior($article);
52			});
53		}
54	
55		function insertFastlinks($article, $wrapper) { 
56			//var isNarrow = $(window).width() < 1960; 
57			var isNarrow = true; 
58			var $target; 
59			if (isNarrow) { 
60				$target = $article.find('.entry-content').first(); 
61			} 
62			else { 
63				//$target = $article.find('.gridholder').first(); 
64				$target = $article.find('.entry-content').first(); 
65			} 
66			if ($target.length) { 
67				$wrapper.insertBefore($target); 
68			} 
69		}
70	
71		
72		
73		function buildFastlinks($article) {
74		
75			var $wrapper = $('<div class="fastlinks-wrapper"></div>');
76			var $container = $('<div class="fastlinks-container"></div>');
77			var $ul = $('<ul class="fastlinks"></ul>');
78		
79			$container.append($ul);
80			$wrapper.append($container);
81		
82			var hasItems = false;
83			var usedIds = {};
84		
85			$article.find('.entry-content').each(function () {
86		
87				var $entry = $(this);
88		
89				var $h2s = $entry.children('h2')
90					.add(
91						$entry
92							.children('.lockedpart')
93							.children('.encrypted')
94							.children('h2')
95					);
96		
97				$h2s.each(function () {
98		
99					var $h2 = $(this);
100					var text = $.trim($h2.text());
101					if (!text) return;
102		
103					var baseSlug = text
104						.toLowerCase()
105						.replace(/[åä]/g, 'a')
106						.replace(/ö/g, 'o')
107						.replace(/[^a-z0-9]+/g, '-')
108						.replace(/^-+|-+$/g, '');
109		
110					if (!baseSlug) baseSlug = 'section';
111		
112					var slug = baseSlug;
113					var i = 2;
114					while (usedIds[slug] || document.getElementById(slug)) {
115						slug = baseSlug + '-' + i++;
116					}
117					usedIds[slug] = true;
118		
119					if (!$h2.attr('id')) {
120						$h2.attr('id', slug);
121					}
122		
123					var $li = $('<li />').append(
124						$('<a />', {
125							href: '#' + slug,
126							text: text
127						})
128					);
129		
130					$ul.append($li);
131					hasItems = true;
132				});
133			});
134		
135			if (!hasItems) return;
136		
137			insertFastlinks($article, $wrapper);
138		
139			// desktop state
140			if ($(window).width() >= desktopBreakpoint) {
141				$wrapper
142					.data('isFixed', false)
143					.data('fixedTop', fixedTop)
144					.data('startTop', null)
145					.css({ position: 'absolute' });
146			}
147		}
148		
149		
150		function bindBehavior($article) {
151		
152			var $wrapper = $article.find('.fastlinks-wrapper');
153			if (!$wrapper.length) return;
154		
155			var $toc = $wrapper.find('.fastlinks');
156			var $items = $toc.find('li');
157			var $window = $(window);
158		
159			var headings = $items.find('a').map(function () {
160				return $($(this).attr('href'));
161			}).get();
162		
163			function updateActive() {
164				var scrollTop = $window.scrollTop();
165				var offset = fixedTop;
166				var activeIndex = 0;
167		
168				for (var i = 0; i < headings.length; i++) {
169					if (headings[i].offset().top - offset <= scrollTop) {
170						activeIndex = i;
171					}
172				}
173		
174				$items.removeClass('active')
175					.eq(activeIndex)
176					.addClass('active');
177			}
178		
179			function updateStickyLimit() { 
180				var winTop = $(window).scrollTop(); 
181				var articleTop = $article.offset().top; 
182				var articleBottom = articleTop + $article.outerHeight(); 
183				var wrapperHeight = $wrapper.outerHeight(); 
184				// ===== DESKTOP ===== 
185				if ($(window).width() >= 1960) { 
186					
187					var startTop = $wrapper.data('startTop');
188					
189					// 🔥 LAZY INIT – exakt en gång, när layouten är stabil
190					if (startTop == null) {
191						startTop = $wrapper.offset().top;
192						$wrapper.data('startTop', startTop);
193					}
194					
195					var fixedTop = $wrapper.data('fixedTop');
196					var isFixed = $wrapper.data('isFixed');
197	
198					if (startTop == null) return; 
199						// Växla till FIXED 
200						if (!isFixed && winTop + fixedTop >= startTop) { 
201							$wrapper
202								.data('isFixed', true)
203								.css({ 
204									position: 'fixed', 
205									top: fixedTop, 
206									bottom: 'auto' 
207								}); 
208						} 
209						// Växla tillbaka till ABSOLUTE 
210						if (isFixed && winTop + fixedTop < startTop) { 
211							$wrapper 
212							.data('isFixed', false) 
213							.css({ position: 'absolute', top: 'auto', bottom: 'auto' }); 
214						} 
215						// Stoppa vid artikelns botten 
216						var fixedBottom = winTop + fixedTop + wrapperHeight; 
217						if (fixedBottom >= articleBottom) { 
218							$wrapper 
219							.data('isFixed', false) 
220							.css({ position: 'absolute', top: 'auto', bottom: '0' }); 
221						} 
222						return; 
223				} 
224			}
225		
226			$window.on('scroll.fastlinks resize.fastlinks', function () {
227				updateActive();
228				updateStickyLimit();
229			});
230		
231			updateActive();
232			updateStickyLimit();
233		}
234		
235		return {
236				init: init
237		};
238	
239	})(jQuery);
240	
241	/**************************
242	* MEDÅKANDE Summa
243	***************************/
244	// Kör bara på desktop
245	  if (window.matchMedia('(min-width: 1024px)').matches) {
246	
247		let $table, startOffset, startLeft, startWidth, headerHeight;
248	
249		// beräkna positioner
250		function recalcPositions() {
251		  $table = $('body.woocommerce-checkout table.shop_table.woocommerce-checkout-review-order-table');
252		  if(!$table.length) return false;
253		  
254		  $table.removeAttr('style');
255	
256		  headerHeight = $('#header').outerHeight() || 0; // ta höjden på fast meny
257		  startOffset  = $table.offset().top - headerHeight; // så den "klistrar" rätt
258		  startLeft    = $table.offset().left;
259		  startWidth   = $table.outerWidth();
260	
261		  return true;
262		}
263	
264		function makeSticky() {
265		  if(!recalcPositions()) return;
266	
267		  $(window).off('scroll.w4sticky').on('scroll.w4sticky', function(){
268			const scrollTop = $(window).scrollTop();
269	
270			if(scrollTop > startOffset){
271			  // fixera tabellen
272			  $table.attr(
273				'style',
274				'position:fixed; top:'+ (headerHeight + 10) +'px; left:'+ startLeft +'px; width:'+ startWidth +'px; z-index:1000;'
275			  );
276			} else {
277			  // återställ
278			  $table.removeAttr('style');
279			}
280		  });
281		}
282	
283		// Kör direkt vid laddning
284		makeSticky();
285	
286		// Kör om WooCommerce uppdaterar checkouten (t.ex. vid adressändring)
287		$(document.body).on('updated_checkout', function(){
288		  makeSticky();
289		});
290	
291		// Hantera resize
292		$(window).on('resize', function(){
293		  if (window.matchMedia('(min-width: 1024px)').matches) {
294			// uppdatera värden så att left/top/width är korrekta
295			recalcPositions();
296		  } else {
297			// om man går under 1024px: ta bort inline-stil och scroll-hantering
298			$(window).off('scroll.w4sticky');
299			if($table) $table.removeAttr('style');
300		  }
301		});
302	
303	  }
304	  
305	  
306	  jQuery(function($) {
307		  if($('.product-buy table.variations').length > 0){		  
308			$('.product-buy table.variations select').select2({
309				width: 'auto'
310			});
311		  }
312	  });
313
314	  
315	 /*Klick på plus eller minus i shoppen.*/ 
316	 function syncQuantity() {
317		 let qty = parseInt($('#event_quantity').val());
318		 let wooQty = $('.product-buy').find('input.qty');
319		 console.log("HIT"+qty);
320		 wooQty.val(qty);
321		 
322		 console.log("TEST:"+wooQty.val());
323		 wooQty.trigger('change');
324	 }
325	 
326	 // När variation hittas → sätt rätt antal efter WooCommerce’s reset
327	 $(document).on('found_variation', '.variations_form', function() {
328		 syncQuantity();
329	 });
330	 
331	 // Plus
332	 $(document).on('click', '.event_quantity_participants .plus', function() {
333		 let input = $('#event_quantity');
334		 input.val(parseInt(input.val()) + 1);
335		 syncQuantity();
336	 });
337	 
338	 // Minus
339	 $(document).on('click', '.event_quantity_participants .minus', function() {
340		 let input = $('#event_quantity');
341		 input.val(Math.max(1, parseInt(input.val()) - 1));
342		 syncQuantity();
343	 });
344	 
345	 // Manuell ändring
346	 $(document).on('change', '#event_quantity', syncQuantity);
347	  
348	
349	
350	/**************************
351	* NYTT FÖR AJAX-LADDNING PÅ ARKIVSIDOR
352	***************************/
353	if($('body').hasClass('archive') || $('body').hasClass('search')){
354			
355		let currentPage = parseInt(SiteParameters.startPage) || 1;
356		const maxPages = parseInt(SiteParameters.maxPages) || 1;
357		const queryVars = SiteParameters.queryVars;
358		
359		$('.nextpages').remove(); // Ta bort den befintliga pagineringen
360		$('.buttonholder').append('<div class="ajaxload button">Ladda fler</div>');
361		
362		$('.ajaxload').on('click', function() {
363			
364			if (currentPage < maxPages) {
365				currentPage++;
366				$.ajax({
367					url: adminajaxurl,
368					type: 'POST',
369					data: {
370						action: 'load_more_posts',
371						page: currentPage,
372						query_vars: queryVars
373					},
374					beforeSend: function() {
375						$('.ajaxload').text('Laddar...');
376					},
377					success: function(response) {
378						if (response) {
379							
380							let oldscrollpos = $(window).scrollTop();
381							
382							$('.huvudflodet > .gridholder > .flow > .insideflow').append(response);
383							
384							$('html, body').scrollTop(oldscrollpos);
385							
386							bLazy.revalidate();
387							
388							$('.ajaxload').text('Ladda fler');
389							if (currentPage >= maxPages) {
390								$('.ajaxload').remove();
391							}
392						} else {
393							$('.ajaxload').remove();
394						}
395					}
396				});
397			}
398		});
399	}
400	
401	
402	/**************************
403	* NYTT FÖR EVENT
404	***************************/
405	$('.the_faq_content .content-section h2').click(function(){
406		
407		if($(this).closest('.content-section').hasClass('opened')){
408			$(this).closest('.content-section').removeClass('opened');
409		}
410		else{
411			$(this).closest('.content-section').addClass('opened');
412		}
413	});
414	
415	$('li.spar_item > .leftest').click(function(){
416		
417		if($(this).closest('.spar_item').hasClass('opened')){
418			$(this).closest('.spar_item').removeClass('opened');
419		}
420		else{
421			$(this).closest('.spar_item').addClass('opened');
422		}
423	});
424	
425	$('.container_more h2.event_menu').click(function(){
426		if($(this).parent().hasClass('opened')){
427			$(this).parent().removeClass('opened');
428		}
429		else{
430			$(this).parent().addClass('opened');
431		}
432	});
433	
434	$('.showalltext').click(function(){
435		$(this).parent().addClass('showhidden');
436	});
437	$('.showlesstext').click(function(){
438		$(this).parent().removeClass('showhidden');
439	});
440	
441	
442	
443	/**************************
444	* Klick på blipartner-info
445	***************************/
446	$('.blipartner .button').click(function(){
447		if($(this).closest('.blipartner').hasClass("openedhidden")){
448			$(this).closest('.blipartner').removeClass("openedhidden");
449		}
450		else{
451			$(this).closest('.blipartner').addClass("openedhidden");
452		}
453	});
454	
455	/**************************
456	* Filtrera Whitepapers
457	***************************/
458	$('.filter-whitepapers a').click(function(e){
459		e.preventDefault();
460		
461		if(!$(this).hasClass('active')){
462			
463			
464			$('.flow .insideflow .linediv').remove();
465			
466			$('.filter-whitepapers a').removeClass("active");
467			
468			$(this).addClass("active");
469			
470			
471			if($(this).hasClass('all')){
472				$('.flow .insideflow .element.artpuff').show();
473			}
474			else{
475				var datatoshow = $(this).attr('data-filt');
476				
477				$('.flow .insideflow .element.artpuff').hide();
478				
479				$('.flow .insideflow .element.artpuff.'+datatoshow).show();
480			}
481			
482			$('.flow .insideflow .element.artpuff:visible').each(function(){
483				$('<div class="linediv"></div>').insertAfter($(this));
484			});
485			
486		}
487		
488	});
489	
490	/**************************
491	WOOCOMMERCE MINICART I HEADER
492	***************************/
493	
494	$(".minicart-total-amount").on("mouseover",function(){
495		$(".widget_shopping_cart_content").show();
496	})
497	
498	$(document).on('mouseout', function(e) {
499		var target = $(e.target);
500		
501		if($("#header").has(e.target).length == 0){
502			$(".widget_shopping_cart_content").hide();
503		} 
504	});
505
506	
507	/**************************
508	* CLOSE SUBSCRIBE SPLASH
509	* servicepack 1
510	***************************/
511	//Kollar om vi redan klickat bort den...
512	var subscribe_splash_optimize = getCookie('subscribe_splash_optimize');
513	if($("#subscribe_splash").length > 0){
514		if(subscribe_splash_optimize != ""){
515			//Ta bort den!
516			$("#subscribe_splash").remove();
517		}
518		else{
519			$("#subscribe_splash").show();
520		}
521	}
522	
523	$('#subscribe_splash .closeit').click(function(){
524		setCookie("subscribe_splash_optimize", "1", 3);		
525		$("#subscribe_splash").animate({'height':'0', 'margin-top':'0', 'margin-bottom':'0'}, 400);
526	});
527	
528	
529	/**************************
530	Hantering av eventspårning google analytics
531	***************************/
532	
533	//Huvudmeny
534	$(document).on('click', '#meny_topp ul.menu li a', function(){
535		var category = "Huvudmeny";
536		var label = $(this).text();
537		var value = 1;
538		handleEventClicksWonderfour(category, label, value, 'click');
539	});
540	
541	//Huvudmeny mindre
542	$(document).on('click', '#meny_topp_botten_hoger ul.menu li a', function(){
543		var category = "Huvudmeny mindre";
544		var label = $(this).text();
545		var value = 1;
546		handleEventClicksWonderfour(category, label, value, 'click');
547	});
548	
549
550	//hamburgarmeny
551	$(document).on('click', '.hamburgercontent ul.menu li a', function(){
552		var category = "Hamburgarmeny";
553		var label = $(this).text();
554		var value = 1;
555		handleEventClicksWonderfour(category, label, value, 'click');
556	});
557	
558	//sidfotsmeny
559	$(document).on('click', '#footer ul.menu li a', function(){
560		var category = "Sidfotsmeny";
561		var label = $(this).text();
562		var value = 1;
563		handleEventClicksWonderfour(category, label, value, 'click');
564	});
565	
566	//sidfotsmeny längst ned
567	$(document).on('click', '#footer ul.menu_overall li a', function(){
568		var category = "Sidfotsmeny utanför";
569		var label = $(this).text();
570		var value = 1;
571		handleEventClicksWonderfour(category, label, value, 'click');
572	});
573
574	//Logga in
575	$(document).on('click', 'form.signin .button', function(){
576		var category = "Logga in";
577		var label = "Arkikelsida";
578		if($('body').hasClass('profil')){
579			label = "Profilsida";
580		}
581		var value = 1;
582		
583		handleEventClicksWonderfour(category, label, value, 'click');
584	});
585		
586	//prenumerera-knappen - arktkelsida låst artikel
587	$(document).on('click', 'a.create_signin', function(){
588		var category = "Prenumerera";
589		var label = "Arkikelsida";
590		var value = 1;
591		handleEventClicksWonderfour(category, label, value, 'click');
592	});
593	
594	//prenumerera-knappen - högerspalt
595	$(document).on('click', '.right_prenumeration_info a.button.green', function(){
596		var category = "Prenumerera";
597		var label = "Högerspalt profilsidor";
598		var value = 1;
599		handleEventClicksWonderfour(category, label, value, 'click');
600	});
601	
602	//prenumerera-knappen - modul
603	$(document).on('click', '.premium_puff a.button.green', function(){
604		var category = "Prenumerera";
605		var label = "Modul";
606		var value = 1;
607		handleEventClicksWonderfour(category, label, value, 'click');
608	});
609	
610	//prenumerera-knappen - sidfoten
611	$(document).on('click', '.newsp_image a.button.sub', function(){
612		var category = "Prenumerera";
613		var label = "Sidfot";
614		var value = 1;
615		handleEventClicksWonderfour(category, label, value, 'click');
616	});	
617	
618	
619	//nyhetsbrevsprenumeration - optimize
620	$(document).on('click', '#subscribe_splash a.button', function(){
621		var category = "Nyhetsbrevsplash";
622		var label = "optimize";
623		var value = 1;
624		handleEventClicksWonderfour(category, label, value, 'click');
625	});	
626	
627	
628	/**************************
629	Visar/döljer Högerställd annons
630	***************************/
631	
632	var currenttime = Date.now()/1000; //sekunder
633	var hidein = 40;
634	var removeat = currenttime+hidein;
635	
636	setTimeout(function(){
637		if($(".flowright-outer").length){
638			//Det finns en annons
639			
640			//visningslogik
641			if(!checkFlowAdCookie()){
642				
643				setCookieHour("flowrightad", removeat, 3);
644				
645				$('.flowright-outer').addClass("flowright");
646			}
647			else{
648				//kolla om vi kommit fram till removeat - isåfall visa inte. Annars visa.
649					
650					var check_removeat_time = getCookie("flowrightad");
651					
652					if(currenttime > check_removeat_time){
653						//visa inte annonsen
654					}
655					else{
656						//forsätt att visa annonsen
657						$('.flowright-outer').addClass("flowright");
658					}
659				
660			}
661		}
662	}, 1000);
663
664
665	$("body").delegate(".flowright-remove", "click", function(e) {
666		//Vi sätter removeat-värdet till väldigt länge sedan så att den inte visas i else-satsen ovan.
667		setCookieHour("flowrightad", 1, 12);
668		$(".flowright-outer").addClass("flowback");
669	})		
670	
671	
672	function checkFlowAdCookie() {
673		var acceptcoockies = getCookie("flowrightad");
674		if (acceptcoockies != "") {
675			return true;
676		} else {
677			return false;
678		}
679	}
680
681	function checkPurchaseEtidning() {
682		var acceptcoockies = getCookie("successbuy");
683		if (acceptcoockies != "") {
684			return true;
685		} else {
686			return false;
687		}
688	}
689	
690	
691	/**************************
692	* Markerar inloggad eller ej
693	***************************/
694	getLoggedInCookie();
695		
696	/**************************
697	* Lazyload - bilder
698	***************************/
699	var initializedowl = function(event){		
700		bLazy.revalidate();
701	}
702	
703	//Hämtar in webbplatsens url
704	ajaxurl = SiteParameters.theme_directory+"/ajax.php";
705	adminajaxurl = SiteParameters.adminajax;
706	
707	/**************************
708	* KLICK PÅ ÄMNENf
709	***************************/
710	$('.show_amnen').click(function(){
711		if($(this).closest('.bottom_header').hasClass("showamnen")){
712			
713			$(this).closest('.bottom_header').removeClass("showamnen");
714		}
715		else{
716			$(this).closest('.bottom_header').addClass("showamnen");
717		}
718	});
719	
720	
721	/**************************
722	* KLICK I EPOSTFÄLTET
723	***************************/
724	
725	var isrecaptchaloaded = false;
726	
727	$("body").delegate(".nlform input.nl_email", "focus", function(e) {
728		$(this).closest('.nlform').addClass("focus");		
729			
730			
731		//Flyttat hit 2024-08-12
732		if(!isrecaptchaloaded){
733			
734			var head = document.getElementsByTagName('head')[0]
735			  var script = document.createElement('script')
736			  script.type = 'text/javascript';
737			  script.src = 'https://www.google.com/recaptcha/api.js?render=6LcQG90UAAAAAB080fryMc245mr0Cy0tYs8hZLqg'
738			  head.appendChild(script);
739			
740			isrecaptchaloaded = true;
741			
742			setTimeout(function(){
743				grecaptcha.ready(function () {
744					grecaptcha.execute('6LcQG90UAAAAAB080fryMc245mr0Cy0tYs8hZLqg', { action: 'newsletterform_submit' }).then(function (token) {
745						document.querySelectorAll(".recaptchaResponse").forEach(elem => (elem.value = token));
746					});
747				});
748			}, 500);
749		}
750		
751	});
752	
753	/**************************
754	Detta är validering på formulären för nyhetsbreven!
755	***************************/
756	
757	$("body").delegate(".nlform", "submit", function(e) {
758		//kolla om .pf_name_ex är tom!
759		if($(this).find('.pf_name_ex').val() != ""){
760			e.preventDefault();
761		}
762		else{
763			if($(this).hasClass('submitbyajax')){
764				e.preventDefault();
765				
766				//TODO Lägg ut en loader!
767				var form = $(this);
768				$(form).addClass('loading');
769				$(form).find('.error').html('');
770				$(form).find('.success').html('');
771				
772				//skicka via ajax	
773				var content = $(this).serialize();
774				
775				$.ajax({
776					type: "POST",
777					timeout: 8000,
778			  		url: ajaxurl+"?checknewsletterform=y",
779			  		data: content,
780			  		success : function(htmlresponse) {
781				  		
782				  		if(htmlresponse.indexOf("validsubmission") !== -1){
783					  		//korrekt!
784					  		$(form).removeClass("loading");
785					  		$(form).addClass("thanku");
786					  		$(form).find('.success').html("Tack för din anmälan");
787					  		
788					  		
789					  		setCookie("subscribe_splash_optimize", "1", 365);
790					  		
791					  		
792					  		
793				  		}
794				  		else{
795					  		//Fel!
796					  		$(form).removeClass("loading");
797					  		$(form).find('.error').html(htmlresponse);
798					  		
799				  		}
800					},
801					error:function (xhr, ajaxOptions, thrownError){
802						$(form).removeClass("loading");
803						$(form).find('.error').html("Någonting gick fel. Försök igen senare");
804				    }
805				});
806			}
807		}
808	});
809
810	
811	/**************************
812	* Fix för när det inte finns någon bildtext angiven!
813	***************************/
814	$('.articlepart .entry-content img').each(function(){
815		if($(this).hasClass("alignleft") || $(this).hasClass("alignright") || $(this).hasClass("aligncenter") || $(this).hasClass("alignnone")){
816			var theclass = $(this).attr('class');
817			$(this).removeAttr("class");
818
819			//console.log($(this).parent().prop('nodeName'));
820			if($(this).parent().prop('nodeName') == "A"){
821				
822
823				$(this).parent().parent().wrap("<figure class='"+theclass+"'></figure>");
824			}
825			else{
826				$(this).parent().wrap("<figure class='"+theclass+"'></figure>");
827			}
828		}
829	});
830	
831	/**************************
832	* Fix för när bilden är smalare än 340px
833	***************************/
834	$('.entry-content .alignright img').each(function(){
835		var widthattr = $(this).attr('width');
836		
837		//Kollar om width finns.
838		if (typeof widthattr !== 'undefined' && widthattr !== false) {
839			if(widthattr < 340){
840				
841				$(this).closest('figure').width(widthattr);
842			}
843		}
844	});
845	$('.entry-content .alignleft img').each(function(){
846		var widthattr = $(this).attr('width');
847		
848		//Kollar om width finns.
849		if (typeof widthattr !== 'undefined' && widthattr !== false) {
850			if(widthattr < 340){
851				
852				$(this).closest('figure').width(widthattr);
853			}
854		}
855	});
856	
857		
858	
859	/**************************
860	* LADDA FLER PÅ STARTSIDAN
861	***************************/
862	
863	var paginering = 0;
864	$('.mainload').click(function(e){
865		
866		e.preventDefault();
867 		
868		if(!$(this).hasClass("active")){
869			$(this).addClass("active");
870			
871			var loaderdiv = '';
872			
873			var premium = "nej";
874			if($(this).hasClass('premiumb')){
875				premium = "ja";
876			}
877			
878			loaderdiv += '<div class="mainloader">';
879			loaderdiv += '<div class="icon"></div>';
880			loaderdiv += '</div>';
881			
882			$('.huvudflodet .flow .insideflow').append(loaderdiv);		
883			
884			$.ajax({
885				type: "POST",
886				timeout: 4000,
887				dataType: 'json',
888		  		url: ajaxurl+"?flowmore=y",
889		  		data: {paginering: paginering, premium:premium},
890		  		success : function(htmlresponse) {
891			  		
892			  		if(htmlresponse[1] < 1){
893				  		$('.mainload').css({'visibility':'hidden'});
894			  		}
895			  		
896					$('.mainload').removeClass("active");
897					$('.huvudflodet .flow .mainloader').remove();
898					$('.huvudflodet .flow .insideflow').append(htmlresponse[0]);
899					
900					bLazy.revalidate();
901										
902					paginering++;
903				},
904				error:function (xhr, ajaxOptions, thrownError){
905					$('.huvudflodet .flow .mainloader').remove();
906			        $('.mainload').removeClass("active");
907			    }
908			});
909		}
910		
911	});
912	
913	
914	/**************************
915	* KLICK PÅ MINIMERA RELATERADBILD
916	***************************/
917	$('.closetip').click(function(){
918		if($(this).hasClass("clicked")){
919			$(this).removeClass("clicked");			
920			$(this).closest('.next_articles_readthis').removeClass("hideimg");				
921			
922			$(this).closest('.next_articles_readthis .alsoread').removeAttr("style");
923		}
924		else{
925			
926			$(this).addClass("clicked");
927			$(this).closest('.next_articles_readthis').addClass("hideimg");	
928			
929			var height = $(this).closest('.next_articles_readthis .alsoread').height();
930			//console.debug(height);
931			$(this).closest('.next_articles_readthis .alsoread').animate({'bottom':'-'+(height-15)}, 300);
932			
933		}
934		
935	});
936	
937	
938	
939	/**************************
940	* LOCKED
941	***************************/
942	$("body").delegate(".already_signin", "click", function(e) {
943		e.preventDefault();
944		$(this).closest('.mw').find('.already_signin').hide();
945		$(this).closest('.mw').find('.signin').show();
946		$(this).closest('.mw').find('.create_userform').hide();
947		$(this).closest('.mw').find('.create_signin').show();
948	});
949		
950	//Gör detta på sidor som har en "lockedarticle"
951	if($('body').hasClass('single') || $('body').hasClass('page')){
952		
953			
954		if($('article').hasClass('closed')){
955			
956			
957			//NYTT 2018-01-22 
958			var thepostid = $('article').attr('id').replace("post-", "");
959			
960			//Inloggad eller ej
961			var data = {
962			    action: 'is_user_logged_in',
963			    thepostid:thepostid
964			};
965
966			//hs helt ny hsnew
967			$.ajax({
968				type: "POST",
969				timeout: 8000, //Borde vara typ 8000
970				dataType: 'json',
971		  		url: adminajaxurl,
972		  		data: data,
973		  		success : function(response) {
974			  		
975			  		if(response[0] == 'yes') {
976				  						  		
977				  		if(response[1] == 'fel'){
978					  		
979					  		$("article").addClass('loggedinbuterror');
980					  		
981					  		//inform_google_about_status(false);
982					  		
983				  		}
984				  		else{
985					  		///Inloggad
986					        $("article").each(function(){
987								$(this).removeClass('closed');
988								
989								
990								const encryptionKey = CryptoJS.enc.Utf8.parse('29s348378soi7def092345ls99a8hyef');
991								
992								const lockedDiv = $(this).find(".lockedpart .encrypted");
993								/*
994								const encryptedDataB64 = lockedDiv.html(); // Base64 (IV + ciphertext)
995								
996								const encryptedData = CryptoJS.enc.Base64.parse(encryptedDataB64);
997								const iv = CryptoJS.lib.WordArray.create(encryptedData.words.slice(0, 4));
998								const ciphertext = CryptoJS.lib.WordArray.create(encryptedData.words.slice(4), encryptedData.sigBytes - 16);
999								
1000								const decrypted = CryptoJS.AES.decrypt(
1001								  { ciphertext: ciphertext },
1002								  encryptionKey,
1003								  { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 }
1004								);
1005								
1006								const decryptedText = decrypted.toString(CryptoJS.enc.Utf8);
1007								lockedDiv.html(decryptedText);
1008								*/
1009								reviveAsync["e319cba4eae4280b0662b5e8f3026c4a"].refresh();
1010								
1011								//alert("Innehållet är upplåst!");
1012								
1013								//inform_google_about_status(true);
1014								
1015								bLazy.revalidate();
1016								
1017								console.log("går hit1");
1018								
1019								FastLinks.init();
1020								
1021								console.log("går hit2");
1022								
1023							});
1024				  		}
1025				  		
1026				  	}
1027				  	/**************************
1028					* NYTT 2021 WC SHOP 
1029					När ett köp av e-tidning sparar vi ner en cookie i 72H genom functions, här ska vi titta efter denna cookie, och därefter öppna upp artiklar.
1030					***************************/
1031				  	else if(checkPurchaseEtidning()) {
1032						///Inloggad
1033						$("article").each(function(){
1034							$(this).removeClass('closed');
1035							
1036							
1037							const encryptionKey = CryptoJS.enc.Utf8.parse('29s348378soi7def092345ls99a8hyef');
1038							
1039							const lockedDiv = $(this).find(".lockedpart .encrypted");
1040							/*
1041							const encryptedDataB64 = lockedDiv.html(); // Base64 (IV + ciphertext)
1042							
1043							const encryptedData = CryptoJS.enc.Base64.parse(encryptedDataB64);
1044							const iv = CryptoJS.lib.WordArray.create(encryptedData.words.slice(0, 4));
1045							const ciphertext = CryptoJS.lib.WordArray.create(encryptedData.words.slice(4), encryptedData.sigBytes - 16);
1046							
1047							const decrypted = CryptoJS.AES.decrypt(
1048							  { ciphertext: ciphertext },
1049							  encryptionKey,
1050							  { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 }
1051							);
1052							
1053							const decryptedText = decrypted.toString(CryptoJS.enc.Utf8);
1054							lockedDiv.html(decryptedText);
1055							*/
1056							
1057							reviveAsync["e319cba4eae4280b0662b5e8f3026c4a"].refresh();
1058							
1059							//alert("Innehållet är upplåst!");
1060							
1061							//inform_google_about_status(true);
1062							
1063							bLazy.revalidate();
1064							
1065							FastLinks.init();
1066							
1067						});
1068					}
1069				  	else{
1070					  	if(response[0] == "no"){ //hsnew
1071					        $("article").addClass('closed');
1072					        
1073							
1074							//Nytt 2026-02-15
1075							$('article.closed .ad.parallax').each(function () {
1076								this.style.setProperty('display', 'block', 'important');
1077							});
1078							
1079							reviveAsync["e319cba4eae4280b0662b5e8f3026c4a"].refresh(); //Ladda in annons!
1080							
1081					        //inform_google_about_status(false);
1082							
1083							
1084					    }
1085					    else{
1086
1087					    }
1088				  	}
1089
1090				},
1091				error:function (xhr, ajaxOptions, thrownError){
1092					alert("Var vänlig ladda om sidan. Det gick inte att kontrollera om du är inloggad eller ej.");
1093			    }
1094			});			
1095		}
1096		else{
1097			console.log("går hit4");
1098			FastLinks.init();
1099		}
1100	}
1101	
1102	
1103    
1104    /******
1105	* MODULER STARTSIDAN
1106	*******/
1107    var w4relateradoptions = {
1108		loop: false,
1109		responsiveClass:true,
1110		responsive:{
1111			0:{
1112			    items:1,
1113				dots:false,
1114				nav:false,
1115			    stagePadding: 40,
1116			    verticalSwiping: false
1117			},
1118			500:{
1119			    items:2,
1120				dots:false,
1121				nav:false,
1122			    stagePadding: 40,
1123   			    verticalSwiping: false
1124			},
1125			1024:{
1126			    items:3,
1127				dots:false,
1128				nav:false,
1129			    stagePadding: 0,
1130			    verticalSwiping: false			    
1131			},
1132			1080:{
1133			    items:4,
1134				dots:false,
1135				nav:false,
1136			    stagePadding: 0
1137			}
1138		},
1139		autoHeight:false,
1140		navClass: ["owl-prev alt bgspr","owl-next alt bgspr"],
1141		onInitialized: initializedowl,
1142		onTranslated: initializedowl
1143
1144	};
1145    
1146    $('.black_widget .owl-carousel').owlCarousel(w4relateradoptions);
1147    
1148    
1149     var w4relateradoptions = {
1150		loop: false,
1151		responsiveClass:true,
1152		responsive:{
1153			0:{
1154			    items:1,
1155				dots:false,
1156				nav:false,
1157			    stagePadding: 40,
1158			    verticalSwiping: false
1159			},
1160			500:{
1161			    items:2,
1162				dots:false,
1163				nav:false,
1164			    stagePadding: 40,
1165   			    verticalSwiping: false
1166			},
1167			1024:{
1168			    items:3,
1169				dots:false,
1170				nav:false,
1171			    stagePadding: 0,
1172			    verticalSwiping: false			    
1173			}
1174		},
1175		autoHeight:false,
1176		navClass: ["owl-prev alt bgspr","owl-next alt bgspr"],
1177		onInitialized: initializedowl,
1178		onTranslated: initializedowl
1179
1180	};
1181    
1182    $('.top_list .owl-carousel').owlCarousel(w4relateradoptions);
1183       
1184    /******
1185	* MODULER STARTSIDAN
1186	*******/
1187    var w4senaste_options = {
1188		loop: false,
1189		responsiveClass:true,
1190		responsive:{
1191			0:{
1192			    items:1,
1193				dots:false,
1194				nav:false,
1195			    stagePadding: 40,
1196			    verticalSwiping: false
1197			},
1198			500:{
1199			    items:2,
1200				dots:false,
1201				nav:false,
1202			    stagePadding: 40,
1203   			    verticalSwiping: false
1204			},
1205			1024:{
1206			    items:3,
1207				dots:false,
1208				nav:false,
1209			    stagePadding: 0,
1210			    verticalSwiping: false			    
1211			},
1212			1080:{
1213			    items:4,
1214				dots:false,
1215				nav:false,
1216			    stagePadding: 0
1217			}
1218		},
1219		autoHeight:false,
1220		navClass: ["owl-prev alt bgspr","owl-next alt bgspr"],
1221		onInitialized: initializedowl,
1222		onTranslated: initializedowl
1223
1224	};
1225    
1226    $('.mobile_latest.owl-carousel').owlCarousel(w4senaste_options);
1227    
1228    
1229		
1230	/****
1231	* Minimerar faktarutor om man klickar utanför
1232	*****/
1233	$(document).bind('mouseup', function(e) {
1234		var target = $(e.target);
1235		
1236		//Minimera faktarutorna vid klick utanför
1237		if($('.expandingbox').has(e.target).length == 0){
1238			$(".expandingbox .cloned").remove();
1239			$(".expandingbox .wrapus").addClass('minify').removeClass('expanded');
1240			$(".expandingbox .wrapus").removeClass('wrapus');
1241			$(".expandingbox .factbox").removeAttr('style');
1242			$(".expandingbox .factbox").unwrap();
1243		}
1244	});	
1245	
1246	
1247	/**************************
1248	* Faktarutor - expandering - minimering
1249	***************************/
1250	$("body").delegate(".factbox .expand", "click", function(e) {
1251		if($(this).parents('.factbox').hasClass("expanded")){
1252	
1253			$(".expandingbox .cloned").remove();
1254			$(".expandingbox .wrapus").addClass('minify').removeClass('expanded');
1255			$(".expandingbox .wrapus").removeClass('wrapus');
1256			$(".expandingbox .factbox").removeAttr('style');
1257			$(".expandingbox .factbox").unwrap();
1258		}
1259		else{
1260			$(".expandingbox .cloned").remove();
1261			$(".expandingbox .wrapus").addClass('minify').removeClass('expanded');
1262			$(".expandingbox .wrapus").removeClass('wrapus');
1263			$(".expandingbox .factbox").removeAttr('style');
1264			$(".expandingbox .factbox").unwrap();
1265			
1266	
1267			$(this).parents('.factbox').addClass('wrapus').clone().addClass('cloned').insertBefore($(this).parents('.factbox'));
1268	
1269			$('.wrapus').wrapAll("<div class='expandingbox' />");
1270			var tempheight = $(this).parents('.factbox').height();
1271			
1272			$(this).parents('.factbox').removeClass("minify");
1273			$(this).parents('.factbox').addClass("expanded");
1274			var toheight = $(this).parents('.factbox').height();
1275			
1276			$(this).parents('.factbox').height(tempheight);
1277			
1278			$(this).parents('.factbox').animate({height: toheight}, 200, function(){
1279			
1280			});
1281		}
1282		
1283	});
1284    
1285    /**********************
1286	* TILLÄGG FÖR BILDER UTAN BILDTEXT
1287	**********************/
1288	$('article .main-entry-container img').each(function(){
1289		if(!$(this).parent().parent().hasClass('ad') && $(this).parents("figure").length != 1){
1290
1291			var style = "";
1292			var classes = $(this).attr('class');
1293			var width = $(this).attr('width')
1294			style = "width: "+width+"px;";
1295			
1296			$(this).removeAttr('class');
1297			$(this).removeAttr('width');
1298			
1299			if($(this).parents("a").length != 1){
1300				$(this).wrap("<figure style='"+style+"' class='"+classes+"'></figure>"); //hs new
1301			}
1302			else{
1303				$(this).closest("a").wrap("<figure style='"+style+"' class='"+classes+"'></figure>"); //hs new					
1304			}
1305			
1306		}
1307	});
1308    
1309    /**********************
1310	* IKONER FÖR BILDER MED LÄNKAR I BRÖDTEXT
1311	**********************/
1312	$('article .entry-content a:not(.hasim) img').each(function(){
1313		
1314		if(!$(this).parent().parent().parent().hasClass('ad')){
1315			//Kollar om det är en bild
1316			var testifimage = $(this).closest('a').attr('href').toLowerCase();
1317			if(testifimage.indexOf(".jpg") > -1 || testifimage.indexOf(".jpeg") > -1 || testifimage.indexOf(".png") > -1 || testifimage.indexOf(".gif") > -1){
1318				$(this).closest('a').addClass("imagelink");
1319			}
1320			else{
1321				//Kollar om det är en utgående länk
1322				var attr = $(this).closest('a').attr('target');
1323				
1324				var isoutbound = false;
1325				if (typeof attr !== typeof undefined && attr !== false) {
1326					if(attr == "_blank"){
1327						isoutbound = true;
1328						$(this).closest('a').addClass("outboundlink");
1329					}
1330				}
1331				if(!isoutbound){
1332					$(this).closest('a').addClass("internallink");
1333				}
1334			}
1335		}
1336		
1337	});
1338
1339	/**************************
1340	* KLICK PÅ EN BILD I BRÖDTEXTEN
1341	***************************/		
1342	$("body").delegate(".imagelink", "click", function(e) {
1343		e.preventDefault();
1344		
1345	
1346		var imageurl = $(this).attr('href');
1347		var meta = $(this).parent().find('.wp-caption-text').html();
1348		var alt = $(this).find('img').attr('alt');
1349		
1350		if(meta == "undefined"){
1351			meta = "";
1352		}
1353		if(alt == "undefined"){
1354			alt = "";
1355		}		
1356		
1357		$('<div class="image"><img src="'+imageurl+'" alt="'+alt+'" /><figcaption class="wp-caption-text">'+meta+'</figcaption></div>').appendTo($('.aboveimage.manual .cell'));
1358		
1359		$('.aboveimage.manual').addClass("show");
1360		
1361		setTimeout(function(){
1362			$('.aboveimage.manual').addClass("bg");
1363		}, 250);		
1364		
1365	});
1366    
1367		
1368	$("body").delegate(".aboveimage .close", "click", function(e) {
1369		
1370		if($(this).closest('.aboveimage').hasClass('takeover')){
1371			
1372			if($(this).closest('.aboveimage').hasClass('takeoverevent')){
1373				setCookieHour("pausertakeover_event", "shown", 168);
1374			}
1375			else{
1376				setCookieHour("pausertakeover", "shown", 2);	
1377			}
1378	
1379			$('.aboveimage.takeover').hide();
1380		}
1381		else{
1382			$('.aboveimage').removeClass('show');
1383			
1384			setTimeout(function(){
1385				$('.aboveimage').removeClass('bg');
1386				$('.aboveimage .cell').html('');
1387			}, 300);
1388		}
1389	});
1390	
1391	$("body").delegate(".aboveimage.takeover", "click", function(e) {		
1392		$('.aboveimage.takeover').hide();
1393		
1394		if($('.aboveimage.takeover').hasClass("takeoverevent")){
1395			setCookieHour("pausertakeover_event", "shown", 168);
1396		}
1397		else{
1398			setCookieHour("pausertakeover", "shown", 2);	
1399		}
1400		
1401	});
1402	
1403	
1404	/***************************
1405	* BRÖDTEXTBILDSPEL
1406	***************************/	
1407	$("figure.wp-block-gallery").each(function(){
1408		$(this).addClass("owl-carousel");
1409		
1410		if($('article').first().hasClass('eventpage')){
1411			$(this).owlCarousel({
1412				startPosition: 0,
1413				loop: true,
1414				autoHeight:true,
1415				responsiveClass:true,
1416				responsive:{
1417					0:{
1418						items:1,
1419						dots:true,
1420						nav:false,
1421						stagePadding: 50
1422					}
1423				},
1424				navClass: ["owl-prev bgspr","owl-next bgspr"],
1425				onInitialized: initializedowl,
1426				onTranslated: initializedowl
1427			});
1428		}
1429		else{
1430			$(this).owlCarousel({
1431				startPosition: 0,
1432				loop: false,
1433				autoHeight:true,
1434				responsiveClass:true,
1435				responsive:{
1436					0:{
1437						items:1,
1438						dots:true,
1439						nav:false,
1440						stagePadding: 0
1441					},
1442					782:{
1443						items:1,
1444						dots:true,
1445						nav:true,				    
1446						stagePadding: 0
1447					}
1448				},
1449				navClass: ["owl-prev bgspr","owl-next bgspr"],
1450				onInitialized: initializedowl,
1451				onTranslated: initializedowl
1452			});
1453		}
1454		
1455	});
1456	
1457	/**************************
1458	* Få bukt på videor i brödtexten
1459	***************************/
1460	if ($(".entry-content").length) {
1461		$(".entry-content").fitVids();
1462	}
1463	
1464	
1465						
1466	/********************
1467	 * BLOCKQUOTE
1468	 ********************/
1469	$('blockquote .smaller').parent().parent().addClass("moremargin");
1470	
1471	
1472	/**********************
1473	* ANKARLÄNKAR
1474	**********************/
1475	$('a[href*=\\#]').on('click', function(event){
1476		var href = $(this.hash);     
1477		href = href[0].id;
1478	    event.preventDefault();
1479		
1480		if($(this).hasClass('noscroll')){
1481			
1482		}
1483	    else{
1484	    	$('html,body').animate({scrollTop:$(this.hash).offset().top-$('#header').height()}, 500, function(){
1485				
1486				if($(this).hasClass('openparent')){
1487					$(this).parent().addClass("opened");
1488					$(this).closest('.container_more').addClass("opened");
1489				}
1490				else{
1491					$(this).addClass("opened"); //detta är för direktlänkar till program etc;  
1492				}
1493	    	});
1494		}
1495	});
1496	
1497	
1498	/**********************
1499	* Klick på menyknappen
1500	**********************/
1501	$(".showmenubtn").click(function(event) {
1502		
1503		if (!$(this).hasClass('clicked')) {
1504            $(".showmenubtn").addClass('clicked');
1505            
1506            $('#header').addClass('falloutopen');
1507            $('#header').removeClass('whitebg');
1508            
1509                    
1510            $('.hamburgercontent').slideToggle(200, function(){
1511            	$(this).toggleClass('open');    
1512            });
1513	        
1514	        //TA BORT SÖKET!
1515	        $(".showsearch").removeClass('clicked');
1516	        
1517            if($('.searchcontent').hasClass("open")){
1518		        $('.searchcontent').slideToggle(200, function(){
1519		            $(this).toggleClass('open');    
1520	            });
1521	        }
1522            
1523        }
1524        else{
1525	        $(".showmenubtn").removeClass('clicked');
1526	        
1527			$('#header').removeClass('falloutopen');
1528            $('#header').addClass('whitebg');
1529
1530	        
1531	        
1532		    $('.hamburgercontent').slideToggle(200, function(){
1533	            $(this).toggleClass('open');    
1534            });    
1535        }
1536	});
1537	
1538	
1539	/**********************
1540	* Klick på sökknappen
1541	**********************/
1542	$(".showsearch").click(function(event) {
1543		
1544		if (!$(".showsearch").hasClass('clicked')) {
1545            $(".showsearch").addClass('clicked');
1546            
1547            $('#header').addClass('falloutopen');
1548            $('#header').removeClass('whitebg');
1549            
1550            
1551            $('.searchcontent').slideToggle(200, function(){
1552	            $(this).toggleClass('open');    
1553            });
1554			
1555            
1556            //TA BORT HAMBURGAREN!
1557	        $(".showmenubtn").removeClass('clicked');
1558	        
1559            if($('.hamburgercontent').hasClass("open")){
1560		        $('.hamburgercontent').slideToggle(200, function(){
1561		            $(this).toggleClass('open');    
1562	            });
1563	        }
1564            
1565        }
1566        else{
1567	        $(".showsearch").removeClass('clicked');
1568	        
1569	        
1570			$('#header').removeClass('falloutopen');
1571            $('#header').addClass('whitebg');
1572
1573	        
1574
1575	        $('.searchcontent').slideToggle(200, function(){
1576	            $(this).toggleClass('open');    
1577            });
1578
1579        }
1580	});
1581	
1582	
1583	/*************************
1584	* KLICK UTANFÖR
1585	**************************/
1586		
1587	$(document).bind('mouseup', function(e) {
1588		var target = $(e.target);
1589		
1590		if($(".hamburgercontent").has(e.target).length == 0 && $(".searchcontent").has(e.target).length == 0 && $(".showmenubtn").has(e.target).length == 0 && $(".showsearch").has(e.target).length == 0){
1591			
1592			if($('.showmenubtn').hasClass("clicked") || $('.showsearch').hasClass("clicked")){
1593				$('#header').removeClass('falloutopen');
1594	            $('#header').addClass('whitebg');
1595			}
1596			
1597			if($('.showmenubtn').hasClass("clicked")){
1598				$('.showmenubtn').removeClass("clicked");		        
1599            }
1600            if($('.hamburgercontent').hasClass("open")){
1601			    $('.hamburgercontent').slideToggle(200, function(){
1602		            $(this).toggleClass('open');    
1603	            });    
1604	        }
1605            
1606            if($('.showsearch').hasClass("clicked")){
1607	            $('.showsearch').removeClass("clicked");
1608		    }
1609		    if($('.searchcontent').hasClass("open")){
1610		        $('.searchcontent').slideToggle(200, function(){
1611		            $(this).toggleClass('open');    
1612	            });
1613	        }
1614            
1615		}
1616
1617	});
1618	
1619	
1620		
1621	/**********************
1622	* ONLOAD -SCROLL
1623	**********************/
1624	if (location.hash) {		
1625        var target = $(location.hash);
1626	  	target = target.length ? target : $('[name=' + target.hash.slice(1) +']');
1627	  	if (target.length) {
1628			 
1629			 
1630			if($(target).hasClass('openparent')){
1631				$(target).parent().addClass("opened");
1632				$(target).closest('.container_more').addClass("opened");
1633			}
1634			else{
1635				$(target).addClass("opened"); //detta är för direktlänkar till program etc;  
1636			}
1637			
1638			  
1639		  	
1640	    	$('html,body').animate({
1641	      		scrollTop: target.offset().top-$('#header').height()
1642	    	}, 1000);
1643	  	}
1644    }
1645    else{
1646
1647    }
1648    
1649    
1650    /**********************
1651	 * PARALLAXTHINGS
1652	**********************/
1653	var lastst = 0;	
1654	
1655	$('.utfallande.parallax').each(function(){		
1656		$(this).addClass("hideorgimage");
1657		var thesrc = $(this).find('img').attr('src');
1658		
1659		if(!$(this).hasClass("largertextontop")){
1660			$(this).append('<div class="bgimgparallax" style="background-image: url('+thesrc+');"></div>');
1661		}
1662		
1663		$(this).find('.bgimgparallax').data('startposition', 0);
1664	});
1665	
1666	/***************************
1667	* CLICK PÅ NEXT
1668	****************************/
1669	$('.nextarticle_teaser a').click(function(e){
1670		var hamta_id = $(this).attr('data-id');
1671		
1672		if($('.infiniteholder > article#post-'+hamta_id).length > 0){
1673			e.preventDefault();
1674			
1675			$('html,body').animate({scrollTop:$('.infiniteholder > article#post-'+hamta_id).offset().top-$('#header').height()}, 500, function(){
1676				
1677			});
1678			
1679			
1680		}
1681		else{
1682			//GÅR TILL ARTIKELN I FRÅGA!
1683		}
1684		
1685	});
1686	
1687	
1688	/*NYTT 2024-06-17 - flyttar innehåll i högerspalten om det behövs*/
1689	if($('.flow_sidebar.movetohere').length > 0){
1690		setTimeout(function(){		
1691			var tempheight = $('.flow_sidebar.movetohere').height()-20;
1692			
1693			var filled = false;
1694		
1695			while(tempheight < $('.flow_sidebar.movetohere').height() && !filled){
1696				
1697				if($('.huvudartikeln.parallaxafter .flow_sidebar .insideflow .sidebar.widget').first().height()+$('.flow_sidebar.movetohere .insideflow').height() < tempheight){
1698					
1699					$('.huvudartikeln.parallaxafter .flow_sidebar .insideflow .sidebar.widget').first().appendTo('.flow_sidebar.movetohere .insideflow');
1700					if($('.huvudartikeln.parallaxafter .flow_sidebar .insideflow .sidebar.widget').length < 1){
1701						filled = true;
1702						//alert("tömd");
1703					}
1704				}
1705				else{
1706					//alert("blir för hög!");
1707					filled = true;
1708				}
1709			}
1710			
1711			//Ladda om annonser
1712			//Ladda om blazy
1713			bLazy.revalidate();
1714			//DEVEN: 47a8e97cef59721ef27aab10037ebcda
1715			//LIVE: e319cba4eae4280b0662b5e8f3026c4a
1716			reviveAsync["e319cba4eae4280b0662b5e8f3026c4a"].refresh();
1717		}, 900);
1718	}
1719	
1720	
1721			
1722	/***************************
1723	* VISAR SIDHUVUDET
1724	****************************/
1725	
1726	var startposition = 0;	
1727	var lasthead = 0;
1728	var lastherohedlinepos = 0;
1729	
1730	//Infinite
1731	var issinglearticle = false;
1732	var arrayofdisplayedarticleids = [];
1733	var arrayofheightpositions = [];
1734	var arrayofurls = [window.location.href];
1735	var arrayofgaurls  = [window.location.href];
1736	var arrayoftitles = [$('title').text()];
1737	var thisartid = 0;
1738	var loading = false;
1739	var activearticle = 0;
1740	var activecheck = 0;
1741	var numpostsleft = 8;
1742	
1743	var firstnativearticle = 0;
1744	
1745	//Nytt 2024-09-23
1746	if($('body').hasClass("single-post") || $('body').hasClass("single-dagens")){
1747		issinglearticle = true;
1748		thisartid = $('article').attr('id').replace("post-", "");
1749		arrayofdisplayedarticleids.push(thisartid);
1750	}
1751	
1752	var hideshowbtnlogic = false;
1753	var posofbutton = 0;
1754	if($('.lagebg_thing .large_contents .bookbtn').length > 0){
1755		hideshowbtnlogic = true;
1756		posofbutton = $('.lagebg_thing .large_contents .bookbtn').offset().top;
1757	}
1758	
1759	$( window ).scroll(function(){
1760				
1761		var scrollposition = $(window).scrollTop();
1762				
1763		if(hideshowbtnlogic){	
1764			if(scrollposition > (posofbutton+($('header').height()*1))){
1765				if($('.lagebg_thing .large_contents').hasClass("hidebtn") && !$('.lagebg_thing .large_contents').hasClass("fixedbtn")){
1766					$('.lagebg_thing .large_contents').removeClass("hidebtn");
1767					$('.lagebg_thing .large_contents').addClass("fixedbtn");
1768				}
1769			}		
1770			else if(scrollposition > (posofbutton-($('header').height()*2))){
1771				if(!$('.lagebg_thing .large_contents').hasClass("hidebtn") && !$('.lagebg_thing .large_contents').hasClass("fixedbtn")){
1772					$('.lagebg_thing .large_contents').addClass("hidebtn");
1773				}
1774			}
1775			else{
1776				if($('.lagebg_thing .large_contents').hasClass("hidebtn") || $('.lagebg_thing .large_contents').hasClass("fixedbtn")){
1777					$('.lagebg_thing .large_contents').removeClass("hidebtn");
1778					$('.lagebg_thing .large_contents').removeClass("fixedbtn");
1779				}
1780			}
1781		}
1782				
1783		/**********************
1784    	* SCROLLHUVUDET
1785    	**********************/
1786        var scrollposheader = $(this).scrollTop();
1787        
1788        //Dölj eller visa sidhuvudet
1789        if($('body').hasClass("home")){
1790	        if(scrollposheader > $('#header').height()){
1791		        if(!$('#header').hasClass('falloutopen')){
1792			        $('#header').addClass('whitebg');
1793		        }
1794	        }
1795	        else{
1796			    $('#header').removeClass('whitebg');    
1797	        }
1798        }
1799        lasthead = scrollposheader;
1800		
1801		
1802		/**********************		
1803		* Parallax på bilder i brödet
1804		***********************/
1805
1806		$('.utfallande.parallax .bgimgparallax').each(function(){
1807
1808			if($(this).is(':appeared')){
1809				
1810				var newpos = 0;
1811
1812				var heightofimgcontainer = $(this).parent().height();
1813				var heightofwindow = $(window).height();
1814				var positionofcontaineronpage = $(this).parent().offset().top;
1815				
1816				
1817				startposition = $(this).data('startposition');
1818				if(startposition == 0){
1819					startposition = positionofcontaineronpage-heightofwindow;
1820					$(this).data('startposition', startposition);
1821				}
1822				var newpos = startposition-scrollposition;
1823				
1824				var delamed = heightofwindow+heightofimgcontainer;
1825
1826				var newpos = newpos/delamed;
1827				
1828                $(this).css({'background-position': '50% ' + Math.abs(newpos*100) + '%'});
1829				
1830			}
1831			else{
1832
1833			}
1834			
1835		});
1836		
1837		
1838		/**********************		
1839		* Fler artiklar och läs också!
1840		***********************/
1841		if($('.next_articles_readthis').length > 0){
1842			
1843			temptestposition = $('.w4_related').offset();
1844			//Efter en sjättedel så visas det!
1845			temptestpositionarticle = $('.container.articlepart').height()/6;
1846			
1847			if($(document).scrollTop()+$(window).height() > temptestposition.top){
1848				//Hide it
1849				$('.next_articles_readthis').removeClass("show");
1850			}
1851			else{
1852				//show, but only if we have scrolled down a bit
1853				if($(document).scrollTop() > temptestpositionarticle){
1854					if(!$('.next_articles_readthis').hasClass("show")){
1855						$('.next_articles_readthis').addClass("show");							
1856					}						
1857				}
1858				else{
1859					$('.next_articles_readthis').removeClass("show");
1860				}
1861			}			
1862		}
1863
1864		/**********************		
1865		* INFINITESCROLL
1866		***********************/
1867		if(issinglearticle){
1868			arrayofheightpositions = [];
1869			$('#main article').each(function(){
1870				var temp = $(this).offset();
1871				
1872				arrayofheightpositions.push([temp.top, temp.top+$(this).height()]);
1873				
1874			});
1875			
1876			
1877			//Kolla vilken scrollthingy vi är innuti
1878			for(var i = 0; i < arrayofheightpositions.length; i++){
1879				
1880				if($(window).scrollTop() > arrayofheightpositions[i][0] && $(window).scrollTop() < arrayofheightpositions[i][1]){
1881					
1882					//Denna är aktiv!
1883					activecheck = i;
1884					
1885					//kolla om vi kommit mer än hälften och är på sista - isåfall ladda en till artikel! 8 är 8 inklusive den som visas!
1886					if(i == arrayofheightpositions.length-1 && !loading && arrayofdisplayedarticleids.length < 8 && numpostsleft > 0){
1887						
1888						
1889						var temp = arrayofheightpositions[i][1]/2;
1890						if($(window).scrollTop() > temp){
1891							loading = true;
1892							//ladda en till artikel
1893							
1894							$('.loadernewarticletext').addClass("loading");
1895							
1896							$.ajax({
1897								type: "POST",
1898								timeout: 4000,
1899								dataType: 'json',
1900								  url: ajaxurl+"?loadart=1",
1901								  data: {arrayofdisplayedarticleids: arrayofdisplayedarticleids},
1902								  success : function(htmlresponse) {
1903									  
1904									  //Lägger till idt, urlen, etc
1905									  arrayofdisplayedarticleids.push(htmlresponse[1]);
1906									  arrayofurls.push(htmlresponse[2]);
1907									  arrayoftitles.push(htmlresponse[4]);
1908									  numpostsleft = htmlresponse[3];
1909									  
1910									  //lägger ut htmlen
1911									  $(htmlresponse[0]).appendTo( ".infiniteholder" );
1912									  bLazy.revalidate();
1913									  														
1914									  loading = false;
1915									
1916									  $('.loadernewarticletext').removeClass("loading");
1917									  
1918									  /*FIX FÖR LÅSTA ARTIKLAR SOM HÄMTATS SÅHÄR*/
1919									  if($('.infiniteholder article:last').hasClass('closed')){
1920										  var thepostid = $('.infiniteholder article:last').attr('id').replace("post-", "");
1921										  
1922										  //Inloggad eller ej
1923										  var data = {
1924											  action: 'is_user_logged_in',
1925											  thepostid:thepostid
1926										  };
1927								  
1928										  //hs helt ny hsnew
1929										  $.ajax({
1930											  type: "POST",
1931											  timeout: 8000, //Borde vara typ 8000
1932											  dataType: 'json',
1933												url: adminajaxurl,
1934												data: data,
1935												success : function(response) {
1936													
1937													if(response[0] == 'yes') {
1938																				  
1939														if(response[1] == 'fel'){
1940															
1941															$("article#post-"+thepostid).addClass('loggedinbuterror');
1942															
1943														}
1944														else{
1945															
1946															if($("article#post-"+thepostid).hasClass('closed')){
1947															
1948																$("article#post-"+thepostid).removeClass('closed');
1949																
1950															
1951																const encryptionKey = CryptoJS.enc.Utf8.parse('29s348378soi7def092345ls99a8hyef');
1952																
1953																const lockedDiv = $("article#post-"+thepostid).find(".lockedpart .encrypted");
1954																/*
1955																const encryptedDataB64 = lockedDiv.html(); // Base64 (IV + ciphertext)
1956																
1957																const encryptedData = CryptoJS.enc.Base64.parse(encryptedDataB64);
1958																const iv = CryptoJS.lib.WordArray.create(encryptedData.words.slice(0, 4));
1959																const ciphertext = CryptoJS.lib.WordArray.create(encryptedData.words.slice(4), encryptedData.sigBytes - 16);
1960																
1961																const decrypted = CryptoJS.AES.decrypt(
1962																{ ciphertext: ciphertext },
1963																encryptionKey,
1964																{ iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 }
1965																);
1966																
1967																const decryptedText = decrypted.toString(CryptoJS.enc.Utf8);
1968																lockedDiv.html(decryptedText);
1969																*/
1970																
1971																reviveAsync["e319cba4eae4280b0662b5e8f3026c4a"].refresh();
1972																
1973																//alert("Innehållet är upplåst!");
1974																
1975																//inform_google_about_status(true);															
1976																///Inloggad
1977															
1978																bLazy.revalidate();
1979																
1980																FastLinks.init();
1981															}
1982															
1983														}
1984														
1985													}
1986								  
1987											  },
1988											  error:function (xhr, ajaxOptions, thrownError){
1989												 // alert("Var vänlig ladda om sidan. Det gick inte att kontrollera om du är inloggad eller ej.");
1990											  }
1991										  });			
1992									  }
1993									  /*SLUT FIX FÖR LÅSTA ARTIKLAR*/
1994									  
1995									  
1996									
1997									
1998									if(firstnativearticle == 0){
1999										firstnativearticle++;
2000										//Lägger ut "nästa artikelthingy"
2001										if(thearticles_next.hasOwnProperty(activecheck)){											
2002											$('.nextarticle_teaser').addClass("show");
2003											
2004											$('.nextarticle_teaser .inside').attr('data-id', thearticles_next[activecheck][0]);
2005											$('.nextarticle_teaser .img').attr('style', 'background-image: url("'+thearticles_next[activecheck][1]+'")');
2006											$('.nextarticle_teaser h2').html(thearticles_next[activecheck][2]);
2007											$('.nextarticle_teaser .inside').attr('href', thearticles_next[activecheck][3]);
2008										}
2009										else{
2010											$('.nextarticle_teaser').removeClass("show");
2011										}
2012									}									
2013									
2014									
2015									/*Fixar script-relaterade saker i brödtexten*/
2016									/***************************
2017									* BRÖDTEXTBILDSPEL - EVNETUELLT?!
2018									***************************/
2019									$("figure.wp-block-gallery:not('.owl-carousel')").each(function(){
2020										$(this).addClass("owl-carousel");
2021										
2022										$(this).owlCarousel({
2023											startPosition: 0,
2024											loop: false,
2025											autoHeight:true,
2026											responsiveClass:true,
2027											responsive:{
2028												0:{
2029													items:1,
2030													dots:true,
2031													nav:false,
2032													stagePadding: 0
2033												},
2034												782:{
2035													items:1,
2036													dots:true,
2037													nav:true,				    
2038													stagePadding: 0
2039												}
2040											},
2041											navClass: ["owl-prev bgspr","owl-next bgspr"],
2042											onInitialized: initializedowl,
2043											onTranslated: initializedowl
2044										});
2045									});
2046									
2047									bLazy.revalidate();
2048									
2049									$(".entry-content").fitVids();
2050									/*SLUT PÅ FIX*/
2051									
2052									//Får ut annonser! Detta är en refreshfunktion
2053									//DEVEN: 47a8e97cef59721ef27aab10037ebcda
2054									//LIVE: e319cba4eae4280b0662b5e8f3026c4a
2055									reviveAsync["e319cba4eae4280b0662b5e8f3026c4a"].refresh();
2056								
2057									FastLinks.init();
2058																		
2059									
2060								},
2061								error:function (xhr, ajaxOptions, thrownError){
2062									loading = false;
2063									$('.loadernewarticletext').removeClass("loading");
2064								}
2065							});
2066							
2067						}
2068					}
2069					
2070				}
2071				
2072				if(activearticle != activecheck){
2073					activearticle = activecheck;
2074					
2075					//Ändrar urlen i toppen
2076					
2077					//Denna adderar en state - istället vill vi byta ut: history.pushState(null, "", arrayofurls[activearticle]);
2078					//OBS: Fungerar inte i IE9 och lägre
2079					history.replaceState(null, "", arrayofurls[activearticle]);
2080					
2081					//Ändrar title
2082					$('title').text(arrayoftitles[activearticle]); 
2083					
2084					
2085					//Lägger ut "nästa artikelthingy"
2086					
2087					
2088					var hamta_id = $(this).attr('data-id');
2089					
2090					if($('.infiniteholder > article#post-'+thearticles_next[activearticle][0]).length > 0){
2091						if(thearticles_next.hasOwnProperty(activearticle)){
2092							$('.nextarticle_teaser').addClass("show");
2093							$('.nextarticle_teaser .inside').attr('data-id', thearticles_next[activearticle][0]);
2094							$('.nextarticle_teaser .img').attr('style', 'background-image: url("'+thearticles_next[activearticle][1]+'")');
2095							$('.nextarticle_teaser h2').html(thearticles_next[activearticle][2]);
2096							$('.nextarticle_teaser .inside').attr('href', thearticles_next[activearticle][3]);
2097						}
2098						else{
2099							$('.nextarticle_teaser').removeClass("show");
2100						}
2101					}
2102					else{
2103						$('.nextarticle_teaser').removeClass("show");
2104					}
2105					
2106					/************************
2107					* HÄR SKA VI KONTAKTA GOOGLE OCH SKICKA EN PAGEVIEW
2108					*************************/
2109					//Referensartikel:
2110					//http://seanjcasey.com/blog/effective-google-analytics-infinite-scroll-tracking-of-pageviews
2111					
2112					//OBS - GÖR ENBART DETTA OM VI INTE SKICKAT PAGEVIEW FÖR DENNA URL TIDIGARE!
2113					if(arrayofgaurls.indexOf(arrayofurls[activearticle]) < 0){
2114						arrayofgaurls.push(arrayofurls[activearticle]);
2115						
2116						
2117						//Nytt 2022-02-23 - Pageview
2118						/*
2119						gtag('event', 'page_view', {
2120						  page_title: arrayoftitles[activearticle],
2121						  page_location: arrayofurls[activearticle]
2122						});
2123						*/
2124						
2125						//Nytt 2023-08-31
2126						_paq.push(['setDocumentTitle', arrayoftitles[activearticle]]);
2127						_paq.push(['setCustomUrl', arrayofurls[activearticle]]);
2128						_paq.push(['trackPageView']);
2129						
2130						
2131						//Nytt 2022-02-23 - Nivå av scrolldjup
2132						var category = "infinitescroll";
2133						var label = "Artikeldjup "+activearticle;
2134						var value = activearticle;
2135						handleEventClicksWonderfour(category, label, value, 'newarticle');
2136						
2137					}
2138				}
2139				else{
2140					if($('.infiniteholder > article#post-'+thearticles_next[activearticle][0]).length > 0){
2141						if(thearticles_next.hasOwnProperty(activearticle)){
2142							$('.nextarticle_teaser').addClass("show");
2143							$('.nextarticle_teaser .inside').attr('data-id', thearticles_next[activearticle][0]);
2144							$('.nextarticle_teaser .img').attr('style', 'background-image: url("'+thearticles_next[activearticle][1]+'")');
2145							$('.nextarticle_teaser h2').html(thearticles_next[activearticle][2]);
2146							$('.nextarticle_teaser .inside').attr('href', thearticles_next[activearticle][3]);
2147						}
2148						else{
2149							$('.nextarticle_teaser').removeClass("show");
2150						}
2151					}
2152					else{
2153						$('.nextarticle_teaser').removeClass("show");
2154					}
2155				}
2156				
2157			}
2158			
2159			
2160		}
2161		
2162		
2163
2164	});
2165	
2166});
2167
2168
2169function handleEventClicksWonderfour(category, label, value, typeofaction) {
2170	
2171	/*
2172	Event Category: Contact
2173	Event Action: Email Link Click
2174	Event Name: [email protected]
2175	*/
2176	if(jQuery('body').hasClass('logged-in')){
2177		
2178	}
2179	else{
2180		if(typeofaction == "newarticle"){
2181			_paq.push(['trackEvent', category, typeofaction, label, value]);
2182		}
2183		else{
2184			_paq.push(['trackEvent', category, typeofaction, label]);
2185		}
2186	}
2187	
2188	
2189	/* skickar event till Google - från 2024-12-05 */ 
2190	gtag('event', typeofaction, {
2191		'event_category': category,
2192		'event_label': label,
2193		'value': value
2194	});
2195	
2196	
2197}
2198
2199
2200
2201function isValidEmailAddress(emailAddress) {
2202    var pattern = new RegExp(/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/i);
2203    return pattern.test(emailAddress);
2204};
2205
2206
2207
2208function setCookie(cname, cvalue, exdays) {
2209	cvalue = encodeURIComponent(cvalue);
2210    var d = new Date();
2211    d.setTime(d.getTime() + (exdays*24*60*60*1000));
2212    var expires = "expires="+d.toUTCString();
2213    document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/;";
2214        
2215}
2216
2217function getCookie(cname) {
2218    var name = cname + "=";
2219    var ca = document.cookie.split(';');
2220    for(var i=0; i<ca.length; i++) {
2221        var c = ca[i];
2222        while (c.charAt(0)==' ') c = c.substring(1);
2223        if (c.indexOf(name) != -1) return decodeURIComponent(c.substring(name.length, c.length));
2224    }
2225    return "";
2226}
2227
2228function setCookieHour(cname, cvalue, exhour) {
2229	cvalue = encodeURIComponent(cvalue);
2230    var d = new Date();
2231    d.setTime(d.getTime() + (1*exhour*60*60*1000));
2232    var expires = "expires="+d.toUTCString();
2233    document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/;";
2234        
2235}
2236
2237
2238//HS - den enda cookien som går att kolla efter WP-standard för att se om man är inloggad eller inte är wp-settings-time (de andra går inte att komma åt av säkerhetsskäl).
2239function getLoggedInCookie() {
2240    var cookie = document.cookie.indexOf('pm_userissignedin') !== -1;
2241    if(cookie || $('body').hasClass("logged-in")){
2242       //Inloggad 
2243       $('.showlogin').addClass("logged_in_user");
2244    }else{
2245       //Ej inloggad
2246    }
2247}

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.