'); var hasMatchingItems = false; // Loop through each official in listOfficials and create .item-wrapper for each $.each(official.listOfficials, function(i, official) { hasMatchingItems = true; // Create .item-wrapper for each official var itemWrapper = $('
'); itemWrapper.attr("search", official.name).attr("sort", i); // Create the item container for the official var item = $('
').appendTo(itemWrapper); var itemContent = $('
').appendTo(item); // Official's name var itemInfo = $('
').css("background-color", color).appendTo(itemContent); var itemName = $('

' + official.name + '

').appendTo(itemInfo); // Official's image or placeholder in .item-image var itemImage = $('
').appendTo(itemInfo); // Load image or add placeholder var imgSrc = '/VisBillede.aspx?OfficialID=' + official.id; if (official.img) { // Queue images for sequential loading officialQueue.push({ imgSrc: imgSrc, itemImage: itemImage, // Pass itemImage directly official: official }); } else { // Add a placeholder if no image createPlaceholder(itemImage, official.name); } // Official's additional info content var itemInfoContent = $('
').appendTo(itemInfo); var itemInfoInner = $('
').appendTo(itemInfoContent); // Details such as official's description if (official.description && (official.description.replace(/]*>/g, '').trim().length > 0 || /]*src=["'][^"']+["'][^>]*>/i.test(official.description))) { var descriptionHTML = official.description; if (!$('body').hasClass('bestyr_keepstyle')) { descriptionHTML = $('
') .html(official.description) .find('*') .removeAttr('style') .end() .html(); } var itemTeaser = $('
') .html(descriptionHTML) .appendTo(itemInfo); } if (official.mobile) { $('').appendTo(itemInfoInner); } // Add email if it has a value if (official.email) { $('').appendTo(itemInfoInner); } // Append the itemWrapper for this official under the kmRows kmRows.append(itemWrapper); }); if (!hasMatchingItems) { kmRows.remove(); } }); // Start processing the image queue for loaded items processofficialQueue(officialQueue); }, error: function(xhr, status, error) { console.error('Error fetching JSON data:', error); } }); // Helper function to create a placeholder div with initials if no image is found function createPlaceholder(itemImage, name) { var initials = name.split(' ').map(word => word[0]).join('').toUpperCase(); var noImgDiv = $('
' + initials + '
'); itemImage.addClass("NoImgContainer") itemImage.append(noImgDiv); } // Function to process the official queue one at a time and load images function processofficialQueue(queue) { if (queue.length === 0) return; var nextItem = queue.shift(); // Check if the image is available using the JSON 'img' property if (nextItem.official.img === "true") { // Check if img is true as a string checkImageSize(nextItem.imgSrc, function(fileSize) { if (fileSize && fileSize > 0) { if (fileSize > 150000) { loadImageToCanvas(nextItem.imgSrc, nextItem.itemImage, function() { nextItem.itemImage.closest('.item-wrapper').removeClass('hidebestyr'); addDescriptionIfNeeded(nextItem); // Check description after loading processofficialQueue(queue); }); } else { var img = $('').attr('src', nextItem.imgSrc).attr('alt', nextItem.official.name); nextItem.itemImage.append(img); nextItem.itemImage.closest('.item-wrapper').removeClass('hidebestyr'); addDescriptionIfNeeded(nextItem); // Check description after loading processofficialQueue(queue); } } else { createPlaceholder(nextItem.itemImage, nextItem.official.name); nextItem.itemImage.closest('.item-wrapper').removeClass('hidebestyr'); addDescriptionIfNeeded(nextItem); // Check description after loading processofficialQueue(queue); } }); } else { // No image exists, create a placeholder directly createPlaceholder(nextItem.itemImage, nextItem.official.name); nextItem.itemImage.closest('.item-wrapper').removeClass('hidebestyr'); addDescriptionIfNeeded(nextItem); // Check description after loading processofficialQueue(queue); } } function addDescriptionIfNeeded(nextItem) { // Select the existing .item-teaser within the relevant .item-info container var itemTeaser = nextItem.itemImage.closest('.item-info').find('.item-teaser'); var itemWrapper = nextItem.itemImage.closest('.item-wrapper'); // Ensure it exists before proceeding if (itemTeaser.length && itemTeaser.text().trim().length > 0) { // Apply max-height and overflow hidden styles initially itemTeaser.css({ "max-height": "200px", "overflow": "hidden" }); // Add a slight delay to measure the height after styles are applied var measuredHeight = itemTeaser.outerHeight(); // Check if the height is exactly 200px and add "See more" link if so if (measuredHeight === 200) { $('
Se hele beskrivelsen
') .appendTo(itemTeaser) .on("click", function() { itemTeaser.css("max-height", "none"); // Expand content itemWrapper.addClass("big"); $(this).remove(); // Remove "See more" link }); } } else { //console.log("No valid .item-teaser found or it is empty for:", nextItem.official.name); } } // Function to check the Content-Length of an image without loading it fully function checkImageSize(imgSrc, callback) { $.ajax({ url: imgSrc, type: 'HEAD', success: function(data, status, xhr) { var fileSize = parseInt(xhr.getResponseHeader("Content-Length"), 10); callback(fileSize); }, error: function() { callback(0); // If HEAD request fails, treat as no image } }); } // Function to load image to canvas with a minimum intrinsic width of 500px, max width 600px, and max height 1000px function loadImageToCanvas(imgSrc, itemImage, onComplete) { var tempImage = new Image(); tempImage.onload = function() { var minWidth = 160; // Minimum intrinsic width for better quality var maxWidth = 200; // Maximum intrinsic width var maxHeight = 1000; // Maximum intrinsic height var width = tempImage.width; var height = tempImage.height; // Ensure minimum intrinsic width for better quality if (width maxWidth || height > maxHeight) { var scalingFactor = Math.max(width / maxWidth, height / maxHeight); width = Math.floor(width / scalingFactor); height = Math.floor(height / scalingFactor); } // Create canvas with the adjusted intrinsic dimensions var canvas = document.createElement('canvas'); canvas.width = width; // Intrinsic canvas width for quality canvas.height = height; // Intrinsic canvas height for quality var ctx = canvas.getContext('2d'); ctx.imageSmoothingEnabled = true; ctx.drawImage(tempImage, 0, 0, width, height); // Set the canvas to scale responsively $(canvas).css({ width: '100%', // Display width set to 100% height: 'auto' // Maintain aspect ratio }).attr('alt', itemImage.find('p').text()); // Append the canvas to itemImage container itemImage.append(canvas); onComplete(); // Signal completion }; tempImage.onerror = function() { createPlaceholder(itemImage, itemImage.find('p').text()); onComplete(); }; tempImage.src = imgSrc; } }); function hexToRgb(hex) { // Remove the hash at the start if it's there hex = hex.replace('#', ''); // Parse r, g, b values var r = parseInt(hex.substring(0, 2), 16); var g = parseInt(hex.substring(2, 4), 16); var b = parseInt(hex.substring(4, 6), 16); return { r: r, g: g, b: b }; } // Function to convert RGB to HSL function rgbToHsl(r, g, b) { r /= 255, g /= 255, b /= 255; var max = Math.max(r, g, b), min = Math.min(r, g, b); var h, s, l = (max + min) / 2; if (max == min) { h = s = 0; // achromatic } else { var d = max - min; s = l > 0.5 ? d / (2 - max - min) : d / (max + min); switch (max) { case r: h = (g - b) / d + (g 1) t -= 1; if (t 160; } function adjustColor(color, amount, opacity) { opacity = (opacity !== undefined) ? opacity : "1"; amount = (amount !== undefined) ? amount : 0; color = color.replace('#', ''); var r = parseInt(color.substring(0, 2), 16); var g = parseInt(color.substring(2, 4), 16); var b = parseInt(color.substring(4, 6), 16); // Convert RGB to HSL var hsl = rgbToHsl(r, g, b); // Adjust lightness (value) var adjustedL = hsl[2] + amount / 100; // Convert amount to a percentage // Set maximum lightness threshold var maxLightness = 0.9; // Adjust as needed // Ensure adjusted lightness stays within 0 to maxLightness adjustedL = Math.min(Math.max(adjustedL, 0), maxLightness); // Convert back to RGB var rgb = hslToRgb(hsl[0], hsl[1], adjustedL); // Convert RGB to hex var result = '#' + rgb.map(component => { var hex = component.toString(16); return hex.length === 1 ? '0' + hex : hex; }).join(''); // Combine with opacity and return result return 'rgba(' + rgb.join(',') + ', ' + opacity + ')'; } $('#searchInput').on('keyup', function() { let searchTerm = $(this).val().toLowerCase(); $('.km_rows').each(function() { let rows = $(this); let anyMatches = false; rows.find('.item-wrapper').each(function() { let itemWrapper = $(this); let wrapperText = itemWrapper.text().toLowerCase(); // Get all text content within .item-wrapper // Check if the search term is within the full text content if (wrapperText.includes(searchTerm)) { itemWrapper.show(); anyMatches = true; } else { itemWrapper.hide(); } }); // Show the title if any item within this row matches the search if (anyMatches) { rows.find('.title-name').show(); } else { rows.find('.title-name').hide(); } }); }); $('#resetButton').on('click', function() { $('#searchInput').val(''); // Empty the search input field $('.item-wrapper, .title-name').show(); // Show all items window.clickedTag = ''; // Reset clicked tag }); });
"; }else { html += "
"; } count++; }); $(this).append(html); $('#banner-slider').slick({ dots: false, autoplay: true, infinite: true, arrows: true, prevArrow: '#banner .prev', nextArrow: '#banner .next', autoplaySpeed: 3000, speed: 300, slidesToShow: 1, slidesToScroll: 1 }); $("#banner-slider img[lazy]").lazy({ viewport: function(img) { $("#banner-slider img[nlazy]").each(function(){ $(this).attr("lazy", $(this).attr("nlazy")); $(this).removeAttr("nlazy"); }); $("#banner-slider img[lazy]").lazy({ onload: function(img) { //console.log(img); var parent = $(img).parent(); parent.css({ "background-image": "url(" + $(img).attr("src") + ")" }); $(img).remove(); } }); } }); }); $("#news-slider").lazy({ viewport: function(img) { var load_url = location.protocol + "//" + location.host + "/cms/NewsTenMostRecentIframeOverview.aspx"; $("#news-slider").loadPage(load_url, function(response){ var html = ""; $(response).find(".KMNewsItem").each(function() { var img = ($(this).find("img").length != 0) ? $(this).find("img") : ""; var src = (img != "" && img.attr("lazy") != "") ? img.attr("lazy") : ""; if(src != "") { $(this).find(".KMNewsItemInner").prepend(""); img.remove(); }else { $(this).find(".KMNewsItemInner").prepend(""); } var date = ($(this).find(".KMNewsDateTxt span").length != 0) ? $(this).find(".KMNewsDateTxt span").html() : ""; var parts = date.split('.'); var format = parts[1] + '/' + parts[0] + '/' + parts[2]; var months = { "01": "Januar", "02": "Februar", "03": "Marts", "04": "April", "05": "Maj", "06": "Juni", "07": "Juli", "08": "August", "09": "September", "10": "Oktober", "11": "November", "12": "December" }; var day = parts[0]; var month = months["" + parts[1]]; var year = parts[2]; var date = "" + day + ". " + month + " " + year; $(this).find(".KMNewsDateTxt span").html(date); $(this).find(".KMNewsInfo").html(function (i, html) { return html.replace(/ /g, ''); }); html += '
' + $(this).html() + '
'; }); $("#news-slider").append(html); $('#news-slider').slick({ dots: false, autoplay: false, infinite: true, arrows: true, prevArrow: '#news .prev', nextArrow: '#news .next', autoplaySpeed: 3000, speed: 300, slidesToShow: 1, slidesToScroll: 1 }); }); } }); $("#events").lazy({ viewport: function(img) { var load_url = location.protocol + "//" + location.host + "/cms/EventIframeOverviewImg.aspx"; $("#events").loadPage(load_url, function(response){ var html = ""; $(response).find(".KMEventItem").each(function(){ var img = ($(this).find("img").length != 0) ? $(this).find("img") : ""; var src = (img != "" && img.attr("lazy") != "") ? img.attr("lazy") : ""; var date = ($(this).find(".KMEventStartDate").length != 0) ? $(this).find(".KMEventStartDate").html() : ""; var parts = date.split('.'); var format = parts[1] + '/' + parts[0] + '/' + parts[2]; var months = { "01": "Januar", "02": "Februar", "03": "Marts", "04": "April", "05": "Maj", "06": "Juni", "07": "Juli", "08": "August", "09": "September", "10": "Oktober", "11": "November", "12": "December" }; var day = parts[0]; var month = months["" + parts[1]]; if(img != "") { $(this).prepend(""); img.remove(); }else { $(this).prepend(""); } var content = ""; content += "

Start: " + $(this).find(".KMEventStartDate").html() + "

"; content += "

Slut: " + $(this).find(".KMEventEndDate").html() + "

"; $(this).find(".KMEventContent").html(content); html += '
' + "
" + day + "" + month + "
" + $(this).html() + '
INFO OG TILMELDING
'; }); $("#events-slider").append(html); $('#events-slider').slick({ dots: false, autoplay: true, infinite: true, arrows: true, prevArrow: '#events .prev', nextArrow: '#events .next', autoplaySpeed: 3000, speed: 300, slidesToShow: 1, slidesToScroll: 1 }); }); } }); var container_width = $('#facebook-feed').width(); $('#facebook-feed').html(''); FB.XFBML.parse(); $( window ).resize(function() { var container_width = $('#facebook-feed').width(); $('#facebook-feed').html(''); FB.XFBML.parse(); }); $("body #sponsors").lazy({ viewport: function(img) { var load_url = location.protocol + "//" + location.host + "/cms/cmsbannerandsponsoriframe.aspx?issponsor=true"; $("body #sponsors").loadPage(load_url, function(response){ var html = ""; console.log(response); $(response).find("img").each(function(){ var img = ($(this).attr("lazy") != undefined) ? $(this).attr("lazy") : ""; var link = ""; if ($(this).parent().is("a")) { link = $(this).parent().attr("href"); } else { link = "#"; } html += "
"; }); $("#sponsor-slider").append(html); $('#sponsor-slider').slick({ dots: false, autoplay: true, infinite: true, arrows: false, prevArrow: '.prev', nextArrow: '.next', autoplaySpeed: 3000, speed: 300, slidesToShow: 3, slidesToScroll: 3, responsive: [{ breakpoint: 1024, settings: { slidesToShow: 3, slidesToScroll: 3 } }, { breakpoint: 600, settings: { slidesToShow: 2, slidesToScroll: 2 } }, { breakpoint: 480, settings: { slidesToShow: 1, slidesToScroll: 1 } }] }); }); } }); /* var scrollTop = $(window).scrollTop(); var offset = $("#menuBar").offset().top; if(scrollTop

Vores sponsorer

10