jQuery(document).ready(function() {
var MegaType = Object.freeze({"Menu":"#mega-menu-container","Category":"#mega-menu-category"});
// Truncate post content box text
// const post_content_box_height = jQuery(".post-content-boxes")[0].clientHeight; // To make this work if textbox height is changed.
jQuery(".post-content-boxes p").each(function() {
var text_arr = jQuery(this).text().split(" ");
while(jQuery(this)[0].clientHeight > 102) { // This number needs to match the height defined in class: ".post-content-boxes".
text_arr.pop();
jQuery(this).text(text_arr.join(" ")+"...");
}
});
jQuery(".instagram-images-placeholder").each(function() {
const placeholder = jQuery(this);
const number = placeholder.data('number');
jQuery.get(
'/wp-admin/admin-ajax.php', {
'action': 'the_instagram_images',
'number': number
},
function(res) {
placeholder.html(res);
})
});
const pinterest_marker = jQuery("h1.single-title-pinterest-marker");
if (pinterest_marker.length > 0) {
const is_single_hack = pinterest_marker[0].innerText;
if (is_single_hack) {
jQuery('article img').each(function() {
jQuery(this).attr('data-pin-description', is_single_hack);
});
}
}
jQuery("body").on("click", ".all-blogs-show", function() {
jQuery(".all-blogs-overlay").slideToggle(150);
jQuery.post(
'/wp-admin/admin-ajax.php', {
'action': 'show_all_blogs'
},
function(res) {
jQuery(".all-blogs-overlay").html(res);
jQuery('div.all-blogs-overlay > div.col-md-2 ').each(function() {
jQuery(this).find('a').attr('target', '_blank');
})
}
);
});
jQuery('#menu-category-li').click(function(){jQuery('#menu-category').toggle()});
jQuery('#menu-archive-li').click(function(){jQuery('#menu-archive').toggle()});
function hideOtherMegas(myType){
for (var type in MegaType) {
if (!MegaType.hasOwnProperty(type)) continue;
var obj = MegaType[type];
for (var prop in obj) {
if(!obj.hasOwnProperty(prop)) continue;
if(type != myType){
hideMega(obj);
}
}
}
}
if(document.getElementById('mega-menu-container') != null){
document.querySelectorAll('#menu-category-li').forEach(function(d){
d.classList.add('mega-enabled');
});
document.querySelectorAll('#menu-category-li > a')[1].addEventListener('mouseenter', function(input){
hideOtherMegas(MegaType.Menu);
showMega(MegaType.Menu);
});
document.querySelector('.mega-menu').addEventListener('mouseleave', function(input){
hideMega(MegaType.Menu);
});
document.querySelector('.header-image').addEventListener('mouseenter', function(input){
hideMega(MegaType.Menu);
hideMega(MegaType.Category);
});
document.querySelector('#mega-cat').innerHTML = document.querySelector('#menu-category').innerHTML;
document.querySelectorAll('#mega-cat li').forEach(function(elem){
elem.addEventListener('mouseenter', function(e){
var my_id ="cat-"+e.target.classList[1].substring(9);
document.querySelectorAll('#mega-cat li').forEach(function(elem2){
var target_id ="cat-"+elem2.classList[1].substring(9);
document.querySelector('#'+target_id).classList.add('hide-cat');
document.querySelector('#'+target_id).classList.remove('show-cat');
});
document.querySelector('#'+my_id).classList.add('show-cat');
document.querySelector('#'+my_id).classList.remove('hide-cat');
});
});
}
if(document.querySelector("#mega-menu-category") != null){
document.querySelectorAll('.menu-item-object-category').forEach(function(item,index){
if(item.parentElement && item.parentElement.parentElement && !item.parentElement.parentElement.classList.contains('has-sub') && !item.classList.contains('has-sub')) {
item.addEventListener('mouseenter',function(input){
hideOtherMegas(MegaType.Category);
showMega(MegaType.Category);
var linksplit = item.firstChild.getAttribute("href").split("/");
//Get second to last item since the url ends with /
var keyword = linksplit[linksplit.length-2];
toggleContent(keyword);
});
}
else {
item.addEventListener('mouseenter',function(){
hideOtherMegas(MegaType.Category);
});
}
});
document.querySelector("#mega-menu-category").addEventListener('mouseleave',function(input){
hideMega(MegaType.Category);
});
//Category in menu items
function toggleContent(category){
var item = document.querySelector("#cat-indviduals").children;
var i;
for(i = 0; i < item.length;i++){
if(item[i].id != "cat-"+category){
item[i].classList.add("hide-cat");
item[i].classList.remove("show-cat");
}else{
item[i].classList.add("show-cat");
item[i].classList.remove("hide-cat");
}
}
}
}
/*End*/
//DROPDOWN MENU
jQuery(".menu li:not(.mega-enabled), .topbar-menu li").on("mouseenter", function() {
jQuery(this).find("ul").first().show();
});
//DROPDOWN MENU
jQuery(".menu li:not(.mega-enabled), .topbar-menu li").on("mouseenter", function() {
jQuery(this).find("ul").first().show();
});
jQuery(".menu li, .topbar-menu li").on("mouseleave", function() {
jQuery(this).find("ul").first().hide();
});
jQuery(".dropdown a").on("click", function() {
jQuery(this).parent('.dropdown').find("ul").toggle();
});
// REPLY ON A COMMENT
jQuery("body").on("click", ".js-comment-reply-link", function(e) {
e.stopPropagation();
var val = jQuery(this).data("parent-id");
jQuery(".js-comment-reply-link").html("Svar på kommentar");
jQuery(this).html("Skriv et svar ovre til højre");
jQuery("#comment_parent").val(val);
jQuery("#cancel-comment-reply-link").show();
return false;
});
jQuery("body").on("click", "#cancel-comment-reply-link", function(e) {
e.stopPropagation();
jQuery(".js-comment-reply-link").html("Svar på kommentar");
jQuery("#comment_parent").val("0");
jQuery("#cancel-comment-reply-link").hide();
return false;
});
// add token field via ajax
var el = '';
jQuery('#commentform').append(el);
// method to set a token and add as value to dynamically added form field
function runrequests() {
jQuery.ajax({
url: '/wp-admin/admin-ajax.php',
type: 'POST',
data: {
action: 'set_comment_token',
},
dataType: 'text',
success: function(data){
jQuery("#comment_token").val(data) ;
}
});
};
runrequests();
// POST A COMMENT
jQuery('#commentform').submit(function(e) {
e.preventDefault();
const el = jQuery(this);
const comments_el = jQuery("#comments");
const logged_in = comments_el.data('logged-in');
const status = jQuery("#comment-status")
const author = el.find("[name=author]").val();
const email = el.find("[name=email]").val();
const comment = el.find("[name=comment]").val();
const require_name_email = comments_el.data('require-name-email');
if (comment == '') {
status.html(' Du skal skrive en kommentar.');
status.addClass("comment-status-error");
} else if (email == '' && require_name_email == 1 && logged_in != 1) {
status.html(' Du skal udfylde en email.');
status.addClass("comment-status-error");
} else if (author == '' && logged_in != 1) {
status.html(' Du skal udfylde et navn.');
status.addClass("comment-status-error");
} else {
status.removeClass("comment-status-error");
status.addClass("comment-status-success");
status.html(' Sender kommentar');
jQuery.ajax({
type: 'POST',
url: '/wp-admin/admin-ajax.php',
dataType: 'text',
data: {
action: 'validate_comment_token',
comment_token: jQuery('#comment_token').val()
},
// if token validates then contunie to other checks
success: function(){
jQuery.ajax({
type: 'POST',
data: jQuery("#commentform").serialize(),
url: '/wp-comments-post.php',
success: function(data) {
if (comments_el.data('moderation') == '1') {
status.html(' Kommentaren blev gemt, men afventer godkendelse');
} else if (comments_el.data('whitelist') == '1') {
status.html(' Kommentaren blev gemt, men afventer godkendelse (medmindre du tidligere har haft en godkendt kommentar)');
} else {
status.html(' Kommentaren blev gemt');
}
el.find("[name=comment]").val('');
if (jQuery("#comment_parent").val() == '0') {
jQuery('html, body').animate({
scrollTop: comments_el.offset().top - 70
}, 300);
}
found = jQuery(data).find(".commentlist");
jQuery("#comment-list").html(found);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
status.removeClass("comment-status-success");
status.addClass("comment-status-error");
if (errorThrown == 'Forbidden') {
status.html(' Du skriver for hurtigt. ');
} else if (errorThrown == 'Internal Server Error') {
status.html(' Der opstod en fejl. Du poster muligvis den samme kommentar igen.');
} else {
status.html(' Der opstod en fejl ( du benytter muligvis en forældet browser. Opdater venligst til nyeste udgave og forsøg igen. ');
}
}
});
},
error: function(){
status.html(' Du sender din kommentar for hurigt, vent lidt og tryk skriv kommentar igen');
status.addClass("comment-status-error");
}
});
}
return false;
});
//OPEN SEARCH
jQuery(".search-link").on("click", function() {
jQuery("#overlay").fadeIn(250);
ga('set', 'anonymizeIp', true)
ga('send', 'event', 'Search', 'click', 'show search');
jQuery("#s").focus();
return false;
});
//CLOSE SEARCH
jQuery("#overlay-close").on("click", function() {
jQuery("#overlay").fadeOut(250);
});
jQuery('#overlay').mousedown(function(e) {
var clicked = jQuery(e.target); // get the element clicked
if (clicked.is('#overlay-search') || clicked.parents().is('#overlay-search')) {
return; // click happened within the dialog, do nothing here
} else { // click was outside the dialog, so close it
jQuery('#overlay').fadeOut(250);
}
});
//MEGA MENU
// hide all dropdowns , drop down delay
// const megaMenu = jQuery('.cluster ul');
jQuery('.dropdown', '.cluster ul').hide();
jQuery('li', '.cluster ul').hover(
function() { // on hover in
const me = jQuery(this);
// flag to indicate that the mouse
// has not left the area
me.attr('mIn', 'true');
setTimeout(function() {
// if the mouse is still in
if (me.attr('mIn') == 'true') {
//show the drop down
jQuery('.cluster-blog-info', me).slideDown(200);
}
}, 250);
},
function() { // on hover out
// set the flag as the mouse has left
jQuery(this).attr('mIn', 'false');
// hide the drop down
const me = jQuery(this);
setTimeout(function() {
// if the mouse is still in
if (me.attr('mIn') == 'false') {
//show the drop down
jQuery('.cluster-blog-info', me).slideUp(100);
}
}, 350);
}
);
//ADDS TARGET BLANK TO ALL COMMENT LINKS
jQuery('#comments a').each(function() {
jQuery(this).attr('target', '_blank');
});
// responsify
!function(t) {
t.fn.responsify = function() {
return this.each(function() {
var e, r, a, i, o, h, n, s, f, u, c, d, p = t(this);
if (e = p.width(), r = p.height(), a = p.parent().width(), i = p.parent().height(), o = Number(p.attr("data-focus-left")), h = Number(p.attr("data-focus-top")), n = Number(p.attr("data-focus-right")), s = Number(p.attr("data-focus-bottom")), e / r > a / i) {
var b = (n - o) * e;
b / r > a / i ? (u = r * a / b, f = e * a / b, d = -o * f, c = (i - u) / 2) : (u = i, f = i * e / r, d = a / 2 - (o + n) * f / 2, d = d > 0 ? 0 : d, d = a - d - f > 0 ? a - f : d, c = 0)
} else {
var l = (s - h) * r;
l / e > i / a ? (f = e * i / l, u = r * i / l, c = -h * u, d = (a - f) / 2) : (f = a, u = a * r / e, c = i / 2 - (h + s) * u / 2, c = c > 0 ? 0 : c, c = i - c - u > 0 ? i - u : c, d = 0)
}
p.parent().css({
overflow: "hidden"
}), p.css({
position: "relative",
height: u,
width: f,
left: d,
top: c
})
})
}
}(jQuery);
// rewardstyle
! function(d, s, id) {
var e, p = /^http:/.test(d.location) ? 'http' : 'https';
if (!d.getElementById(id)) {
e = d.createElement(s);
e.id = id;
e.src = p + '://widgets.rewardstyle.com/js/shopthepost.js';
d.body.appendChild(e);
}
if (typeof window.__stp === 'object')
if (d.readyState === 'complete') {
window.__stp.init();
}
}(document, 'script', 'shopthepost-script');
});
function responsive_img(src) {
if (window.innerWidth < 768) {
this.src = this.src.replace("w=500", "w=1000").replace("h=500", "h=1000");
}
}
function showMega() {
// show menu
document.querySelector('.mega-menu').classList.add('show-mega');
jQuery('.mega-menu').css("z-index", 10000);
}
function hideMega() {
document.querySelector('.mega-menu').classList.remove('show-mega');
}