PageSourceSearch

https://www.visindavefur.is/libs/js/mainweb-is.js?c9dc24c6aba5467eb544e6825af08347a4c214e5

js visindavefur.is collected 2026-10-02 05:53:18 UTC 47,410 bytes, 1,882 lines download raw bytes

1VV = new Object();
2
3$(function(){
4    /*
5     * Icons
6     */
7    feather.replace();
8    /*
9     * Menus
10     */
11     $(".mobile-nav .burger a").on("click", function(event){
12         if ($("header.header").hasClass("--open")) {
13            $("header.header").removeClass("--open");   
14             $("body").removeClass("--menuOpen");
15        } else {
16            $("header.header").addClass("--open");
17            $("body").addClass("--menuOpen");
18        }
19         event.preventDefault();
20     });
21
22     $(".mobile-nav .categories a").on("click", function(event){
23        $("header.header.--open .header-mobile .mobile-nav ul li.burger a").click();
24
25        if ($(".category-nav").hasClass("--open")) {
26
27          $(".category-nav").removeClass("--open");
28           $(".mobile-nav .categories").removeClass("--open");
29
30            if (!$("header.header").hasClass("--open")) {
31                    $("body").removeClass("--menuOpen");
32                   $("header.header").removeClass("--open");   
33         }
34
35          $("li.categories").removeClass("--open");
36
37       } else {
38           $(".mobile-nav .categories").addClass("--open");
39           $("li.categories").addClass("--open");
40           $(".category-nav").addClass("--open");
41           $("body").addClass("--menuOpen");
42
43            // Close on click outside
44            $("body").one("click", function(event){
45                $(".category-nav").removeClass("--open");
46                $(".mobile-nav .categories").removeClass("--open");
47
48                if (!$("header.header").hasClass("--open")) {
49                    $("body").removeClass("--menuOpen");
50                }
51           });
52
53            // Close on escape
54            $(window).one("keyup", function(event){
55            if (event.keyCode == 27) {
56                $(".category-nav").removeClass("--open");
57            }
58        });
59       }
60        event.preventDefault();
61        event.stopPropagation();
62    });
63    // Show menu on scroll up
64    var lastScrollTop = 0;
65    var headerContainer = $(".header-container");
66
67	$(window).on("scroll", function() {
68		st = $(this).scrollTop();
69		diff = st - lastScrollTop; // Don't hide menu when scrolling is due to scrollbars being removed from body tag (3-5px, overflow hidden).
70
71                if (st <= 0) {
72                    $("body").removeClass("menu__compact");
73                } else if (st >=150 && !$("body").hasClass("menu__compact")){
74                    headerContainer.css({top: "-6rem"});
75                    headerContainer[0].offsetHeight; // Trigger a reflow, flushing the CSS changes
76                    $("body").addClass("menu__compact");
77                    headerContainer.css({top: ""});
78                }
79
80                if(diff < 0){
81                      $("body").addClass("menu__up");
82                }else{
83                      $("body").removeClass("menu__up");
84                }
85
86		lastScrollTop = st;
87    });
88
89    /*
90     * Scroll up button
91     */
92     $(".arrow-btn.scroll-up").on('click',function() {  $("html, body").animate({ scrollTop: 0 }, 500);});
93
94    /*
95     *   Horizontal Scroll
96     */
97    var horizontalScrollWrapper = $('.horizontal-scroll-wrapper');
98    
99    if(horizontalScrollWrapper.length){
100        if($('.horizontal-scroll-wrapper .hr').get(0).scrollWidth > $('.horizontal-scroll-wrapper .hr').innerWidth()){
101            horizontalScrollWrapper.addClass("right");
102        }
103
104        $(".horizontal-scroll-wrapper > a.left").click(function () {
105            var leftPos = $('.horizontal-scroll-wrapper .hr').scrollLeft();
106            $(".horizontal-scroll-wrapper .hr").animate({
107                scrollLeft: leftPos - 150
108            }, 300);
109        });
110
111        $(".horizontal-scroll-wrapper > a.right").click(function () {
112            var leftPos = $('.horizontal-scroll-wrapper .hr').scrollLeft();
113            $(".horizontal-scroll-wrapper .hr").animate({
114                scrollLeft: leftPos + 150
115            }, 300);
116        });
117    };
118
119    $(function () {
120        var scrollLeftPrev = 0;
121        $('.horizontal-scroll-wrapper .hr').scroll(function () {
122            var $elem=$('.horizontal-scroll-wrapper .hr');
123            var newScrollLeft = $elem.scrollLeft(),
124                width=$elem.outerWidth(),
125                scrollWidth=$elem.get(0).scrollWidth;
126            $elem.parent().addClass("right").addClass("left");
127            if (scrollWidth-newScrollLeft==width) {
128                $elem.parent().removeClass("right");
129            }
130            if (newScrollLeft === 0) {
131                $elem.parent().removeClass("left");
132            }
133            
134            scrollLeftPrev = newScrollLeft;
135        });
136     });
137
138    /*
139     * Footnotes buttons
140     */
141    $(".citation-button").eq(0).addClass("--active");
142    $(".footnote .citation-buttons-wrapper a").on("click", function(event){
143        $(".footnote .citation_displayed").removeClass("citation_displayed");
144        $(".citation-button").removeClass("--active");
145        $($(this).attr("href")).addClass("citation_displayed");
146        $(this).addClass("--active");
147        event.preventDefault();
148    });
149    /*
150     * Tabs
151     */
152    $(".tab-nav a").on("click", function(event){
153        var $tab = $($(this).attr("href"));
154        var $tabparent = $tab.parents(".tabs");
155        var $tabnav = $(this).parents(".tab-nav");
156        // Update tab nav
157        $tabnav.find("a").removeClass("--active");
158        $(this).addClass("--active");
159        // Set tab
160        $tabparent.find(".tab").removeClass("--active");
161        $tab.addClass("--active");
162        event.preventDefault();
163    });
164    /*
165     * Send question
166     */
167    $(".header-question a.send").on("click", function(event){
168        if ($("body").hasClass("--sendquestion")) {
169           $("body").removeClass("--sendquestion");     
170       } else {
171           $("body").addClass("--sendquestion");
172           $(".md-send").removeClass("--help");
173       }
174       // Close 
175       $(".md-send .md-actions .btn-white").one("click", function(event){
176            $("body").removeClass("--sendquestion");
177        });
178        event.preventDefault();
179    });
180    $("a.instructions").on("click", function(event) {
181        $(".md-send").addClass("--help");
182    });
183    $("a.instructions-close").on("click", function(event) {
184        $(".md-send").removeClass("--help");
185    });
186    /*
187     * Share
188     */
189    $(".social-share a.btn.share").on("click", function(event) {
190        socialShare($(this).attr("href"));
191        event.preventDefault();
192    });
193
194    function socialShare(url) {
195        u=location.href;
196        t=document.title;
197        window.open(url,
198            'sharer','toolbar=0,status=0,width=626,height=436'
199        );
200        return false;
201    }
202    $(".share-buttons a.share.email").on("click", function(event){
203	if ( $(".poppin.md-email").css("display") == "block" ) {
204		$(".poppin.md-email").css("display","none");
205	} else {
206		$(".poppin.md-email").css("display","block");
207	}
208
209        event.preventDefault();
210    });
211    $("div.poppin.md-email .md-actions button.btn.btn-white").on("click", function(event) {
212        $(".poppin.md-email").css("display","none");
213        event.preventDefault();
214    });
215
216  /*
217   * For page 7089, "Um vefinn", move readspeaker.
218   */
219   let about_info_dom = $("body.b-page section.layout div.main-content div.article-hero div.hero-element.layout-item.about-info");
220
221   if ( about_info_dom.length > 0 ) {
222       $("#vv-article-text-area").prepend(
223            $("#readspeaker_button1")
224       );
225   }
226
227  /*
228   * For frontpage, hide 'Gervigreindarsvör' tabs if no items are present.
229   */
230   if ((jQuery("#nyjustu-gervigreind .recent-answers-wrapper").length) && (jQuery("#nyjustu-gervigreind .recent-answers-wrapper")[0].childNodes.length <= 1)) {
231         jQuery(".recent-answers h2.section-title .tab-nav .nyjustu-gervigreind").css("display", "none");
232   }
233
234   if ((jQuery("#vinsaelsvor-gervigreind .recent-answers-wrapper").length) && (jQuery("#vinsaelsvor-gervigreind .recent-answers-wrapper")[0].childNodes.length <= 1)) {
235         jQuery(".recent-answers h2.section-title .tab-nav .vinsaelsvor-gervigreind").css("display", "none");
236   }
237
238   if ((jQuery("#onnursvor-gervigreind .recent-answers-wrapper").length) && (jQuery("#onnursvor-gervigreind .recent-answers-wrapper")[0].childNodes.length <= 1)) {
239       jQuery(".recent-answers h2.section-title .tab-nav .onnursvor-gervigreind").css("display", "none");
240   }
241
242
243});
244
245/*
246 * On loading of site.
247 */
248
249jQuery().ready(function() {
250	/*
251	 * Variable used for locking, so we don't 
252	 * resize objects multiple times at once 
253	 * which can cause the browser to slow down.
254	 */
255	vv_resizing_objects_lock = false;
256
257	/* Cookie policy prompt */
258	vv_public_cookie_policy_check();
259
260	/* Math problem form, revive, fetch, etc. */
261	if (
262		( typeof vv_math_problem_successfully_solved != "undefined" ) &&
263		( vv_math_problem_successfully_solved == true )
264		||
265		( typeof vv_math_problem_unsuccessful_solve != "undefined") &&
266		( vv_math_problem_unsuccessful_solve == true )
267	) {
268		/*
269 		 * If math problem was successfully solved,
270 		 * we need to renew the cookie we have stored,
271 		 * as the current one has now become invalid.
272 		 */
273		vv_math_cookie_remove();
274	}
275
276	vv_math_form_problem_hide_or_show_submit_btn('hide');
277	vv_math_form_problem_fetch();
278	vv_math_form_problem_hide_or_show_submit_btn('show');
279	vv_math_form_revive();
280
281	/* Dynamic search results */
282	vv_search_pagination_in_progress = false;
283	vv_search_pagination_enabled_check();
284
285	/* Dynamic category results */
286	vv_category_pagination_in_progress = false;
287	vv_category_pagination_enabled_check();
288
289	/* Author page, dynamic results */
290	vv_author_pagination_in_progress = false;
291	vv_author_pagination_enabled_check();
292
293	/* Submission form, possibly display 'Back' link */
294	if ( $(".main-content .svor-skref.nr4 .content") ) {
295		vv_possibly_add_home_button(
296			$(".main-content .svor-skref.nr4 .content .layout-item"),
297			'Fara á forsíðu',
298			'/design/i_vv/icon-arrow-left.svg'
299		);
300	}
301
302	/* Send to friend confirmation page, possibly display 'Back' link */
303	if ( $(".no-js.lang-is .b-send .layout .main-content #answer-sent-confirmation") ) {
304		vv_possibly_add_home_button(
305			$(".no-js.lang-is .b-send .layout .main-content .layout-item"),
306			'Fara á forsíðu',
307			'/design/i_vv/icon-arrow-left.svg'
308		);
309	}
310
311	/* 
312	 * If needed, when ready, 
313	 * resize objects 
314	 * that can be resized 
315	 */
316	vv_resize_objects();
317
318	/* 
319	 * On resize of window,
320	 * resize any objects
321	 * that can be resized.
322	 */
323	window.addEventListener('resize', vv_resize_objects);
324
325	/* 
326	 * If JavaScript put in place to indicate rendering
327	 * of statistics, then actually render the statistics.
328	 *
329	 * Note that this needs to take place after objects
330	 * are resized after initalization.
331 	 */
332	if ( typeof vv_public_stats_render_lang != "undefined" ) {
333		vv_public_stats_render( vv_public_stats_render_lang );
334	}
335
336	/*
337	 * For LLM-switching functionality on front-page.
338	 */
339	$(".toggle-search-type").on(
340		'click',
341		vv_llm_classic_search_boxes_toggle
342	);
343
344	if (
345		($(".toggle-search-type").length > 0) && 
346		(jQuery.cookie("search-box-chosen"))
347	) {
348		vv_llm_classic_search_boxes_toggle(
349			jQuery.cookie("search-box-chosen") == 'ai-hero' ? 'classic-search-box' : 'ai-search-box'
350		);
351	}
352
353	/* For LLM question form */
354	$('#ai-question-form').on('submit', vv_llm_question_send);
355});
356
357/*
358 * If form was submitted but with
359 * issues, revive the form so user can retry.
360 *
361 * If we find any content in the name-field, 'click'
362 * the 'spyrja' button. Note that for 'send.php'
363 * similar functionality is in the templates.
364 */
365
366function vv_math_form_revive() {
367	if (
368		( $(".main-content .poppin.md-send form .md-fields .md-input input#s-fname.send-input").val() != undefined ) &&
369		( $(".main-content .poppin.md-send form .md-fields .md-input input#s-fname.send-input").val() != "" )
370	) {
371		$("div.header-question a.btn.send").click();
372	}
373
374	if ( typeof vv_error_math_problem_step3 !== 'undefined' && vv_error_math_problem_step3 === true ) {
375		$("div.header-question a.btn.send").click();
376	}
377}
378
379/*
380 * Hide submit buttons in forms
381 */
382
383function vv_math_form_problem_hide_or_show_submit_btn( type ) {
384	if ( type == "hide" ) {
385		jQuery(".no-js.lang-is div.poppin.md-send form div.md-actions button.btn.send-button").css("display", "none");
386		jQuery(".no-js.lang-is div.poppin.md-email form div.md-actions button.btn.send-button").css("display", "none");
387	}
388
389	else if ( type == "show" ) {
390		jQuery(".no-js.lang-is div.poppin.md-send form div.md-actions button.btn.send-button").css("display", "inline-block");
391		jQuery(".no-js.lang-is div.poppin.md-email form div.md-actions button.btn.send-button").css("display", "inline-block");
392	}
393}
394
395/*
396 * Fetch math problem from webservice
397 */
398function vv_math_form_problem_fetch() {
399	
400	if (jQuery.cookie("input_check_math_problem") == undefined) {
401		jQuery.getJSON("/misc.php?module=input_check_math_problem",
402			{
403				'action': 'input_check_math_problem',
404			},
405
406			function(data) {
407				var timestamp_now_obj = new Date();
408				var timestamp_now = Math.round(timestamp_now_obj.getTime() / 1000);
409	
410				jQuery.cookie(
411					"input_check_math_problem", 
412					JSON.stringify(data), 
413					{ expires: new Date( (timestamp_now + (Math.round(data.math_problem_expiry_seconds * 0.9))) * 1000) }
414				);
415
416				vv_math_form_problem_populate();
417			}
418		);	
419	}
420
421	else {
422		vv_math_form_problem_populate();
423	}
424}
425
426function vv_math_cookie_remove() {
427	jQuery.removeCookie("input_check_math_problem");
428}
429
430/*
431 * Populate math problem form with data
432 */
433function vv_math_form_problem_populate() {
434	var input_check_math_problem = JSON.parse(jQuery.cookie('input_check_math_problem'));
435
436	jQuery(".poppin.md-send form .s-math-container .math_problem_num1_txt").text(input_check_math_problem.chosen_rand_num1_txt);
437	jQuery(".poppin.md-send form .s-math-container .math_problem_math_icon").attr("src", input_check_math_problem.chosen_math_icon);
438	jQuery(".poppin.md-send form .s-math-container .math_problem_num2_txt").text(input_check_math_problem.chosen_rand_num2_txt);
439
440	jQuery(".poppin.md-send form .vv_math_problem_hash_id").val(input_check_math_problem.math_problem_hash_id);
441
442	jQuery(".poppin.md-email form .s-math-container .math_problem_num1_txt").text(input_check_math_problem.chosen_rand_num1_txt);
443	jQuery(".poppin.md-email form .s-math-container .math_problem_math_icon").attr("src", input_check_math_problem.chosen_math_icon);
444	jQuery(".poppin.md-email form .s-math-container .math_problem_num2_txt").text(input_check_math_problem.chosen_rand_num2_txt);
445
446	jQuery(".poppin.md-email form .vv_math_problem_hash_id").val(input_check_math_problem.math_problem_hash_id);
447}
448
449/*
450 * Check if accepted cookies, if
451 * not, display form.
452 */
453
454function vv_public_cookie_policy_check() {
455	if (jQuery.cookie("cookie_policy_accepted") != "1") {
456		jQuery("#cookie-policy-disclaimer").removeClass("--hide");
457	}
458}
459
460/*
461 * Accepted cookies, hide form.
462 */
463function vv_public_cookie_policy_ok() {
464	var timestamp_now_obj = new Date();
465	var timestamp_now = Math.round(timestamp_now_obj.getTime() / 1000);
466
467	jQuery.cookie(
468		"cookie_policy_accepted", 
469		"1",
470		{
471			expires: new Date( ( timestamp_now + ( 365 * 24 * 60 * 60 ) ) * 1000 ),
472			path: '/',
473 		}
474	);
475
476	jQuery("#cookie-policy-disclaimer").addClass("--hide");
477
478	return false;
479}
480
481/*
482 * Search pagination logic
483 */
484
485function vv_search_pagination_enabled_check() {
486	if (
487		(typeof vv_search_pagination_enable == 'undefined') ||
488		 (vv_search_pagination_enable != 1)
489	) {
490		return;
491	}
492
493	$('.layout .main-content .main-search-container #search-scroll-marker a').
494		css('display', 'inline-block');
495
496	var waypoint = new Waypoint({
497		element: document.getElementById('search-scroll-marker'),
498		handler: function(direction) {
499			if (direction == 'up') {
500				return;
501			}
502
503			vv_search_pagination_next();
504		},
505		offset: 'bottom-in-view'
506	});
507
508}
509
510function vv_search_pagination_next() {
511	vv_search_pagination_next_counter++;
512
513	if (vv_search_pagination_in_progress == true) {
514		/* Request in progress -- bail */
515		return;
516	}
517
518	vv_search_pagination_in_progress = true;
519
520	$('.b-search .layout .main-content #search-scroll-marker a').css('display', 'none');
521	$('.b-search .layout .main-content #search-scroll-marker .loading-text').css('display', 'inline-block');
522
523	$.getJSON("/search.php", {
524		"ajax": "1",
525		"xml": 1,
526		"q": vv_search_query,
527		"page": vv_search_pagination_next_counter
528		},
529
530		function(data) {
531			if (data.search_results.length == 0) {
532				$('.b-search .layout .main-content #search-scroll-marker .loading-text').css('display', 'none');
533				$('.b-search .layout .main-content #search-scroll-marker .no-more-text').css('display', 'inline-block');
534				$('.b-search .layout .main-content #search-scroll-marker .no-more-text a').css('display', 'inline-block');
535
536				return;
537			}
538
539			data.search_results.forEach(function(question_obj) {
540				if (vv_lang == 'is' ) {
541					$('.b-search .main-content .search-results').append(
542						$('<a>')
543							.attr('class', 'search-result')
544							.attr('href', '/svar.php?id=' + question_obj.question_id)
545							.attr('target', '_new')
546							.append(
547								$('<div>')
548									.attr('class', 'result-category')
549										.append(
550										$('<img>')
551											.attr('src', '/design/i_vv/icon-spa.svg' )
552											.attr('alt', 'category-icon')
553										)
554									.append(
555										question_obj.categories[0].name ? question_obj.categories[0].name : ''
556									)
557								)
558
559							.append(
560								$('<time>')
561									.attr('pubdate', 'pubdate')
562									.append(question_obj.publish_date)
563							)
564
565							.append(
566								$('<h3>')
567									.append(question_obj.question)
568							)
569
570							.append(
571								$('<aside>')
572									.attr('class', 'search-result-img')
573									.append(
574										$('<img>')
575											.attr('src', '/' + question_obj.image)
576											.attr('alt', 'thumb')
577									)
578							)
579
580							.append(
581								$('<p>')
582									.append(question_obj.answer_preview)
583							)
584					);
585				} else {
586					$('.b-search .main-content .search-results').append(
587						$('<a>')
588							.attr('class', 'search-result')
589							.attr('href', '/svar.php?id=' + question_obj.question_id)
590							.attr('target', '_new')
591							.append(
592								$('<div>')
593									.attr('class', 'result-thumbnail')
594									.append(
595										$('<img>')
596											.attr('src', '/' + question_obj.image)
597											.attr('alt', 'thumb')
598										)
599							)
600							.append(
601								$('<div>')
602									.attr('class', 'result-content')
603									.append(
604										$('<div>')
605											.attr('class', 'result-meta')
606											.append(
607												$('<div>')
608													.attr('class', 'result-category')
609													.append(
610														question_obj.categories[0].category_name ? question_obj.categories[0].category_name : ''
611													)
612													.append(
613														$('<span>')
614														.attr('class', 'result-date')
615															.append(
616																question_obj.publish_date
617															)
618													)
619											)
620									)
621									.append(
622										$('<h3>')
623										.attr('class', 'result-title')
624										.append(question_obj.question)
625									)
626									.append(
627										$('<p>')
628											.attr('class', 'result-excerpt')
629											.append(question_obj.answer_preview)
630									)
631							)
632					);
633				}
634			});
635
636			$('.b-search .layout .main-content #search-scroll-marker a').css('display', 'inline-block');
637			$('.b-search .layout .main-content #search-scroll-marker .loading-text').css('display', 'none');
638
639			Waypoint.refreshAll();
640
641			vv_search_pagination_in_progress = false;
642		}
643	);
644}
645
646
647/*
648 * Dynamic category loading logic
649 */
650function vv_category_pagination_enabled_check() {
651	if (
652		(typeof vv_category_pagination_enable == 'undefined') ||
653		 (vv_category_pagination_enable != 1)
654	) {
655		return;
656	}
657
658	$('.b-category .layout .main-content #category-scroll-marker a').css('display', 'inline-block');
659
660	var waypoint = new Waypoint({
661		element: document.getElementById('category-scroll-marker'),
662		handler: function(direction) {
663			if (direction == 'up') {
664				return;
665			}
666
667			vv_category_pagination_next();
668		},
669		offset: 'bottom-in-view'
670	});
671}
672
673function vv_category_pagination_next() {
674	vv_category_pagination_next_counter++;
675
676	if (vv_category_pagination_in_progress == true) {
677		/* Request in progress -- bail */
678		return;
679	}
680
681	vv_category_pagination_in_progress = true;
682
683	$('.b-category .layout .main-content #category-scroll-marker a').css('display', 'none');
684	$('.b-category .layout .main-content #category-scroll-marker .loading-text').css('display', 'inline-block');
685
686	$.getJSON("/vegna_thess.php", {
687		"ajax": "1",
688		"xml": 1,
689		"id": vv_category_id,
690		"page": vv_category_pagination_next_counter
691		},
692
693		function(data) {
694			if (data.questions.length == 0) {
695				$('.b-category #category-scroll-marker .loading-text').css('display', 'none');
696				$('.b-category #category-scroll-marker .no-more-text').css('display', 'inline-block');
697				$('.b-category #category-scroll-marker .no-more-text a').css('display', 'inline-block');
698
699				return;
700			}
701
702			data.questions.forEach(function(question_obj) {
703				let css_selector = null;
704
705				if (vv_lang == "is" ) {
706					css_selector = '.b-category .layout .main-content .content-below .recent-answers .recent-answers-wrapper';
707				}
708
709				else if (vv_lang == "ev_is") {
710					css_selector = '.b-category .layout .main-content .articles-grid';
711				}
712
713				$(css_selector).append(
714					$('<article>')
715						.attr(
716							'class',
717							vv_lang == 'is' ? 'recent-article' : 'article-card'
718						)
719						.append(
720							$('<a>')
721								.attr('href', '/svar.php?id=' + question_obj.id)
722								.attr('target', '_new')
723								.attr('class', 'recent-article-wrapper' )
724							.append(
725								vv_lang == 'is' ? (
726									$('<div>')
727									.attr('class', 'recent-category cat-hugvisindi')
728									.css('border-color', question_obj.question_cat_single.category_color)
729									.append(question_obj.question_cat_single.category_name)
730								) : (
731									$('<span>')
732									.attr('class', 'card-category')
733									.append(question_obj.question_cat_single.category_name)
734								)
735							)
736							.append(
737								vv_lang == 'is' ?
738									$('<h4>' + question_obj.question + '</h4>')
739									:
740									$('<h3>' + question_obj.question + '</h3>')
741										.attr('style', 'padding-bottom: 12px;')
742							)
743							.append(
744								vv_lang == 'is' ?
745									$('<div>')
746								:
747									$('<div>')
748										.attr('class', 'answer-meta')
749										.append(
750											$('<span>')
751												.attr('class', 'answer-date')
752													.append(
753													$('<img>')
754														.attr('src', '/design/i_ev_is/icon-date.svg')
755												)
756												.append(
757													question_obj.publish_time
758											)
759										)
760							)
761					)
762				);
763			});
764
765			$('.b-category #category-scroll-marker a').css('display', 'inline-block');
766			$('.b-category #category-scroll-marker .loading-text').css('display', 'none');
767
768			Waypoint.refreshAll();
769		
770			vv_category_pagination_in_progress = false;
771		}
772	);
773}
774
775function vv_categories_toggle(){
776        $(".breadcrumbs .b-right").toggleClass("--open")
777}
778
779/*
780 * Author page questions pagination
781 */
782function vv_author_pagination_enabled_check() {
783	if (
784		(typeof vv_author_pagination_enable == 'undefined') ||
785		 (vv_author_pagination_enable != 1)
786	) {
787		return;
788	}
789
790	$('#category-scroll-marker a').css('display', 'inline-block');
791
792	var waypoint = new Waypoint({
793		element: document.getElementById('author-scroll-marker'),
794		handler: function(direction) {
795			if (direction == 'up') {
796				return;
797			}
798
799			vv_author_pagination_next();
800		},
801		offset: 'bottom-in-view'
802	});
803}
804
805function vv_author_pagination_next() {
806	vv_author_pagination_next_counter++;
807
808	if (vv_author_pagination_in_progress == true) {
809		/* Request in progress -- bail */
810		return;
811	}
812
813	vv_author_pagination_in_progress = true;
814
815	let css_selector_prefix = null;
816
817	if (vv_lang == "ev_is") {
818		css_selector_prefix = ".b-page ";
819	}
820
821	else if (vv_lang == "is") {
822		css_selector_prefix = ".b-page ";
823	}
824
825	else {
826		return;
827	}
828
829	$(css_selector_prefix + '#author-scroll-marker a').css('display', 'none');
830	$(css_selector_prefix + '#author-scroll-marker .loading-text').css('display', 'inline-block');
831
832	$.getJSON("/author.php", {
833		"ajax": "1",
834		"xml": 1,
835		"id": vv_author_id,
836		"page": vv_author_pagination_next_counter
837		},
838
839		function(data) {
840			if (data.questions.length == 0) {
841				$(css_selector_prefix + ' #author-scroll-marker .loading-text').css('display', 'none');
842				$(css_selector_prefix + ' #author-scroll-marker .no-more-text').css('display', 'inline-block');
843				$(css_selector_prefix + ' #author-scroll-marker .no-more-text a').css('display', 'inline-block');
844
845				return;
846			}
847
848			if (vv_lang == "is") {
849				data.questions.forEach(function(question_obj) {
850					$( ' .recent-answers .recent-answers-wrapper').append(
851						$('<article>')
852							.attr(
853								'class',
854								'recent-article'
855							)
856
857							.append(
858								$('<a>')
859									.attr('href', '/svar.php?id=' + question_obj.id)
860									.attr('target', '_new')
861									.attr('class', 'recent-article-wrapper')
862								.append(
863									$('<div>')
864									.attr('class', 'recent-category cat-hugvisindi')
865									.css('border-color', question_obj.question_cat_single.category_color)
866									.append( question_obj.question_cat_single.category_name )
867								)
868								.append(
869									$('<h4>' + question_obj.question + '</h4>')
870								)
871							)
872					);
873				});
874			}
875
876			else if (vv_lang == "ev_is") {
877				data.questions.forEach(function(question_obj) {
878					$(' .answers-grid').append(
879						$('<article>')
880							.attr(
881								'class',
882								'answer-card'
883							)
884
885							.append(
886								$('<span class="answer-category">' + question_obj.question_cat_single.category_name + '</span>'),
887								$('<a>')
888									.attr('href', '/svar.php?id=' + question_obj.id)
889									.attr('target', '_new')
890									.attr('class', 'answer-title')
891									.append(question_obj.question),
892								$('<div>')
893									.attr('class', 'answer-meta')
894									.append(
895										$('<span>')
896											.attr('class', 'answer-date')
897											.append(
898												$('<img>')
899													.attr('src', '/design/i_ev_is/icon-date.svg'),
900												question_obj.publish_date,
901											)
902									)
903							)
904					);
905				});
906			}
907
908			$(css_selector_prefix + ' #author-scroll-marker a').css('display', 'inline-block');
909			$(css_selector_prefix + ' #author-scroll-marker .loading-text').css('display', 'none');
910
911			Waypoint.refreshAll();
912		
913			vv_author_pagination_in_progress = false;
914		}
915	);
916}
917
918/*
919 * Possibly add 'back' link.
920 */
921function vv_possibly_add_home_button( locator, str, img_url = null ) {
922	if (document.referrer == "") {
923		return;
924	}
925
926	if ( img_url !== null ) {
927		locator.append(
928			$('<a href="/"">')
929				.append(
930					$('<img>')
931						.attr( 'src', img_url )
932				)
933		);
934	}
935
936	locator.append(
937		$('<a href="/"">').text( str )
938	);
939}
940
941function vv_btoa(str) {
942	var ret = window.btoa(str);
943
944	/* 
945	 * Because JavaScript is extremly stupid,
946 	 * string.replace() does only replace
947 	 * the first occurrance of what should
948	 * be replaced. Here we work around that.
949 	 */
950	for (i = 0; i < 10; i++) {
951		ret = ret.replace("=", "x8173");
952		ret = ret.replace("/", "x8174");
953	}
954        
955	return ret;
956}
957
958function vv_uc_first(string) {
959	return string.charAt(0).toUpperCase() + string.slice(1);
960}
961
962
963/*
964 * Public stats rendering and
965 * processing.
966 */
967
968function vv_public_stats_render(lang) {
969	$.getJSON("/misc.php", {
970		"module": "public_stats",
971		"lang": lang
972		},
973		vv_public_stats_data_process
974	);
975}
976
977function vv_public_stats_data_process(data) {
978	/*
979	 * Global variable, used to store
980	 * stuff from server
981	 */
982
983	VV.public_stats = data;
984
985
986	/*
987	 * Place tooltip for the graphs
988	 */
989
990	$("<div id='public-stats-tooltip'></div>").css({
991		position: "absolute",
992		display: "none",
993		border: "1px solid #fdd",
994		padding: "2px",
995		"background-color": "#fee",
996		opacity: 0.80
997	}).appendTo("body");
998
999
1000	/*
1001	 * Function to place label on pie-chart
1002	 */
1003
1004        VV.public_stats._labelFormatter = function (label, series) {
1005		var style_hide = "";
1006
1007		if (series.percent < 5.0) {
1008			style_hide = "display: none;";
1009		}
1010
1011		return "<div " + 
1012			" style='" +
1013			"    font-size:9pt; " + 
1014			"    text-align:center; " +
1015			"    padding:15px; " +
1016			"    color:black; " + 
1017			style_hide + 
1018			"'" +
1019			" class='pieLabelFormatter pieLabelFormatter-" + vv_btoa(label) + " '" +
1020			">" + 
1021			label + 
1022			"<br/>" + 
1023			Math.round(series.percent) + 
1024			"%</div>";
1025        }
1026
1027
1028	/*
1029	 * Draw number of published questions per category 
1030	 * -- pie chart
1031	 */
1032
1033	var data_new_max_val = 50;
1034	var count = 0;
1035	var count_max = 
1036		$("#public-stats-placeholder-published-by-category").
1037		attr('vv-display-max') || 75; 
1038
1039	var data_new = Object.keys(
1040		data['published_by_category_keys']
1041	).map(function(key) {
1042		data_new_max_val = Math.max(
1043			data['published_by_category'][
1044				data['published_by_category_keys'][key]
1045			],
1046			data_new_max_val
1047		);
1048
1049		if (
1050			(
1051				parseInt(key) + 1 == 
1052				VV.public_stats.published_by_category_keys.length
1053			) && (
1054				count + 1 >=
1055				count_max
1056			)
1057		) {
1058			/*
1059			 * We are processing the last category in the set;
1060			 * this will usually be skipped, so use the
1061			 * opportunity and create 'Others' entry for
1062			 * the piechart.
1063			 */
1064			
1065			var obj;
1066			obj = new Object();
1067			obj.label = 'Aðrir';
1068			obj.data = 
1069				data['published_by_category']['other'];
1070
1071			return obj;
1072		}
1073
1074
1075		if (count++ >= count_max) {
1076			if (
1077				VV.public_stats.published_by_category['other'] ==
1078				undefined
1079			) {
1080				VV.public_stats.published_by_category['other'] = 0;
1081			}
1082
1083			VV.public_stats.published_by_category['other'] += 
1084				parseInt(
1085					data['published_by_category'][
1086						data['published_by_category_keys'][key]
1087					]
1088				);
1089			return;
1090		}
1091
1092		var obj;
1093
1094		obj = new Object();
1095
1096		obj.label = VV.public_stats['categories'][
1097			data['published_by_category_keys'][key]
1098		];
1099
1100		obj.data = parseInt(
1101				data['published_by_category'][
1102					data['published_by_category_keys'][key]
1103				]
1104		);
1105		
1106		return obj;
1107	});
1108
1109
1110	/*
1111	 * Remove any possible "undefined" values
1112	 * left over when we returned without a 
1113	 * a value
1114	 */
1115
1116	data_new = $.grep(
1117		data_new,
1118		function (n){
1119			return n == 0 || n
1120		}
1121	);
1122
1123
1124	VV.public_stats._hidden_labels_by_default = [];
1125
1126	$.plot(
1127		"#public-stats-placeholder-published-by-category", 
1128		data_new, 
1129		{
1130			series: {
1131				pie: { 
1132					show: true,
1133					radius: 1,
1134					label: {
1135						show: true,
1136						radius: 2/3,
1137						formatter: VV.public_stats._labelFormatter,
1138						//threshold: 0.05
1139					}
1140				}
1141			},
1142
1143			grid: {
1144				hoverable: true,
1145				clickable: true
1146			},
1147                                
1148			legend: {
1149				show: false
1150			}
1151		}
1152	);
1153
1154	$("#public-stats-placeholder-published-by-category").bind("plothover", function(event, pos, obj) {
1155		if (! obj) {
1156			return;
1157		}
1158
1159		label_class = 
1160			".pieLabelFormatter-" + vv_btoa(obj.series.label);
1161		
1162
1163		if (VV.public_stats._hidden_labels_by_default.includes(label_class) == false) {
1164			if ($(label_class).css('display') == 'none') {
1165				VV.public_stats._hidden_labels_by_default.push(label_class);
1166			}
1167		}
1168
1169		for (x in VV.public_stats._hidden_labels_by_default) {
1170			$(VV.public_stats._hidden_labels_by_default[x]).css(
1171				'display',
1172				'none'
1173			);
1174		}
1175
1176		$(label_class).css(
1177			'display', 
1178			'inline-block'
1179		);
1180	});
1181
1182	/*
1183	 * Draw 'count by keyword'
1184	 */
1185
1186	vv_wordcloud(
1187		document.getElementById(
1188			"public-stats-placeholder-published-by-keyword"
1189		),
1190		[ 565, 400 ],
1191		VV.public_stats.published_by_keyword
1192	);
1193
1194	/*
1195	 * Draw 'word-count by keyword'
1196	 */
1197
1198	var data_new_max_val = 50;
1199	var count = 0;
1200	var count_max = $("#public-stats-placeholder-words-by-keyword-average").
1201			attr('vv-display-max') || 75;
1202
1203	// For labels on the graph
1204	VV.public_stats['_keywords_labels_word_count'] = new Array();
1205
1206	var data_new = Object.keys(
1207		data['words_by_keyword_keys']
1208	).map(function (key) {
1209		data_new_max_val = Math.max(
1210			data['words_by_keyword'][
1211				data['words_by_keyword_keys'][key]
1212			],
1213			data_new_max_val
1214		);
1215
1216		if (count++ > count_max) {
1217			return;
1218		}
1219
1220		VV.public_stats['_keywords_labels_word_count'][count] = 
1221				data['words_by_keyword_keys'][key];
1222
1223		return [
1224			count++,
1225			data['words_by_keyword'][
1226				data['words_by_keyword_keys'][key]
1227			]
1228		]; 
1229	});
1230
1231
1232	$.plot(
1233		$("#public-stats-placeholder-words-by-keyword-average"),
1234		[{
1235			data: data_new,
1236			label:	$("#public-stats-placeholder-words-by-keyword-average").
1237				attr('vv-label') || "Efnisorð",
1238			color:	$("#public-stats-placeholder-words-by-keyword-average").
1239				attr('vv-color') || "#888"
1240		}], 
1241		{
1242			bars: { show: true, barWidth: 0.5, fill: 0.9 },
1243			xaxis: { ticks: [], autoscaleMargin: 0.02 },
1244			yaxis: { min: 0, max: data_new_max_val + 50 },
1245			grid: { markings: [], hoverable: true, clickable: true }
1246		}
1247	);
1248                
1249
1250	$("#public-stats-placeholder-words-by-keyword-average").bind("plothover", function (event, pos, item) {
1251		if ( ! item ) {
1252			$("#public-stats-tooltip").hide();
1253			return;
1254		}
1255
1256		var tooltip_txt = VV.public_stats['_keywords_labels_word_count'][item.datapoint[0]];
1257
1258		$("#public-stats-tooltip").html(vv_uc_first(tooltip_txt))
1259			.css({top: item.pageY + 5, left: item.pageX + 5})
1260			.fadeIn(200);
1261	});
1262
1263
1264	/*
1265	 * Draw 'count by author'
1266	 */
1267
1268	var data_new_max_val = 50;
1269	var count = 0;
1270	var count_max = $("#public-stats-placeholder-published-by-author").
1271			attr('vv-display-max') || 75;
1272
1273	VV.public_stats['_authors_labels'] = new Array();
1274
1275	var data_new = Object.keys(
1276		data['published_by_author_keys']
1277	).map(function (key) {
1278		data_new_max_val = Math.max(
1279			data['published_by_author'][
1280				data['published_by_author_keys'][key]
1281			],
1282			data_new_max_val
1283		);
1284
1285		if (count > count_max) {
1286			return;
1287		}
1288
1289		VV.public_stats['_authors_labels'][count] = 
1290			VV.public_stats['authors'][
1291				data['published_by_author_keys'][key]
1292			];
1293
1294		return [
1295			count++,
1296			data['published_by_author'][
1297				data['published_by_author_keys'][key]
1298			]
1299		]; 
1300	});
1301
1302	$.plot(
1303		$("#public-stats-placeholder-published-by-author"),
1304		[{
1305			data: data_new,
1306			label:	$("#public-stats-placeholder-published-by-author").
1307				attr('vv-label') || "Höfundur",
1308			color:	$("#public-stats-placeholder-published-by-author").
1309				attr('vv-color') || "#888"
1310		}], 
1311		{
1312			bars: { show: true, barWidth: 0.5, fill: 0.9 },
1313			xaxis: { ticks: [], autoscaleMargin: 0.02 },
1314			yaxis: { min: 0, max: data_new_max_val + 50 },
1315			grid: { markings: [], hoverable: true, clickable: true }
1316		}
1317	);
1318                
1319
1320	$("#public-stats-placeholder-published-by-author").bind("plothover", function (event, pos, item) {
1321		if ( ! item ) {
1322			$("#public-stats-tooltip").hide();
1323			return;
1324		}
1325
1326		var tooltip_txt = VV.public_stats['_authors_labels'][item.datapoint[0]];
1327
1328		$("#public-stats-tooltip").html(vv_uc_first(tooltip_txt))
1329			.css({top: item.pageY + 5, left: item.pageX + 5})
1330			.fadeIn(200);
1331	});
1332
1333 
1334	/*
1335	 * Draw 'published by month'
1336	 */
1337
1338	var data_new = Array();
1339
1340	for (var key in data['published_by_month']) {
1341		data_new.push(
1342			[ new Date(key), data['published_by_month'][key] ]
1343		);
1344	}
1345
1346	$.plot("#public-stats-placeholder-published-by-month", 
1347		[{
1348			data: data_new,
1349			color:	$("#public-stats-placeholder-published-by-month").
1350				attr('vv-color') || "#888"
1351		}], 
1352		{
1353			xaxis: { mode: "time", tickDecimals: 0, tickSize: 0 },
1354			lines: { show: true },
1355			points: { show: true },
1356			grid: { hoverable: true, clickable: true },
1357		}
1358	);
1359
1360	$("#public-stats-placeholder-published-by-month").bind("plothover", function (event, pos, item) {
1361		if ( ! item ) {
1362			$("#public-stats-tooltip").hide();
1363			return;
1364		}
1365
1366	
1367		var months = [	'Janúar', 'Febrúar', 'Mars', 'Apríl', 
1368				'Maí', 'Júní', 'Júlí', 'Ágúst', 
1369				'September', 'Október', 'Nóvember', 'Desember'
1370		];
1371
1372		var d = new Date(item.datapoint[0]);
1373		var tooltip_txt = '' + months[d.getMonth()] + ' ' + (1900 + d.getYear());
1374
1375		$("#public-stats-tooltip").html(tooltip_txt)
1376			.css({top: item.pageY + 5, left: item.pageX + 5})
1377			.fadeIn(200);
1378	});
1379
1380
1381	/*
1382	 * Average word-count of answer by category
1383	 */
1384
1385
1386	var data_new_max_val = 50;
1387	var count = 0;
1388	var count_max = $("#public-stats-placeholder-words-by-category").
1389			attr('vv-display-max') || 75; 
1390
1391	var data_new = Object.keys(
1392		data['words_by_category_keys']
1393	).map(function(key) {
1394		data_new_max_val = Math.max(
1395			data['words_by_category'][
1396				data['words_by_category_keys'][key]
1397			],
1398			data_new_max_val
1399		);
1400
1401		if (count++ > count_max) {
1402			return;
1403		}
1404
1405		return [
1406			key,
1407			data['words_by_category'][
1408				data['words_by_category_keys'][key]
1409			]
1410		]; 
1411	});
1412
1413	$.plot(
1414		$("#public-stats-placeholder-words-by-category"),
1415		[{
1416			data: data_new,
1417			label:	$("#public-stats-placeholder-words-by-category").
1418				attr('vv-label') || "Flokkur",
1419			color:	$("#public-stats-placeholder-words-by-category").
1420				attr('vv-color') || "#888"
1421		}], {
1422			bars: { show: true, barWidth: 0.5, fill: 0.9 },
1423			xaxis: { ticks: [], autoscaleMargin: 0.02 },
1424			yaxis: { min: 0, max: data_new_max_val + 50 },
1425			grid: { markings: [], hoverable: true, clickable: true }
1426		}
1427	);
1428                
1429
1430	$("#public-stats-placeholder-words-by-category").bind("plothover", function (event, pos, item) {
1431		if ( ! item ) {
1432			$("#public-stats-tooltip").hide();
1433			return;
1434		}
1435
1436		var tooltip_txt = VV.public_stats['categories'][
1437				VV.public_stats['words_by_category_keys'][
1438					item.datapoint[0]
1439				]
1440		];
1441
1442		$("#public-stats-tooltip").html(vv_uc_first(tooltip_txt))
1443			.css({top: item.pageY + 5, left: item.pageX + 5})
1444			.fadeIn(200);
1445	});
1446
1447 
1448	/*
1449	 * Draw 'visits per day'
1450	 */
1451
1452	var data_new = Array();
1453
1454	for (var key in data['visits_per_day']) {
1455		if (data['visits_per_day'][key] == 0) {
1456			continue;
1457		}
1458
1459		data_new.push(
1460			[ new Date(key), '' + data['visits_per_day'][key] ]
1461		);
1462	}
1463
1464	$.plot("#public-stats-placeholder-visits-per-day", 
1465		[{
1466			data: data_new,
1467			color:	$("#public-stats-placeholder-visits-by-day").
1468				attr('vv-color') || "#888"
1469		}], 
1470		{
1471			xaxis: { mode: "time", tickDecimals: 0, tickSize: 0 },
1472			lines: { show: true },
1473			points: { show: true },
1474			grid: { hoverable: true, clickable: true },
1475		}
1476	);
1477
1478	$("#public-stats-placeholder-visits-per-day").bind("plothover", function (event, pos, item) {
1479		if ( ! item ) {
1480			$("#public-stats-tooltip").hide();
1481			return;
1482		}
1483
1484	
1485		var months = [	'Janúar', 'Febrúar', 'Mars', 'Apríl', 
1486				'Maí', 'Júní', 'Júlí', 'Ágúst', 
1487				'September', 'Október', 'Nóvember', 'Desember'
1488		];
1489
1490		var d = new Date(item.datapoint[0]);
1491		var tooltip_txt = d.getDate() + ' ' + months[d.getMonth()] + ' ' + (1900 + d.getYear());
1492
1493		$("#public-stats-tooltip").html(tooltip_txt)
1494			.css({top: item.pageY + 5, left: item.pageX + 5})
1495			.fadeIn(200);
1496	});
1497
1498
1499	var tmp_xaxis_labels = $(".public-stats-container-container  .xAxis .tickLabel");
1500
1501	/*
1502	 * Labels on x-axis are by default in
1503	 * English -- switch them to Icelandic.
1504	 */
1505	for (i = 0; i < tmp_xaxis_labels.length; i++) {
1506		tmp_label = tmp_xaxis_labels[i];
1507
1508		switch(tmp_label.innerHTML) {
1509			case 'May':
1510				tmp_label.innerHTML = 'Maí'
1511				break;
1512
1513			case 'Jun':
1514				tmp_label.innerHTML= 'Jún';
1515				break;
1516
1517			case 'Jul':
1518				tmp_label.innerHTML= 'Júl';
1519				break;
1520
1521			case 'Aug':
1522				tmp_label.innerHTML = 'Ágú';
1523				break;
1524
1525			case 'Oct':
1526				tmp_label.innerHTML = 'Okt';
1527				break;
1528
1529			case 'Nov':
1530				tmp_label.innerHTML = 'Nóv';
1531				break;
1532
1533			case 'Dec':
1534				tmp_label.innerHTML = 'Des';
1535				break;
1536		}
1537	}
1538}
1539
1540/*
1541 * For those objects that can be resized --
1542 * they have the cass "vv-objects-resizable" --
1543 * actually resize if needed.
1544 */
1545function vv_resize_objects() {
1546	if ( vv_resizing_objects_lock == true ) {
1547		return;
1548	}
1549
1550	vv_resizing_objects_lock = true;
1551
1552	/*
1553	 * Resize various objects, such
1554	 * as videos.
1555	 */ 	
1556	objs_resizable = $(".vv-objects-resizable")
1557
1558	for (i = 0; i < objs_resizable.length; i++) {
1559		obj_item = objs_resizable[i];
1560
1561		obj_item_ideal_width = obj_item
1562			.attributes
1563			.getNamedItem("vv-ideal-width")
1564			.value;
1565
1566		if (typeof obj_item_ideal_width == undefined) {
1567			continue;
1568		}
1569
1570		/*
1571		 * If window is smaller than ideal width of object,
1572		 * make the object smaller than the window.
1573		 */
1574		if ((window.innerWidth * 0.70) <= obj_item_ideal_width) {
1575			obj_item.width =
1576				window
1577					.innerWidth * 0.70;
1578		}
1579
1580		/*
1581		 * If window is larger than ideal width of object,
1582		 * make the object the ideal width.
1583		 */
1584		else {
1585			obj_item.width = obj_item_ideal_width;
1586		}
1587	}
1588
1589	/*
1590	 * If we have statistics objects,
1591	 * resize those as well. Note that they
1592	 * behave differently from for instance
1593	 * videos, and so need different treatment.
1594	 */
1595	stats_resizable = $(".public-stats-placeholder");
1596
1597	for (i = 0; i < stats_resizable.length; i++) {
1598		stats_item = stats_resizable[i];
1599
1600		stats_item_ideal_width = stats_resizable[i]
1601			.attributes
1602			.getNamedItem("vv-ideal-width")
1603			.value;
1604
1605		/*
1606		 * If window is smaller than ideal width of object,
1607		 * make the object smaller than the window.
1608		 */
1609		if ((window.innerWidth * 0.70) <= stats_item_ideal_width) {
1610			$("#" + stats_item.id).css('width', window.innerWidth * 0.70);
1611		}
1612
1613		/*
1614		 * If window is larger than ideal width of object,
1615		 * make the object the ideal width.
1616		 */
1617		else {
1618			$("#" + stats_item.id).css('width', stats_item_ideal_width);
1619		}
1620
1621		/*
1622		 * Word-cloud is problematic,
1623		 * remove all child nodes
1624		 * before rendering again.
1625		 */
1626
1627		if (stats_item.id == "public-stats-placeholder-published-by-keyword") {
1628			vv_stats_clear_keyword_clouds(false);
1629		}
1630	}
1631
1632	if (stats_resizable.length > 0) {
1633		vv_public_stats_render(
1634			vv_public_stats_render_lang
1635		);
1636
1637		/*
1638		 * Because JavaScript is JavaScript,
1639		 * things are loaded after a delay,
1640		 * and so we will remove extra keywords 
1641		 * after a delay too.
1642		 */
1643		window.setTimeout(
1644			function() {
1645				vv_stats_clear_keyword_clouds(true);
1646			},
1647			1200
1648		);
1649	}
1650
1651	// Resize word-cloud on the fly, after a delay.
1652	setTimeout(
1653		() => $(".b-page .article-wrapper.layout-item #public-stats-placeholder-published-by-keyword.public-stats-placeholder svg")
1654			.css('width', 460),
1655		500
1656	);
1657
1658	vv_resizing_objects_lock = false;
1659}
1660
1661/*
1662 * For keyword statistics cloud, remove all or some child-nodes
1663 * of container <div>. This needs to be done because when
1664 * statistics is re-rendered the keyword cloud will be
1665 * displayed multiple times, unless we do this.
1666 */
1667function vv_stats_clear_keyword_clouds(keep_latest) {
1668	 tmp_keyword_children = $("#public-stats-placeholder-published-by-keyword")
1669		.children();
1670
1671	if (tmp_keyword_children.length > 0) {
1672		for (i = tmp_keyword_children.length - 1; i >= 0; i--) {
1673			if ( (keep_latest == true) && (i == 0) ) {
1674				continue;
1675			}
1676
1677			tmp_keyword_children[i].remove();
1678		}
1679	}
1680}
1681
1682/*
1683 * Handle when user switches between LLM-question box and search
1684 * box on front-page. Save choice in cookie.
1685 */
1686function vv_llm_classic_search_boxes_toggle(obj) {
1687	if (typeof obj === 'object') {
1688		current_box_id = obj.currentTarget.parentElement.parentElement.id;
1689	}
1690
1691	else {
1692		current_box_id = obj;
1693	}
1694
1695	/*
1696	 * Switch boxes according to choice.
1697	 */
1698	let chosen_box = '';
1699
1700	if (current_box_id == 'ai-search-box') {
1701		chosen_box = "classic-search";
1702		$("#ai-search-box").addClass("ai-hero--hidden");
1703		$("#classic-search-box").removeClass("classic-search--hidden");	
1704	}
1705
1706	else {
1707		chosen_box = "ai-hero";
1708		$("#ai-search-box").removeClass("ai-hero--hidden");
1709		$("#classic-search-box").addClass("classic-search--hidden");	
1710	}
1711
1712	/*
1713	 * Save choice in cookie.
1714	 */
1715	oneyear = new Date();
1716	oneyear.setFullYear(oneyear.getFullYear() + 1);
1717
1718	jQuery.cookie(
1719		"search-box-chosen",
1720		chosen_box,
1721		{ expires: oneyear }
1722	);
1723}
1724
1725/*
1726 * Handle sending question via LLM-question form on frontpage.
1727 */
1728function vv_llm_question_send(event) {
1729	// Prevent submit.
1730	event.preventDefault();
1731
1732	// Disable submit button.
1733	$('.ai-hero .btn').css("pointer-events", "none");
1734	$('.ai-hero .btn').css("opacity", "0.6");
1735
1736	// Save button text & change button.
1737	let send_button_text = $('.ai-hero .btn').text();
1738	$('.ai-hero .btn').text("Augnablik!");
1739
1740	// Set timeout.
1741	$.ajaxSetup({
1742		timeout: 3 * 60 * 1000
1743	});
1744
1745	// Send question.
1746	$.getJSON("/misc.php", {
1747		"module": "llm_question_send",
1748		"question": $("#ai-search-input-box").val()
1749		},
1750		async function(data) {
1751			if (data.ok == 1) {
1752				// Success. Redirect user to answer.
1753				window.location.href = "/?id=" + data.question_id;
1754			}
1755
1756			else {
1757				// Handle errors.
1758				$(".ai-search-error-msg").text(data.errorstr);
1759				$('.ai-hero .btn').css("pointer-events", "auto");
1760				$('.ai-hero .btn').css("opacity", "1");
1761				$('.ai-hero .btn').text(send_button_text);
1762			}
1763		}
1764	);
1765}
1766/*
1767 * Retrieve LLM-question from backend
1768 */
1769function vv_llm_question_fetch(question_id, try_cnt = 1) {
1770	// Set timeout.
1771	$.ajaxSetup({
1772		timeout: 3 * 60 * 1000
1773	});
1774
1775	// Send question.
1776	$.getJSON("/misc.php", {
1777		"module": "llm_question_fetch",
1778		"question_id": question_id
1779		},
1780		function(data) {
1781			// If not ok, or answer is null, do not do anything.
1782			if (data.ok != 1 || data.answer === null) {
1783				$(".article-text").html(data.errorstr);
1784				return;
1785			}
1786
1787			// Success. Render answer & remove LLM loading indicator.
1788			$(".lp-loader").remove();
1789			$("body").removeClass("lp-generating");
1790
1791			$(".article-text").prepend(data.answer);
1792			$('.ai-review-prompt').appendTo('.article-text');
1793			$(".ai-review-prompt").css("display", "inline-block");
1794
1795			/*
1796			 * Add related questions.
1797			 */
1798			related_questions = [];
1799
1800			for (const related of data.questions_related) {
1801				related_questions.push(
1802					$("<article>")
1803						.addClass("recent-article")
1804						.append(
1805							$("<a>")
1806								.addClass("recent-article-wrapper")
1807								.attr("href", related.url)
1808								.append(
1809									$("<div>")
1810										.addClass("recent-category")
1811										.text(related.cat_first),
1812									$("<h4>")
1813										.text(related.title)
1814								)
1815						)
1816				);
1817			}
1818
1819			if (related_questions.length > 0) {
1820				$('.main-content').append(
1821					$('<section>')
1822						.addClass('content-below backdrop-blue')
1823						.append(
1824							$('<div>')
1825								.addClass('recent-answers layout-item')
1826								.append(
1827									$('<h2>')
1828									.addClass('section-title')
1829									.text(
1830										(
1831											related_questions.length == 1 ? 'Svar' : 'Svör'
1832										) + ' fræðafólks sem gervigreindin nýtti'
1833									),
1834
1835									$('<div>')
1836									.addClass('recent-answers-wrapper')
1837									.append(
1838										related_questions
1839									)
1840								)
1841						)
1842				);
1843			}
1844		}
1845	).fail(function(jqXHR,textStatus, errorThrown) {
1846		/*
1847		 * In case of HTTP request failure, catch and
1848		 * retry within reasonable limits.
1849		 */
1850		if (try_cnt > 3) {
1851			$(".article-text").html("Óvænt villa átti sér stað. Vinsamlega reyndu aftur eftir svolitla stund.");
1852			return;
1853		}
1854
1855		// Retry.
1856		vv_llm_question_fetch(question_id, ++try_cnt);
1857	});
1858}
1859
1860/*
1861 * Rate LLM-generated answer.
1862 */
1863function vv_llm_question_rate(question_id, rating) {
1864	$.getJSON("/misc.php", {
1865		"module": "llm_question_rate",
1866		"question_id": question_id,
1867		"rating": rating,
1868		},
1869		function(data) {
1870			if (data.ok == 1) {
1871				$(".ai-review-thanks").show();
1872				$(".ai-review-error").css("display", "none");
1873			}
1874
1875			else {
1876				$(".ai-review-error").text(data.errorstr);
1877				$(".ai-review-error").css("display", "block");
1878			}
1879		}
1880	);
1881}
1882

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.