/* ############################ ######## PLUGINS ######## ############################ */ /* JRESPOND ========== */ /*! jRespond.js v 0.10 | Author: Jeremy Fields [jeremy.fields@viget.com], 2013 | License: MIT */ !function(a,b,c){"object"==typeof module&&module&&"object"==typeof module.exports?module.exports=c:(a[b]=c,"function"==typeof define&&define.amd&&define(b,[],function(){return c}))}(this,"jRespond",function(a,b,c){"use strict";return function(a){var b=[],d=[],e=a,f="",g="",i=0,j=100,k=500,l=k,m=function(){var a=0;return a="number"!=typeof window.innerWidth?0!==document.documentElement.clientWidth?document.documentElement.clientWidth:document.body.clientWidth:window.innerWidth},n=function(a){if(a.length===c)o(a);else for(var b=0;b=e[c].enter&&a<=e[c].exit){b=!0;break}b&&f!==e[c].label?(g=f,f=e[c].label,p()):b||""===f||(f="",p())},r=function(a){if("object"==typeof a){if(a.join().indexOf(f)>=0)return!0}else{if("*"===a)return!0;if("string"==typeof a&&f===a)return!0}},s=function(){var a=m();a!==i?(l=j,q(a)):l=k,i=a,setTimeout(s,l)};return s(),{addFunc:function(a){n(a)},getBreakpoint:function(){return f}}}}(this,this.document)); var jRes = jRespond([ { label: 'small-mobile', enter: 0, exit: 540 },{ label: 'mobile', enter: 540, exit: 980 },{ label: 'tablet', enter: 980, exit: 1024 },{ label: 'desktop', enter: 1024, exit: 10000 } ]); (function($){ /* ############################## ######## FUNCTIONS ######## ############################## */ /* MOBILE BREAKPOINT DETECTOR ============================ */ function isMobileWidth() { return $('#mobile-indicator').is(':visible'); } /* EQUAL HEIGHT ELEMENTS ======================= */ function equalHeights(parent, child, mobile) { parent = typeof parent !== 'undefined' ? parent : '.equal-cont'; child = typeof child !== 'undefined' ? child : '.equal-height'; mobile = typeof mobile !== 'undefined' ? mobile : false; if(mobile || jRes.getBreakpoint() != 'small-mobile') { $(parent+' '+child).css({"height":"auto"}); $(parent).each(function(index) { var totalChildren = $(this).find(child).length; var numCols = Math.floor( ($(this).width() / $(this).find(child).width()) + .1 ); // .1 is added to ensure ('1.999' + .1) is floored to '2' rather than '1' var rowCount = 0; var maxHeight = 0; var heights = []; $(this).find(child).each(function(innerIndex) { maxHeight = $(this).outerHeight() > maxHeight ? $(this).outerHeight() : maxHeight; if((innerIndex+1) % numCols == 0 || innerIndex == totalChildren - 1) { heights.push(maxHeight); maxHeight = 0; } }); for(var i = 0; i < totalChildren; i++) { $(this).find(child).eq(i).css({"height":heights[rowCount]+"px"}); if((i+1) % numCols == 0) rowCount++; } //console.log('Parent: '+$(this).attr('class')+' | children: '+totalChildren+' | rows: '+rowCount+' | cols: '+numCols+' | p width: '+$(this).width()+' | c width: '+$(this).find(child).width()); }); } else $(parent).find(child).css({"height":""}); } $(window).on('load', function(){ equalHeights(); }); $(window).on('resize', function(){ equalHeights(); }); /* ANIMATE AUTO ============== */ jQuery.fn.animateAuto = function(prop, speed, callback){ var elem, height, width; return this.each(function(i, el){ el = jQuery(el); if(prop == "width") { width = el.css({"width":"auto"}).css("width"); el.css({"width":"0px"}); el.animate({"width":width}, speed, callback); setTimeout(function(){ el.css({"width":"auto"}) }, speed+100) } else if(prop == "height") { height = el.css({"height":"auto"}).css("height"); el.css({"height":"0px"}); el.animate({"height":height}, speed, callback); setTimeout(function(){ el.css({"height":"auto"}) }, speed+100) } else if(prop == "both") { width = el.css({"width":"auto"}).css("width"); height = el.css({"height":"auto"}).css("height"); el.css({"width":"0px", "height":"0px"}); el.animate({"width":width,"height":height}, speed, callback); setTimeout(function(){ el.css({"height":"auto","width":"auto"}) }, speed+100) } }); } /* VERTIVAL CENTER ================= */ function vertivalCenter() { $('.vertical-center').each(function(i){ // desktop if($(this).hasClass('v-mobile') || !isMobileWidth()) { var center = $(this).parent('div').height()/2; var offset = $(this).height()/2; $(this).css('margin-top', (center-offset)+'px'); } // mobile else $(this).css('margin-top', ''); }); } $(window).on('load', function(){ vertivalCenter(); }); $(window).on('resize', function(){ vertivalCenter(); }); /* PUSHING COLUMNS ================= */ function pushColumns() { // USE FOR: desktop if(!isMobileWidth()) { $('.push-up-desktop').each(function(){ var pushHeight = $(this).outerHeight(); $(this).css('position', 'absolute'); $(this).siblings('.push-down-desktop').css('margin-top', pushHeight+'px'); }); } else { $('.push-up-desktop').each(function(){ $(this).css('position', ''); if(!$(this).hasClass('vertical-center') && !$(this).siblings('.push-down-mobile').hasClass('vertical-center')) $(this).siblings('.push-down-desktop').css('margin-top', ''); }); } // USE FOR: mobile if(isMobileWidth()) { $('.push-up-mobile').each(function(){ var pushHeight = $(this).outerHeight(); $(this).css('position', 'absolute'); $(this).siblings('.push-down-mobile').css('margin-top', pushHeight+'px'); }); } else { $('.push-up-mobile').each(function(){ $(this).css('position', ''); if(!$(this).hasClass('vertical-center') && !$(this).siblings('.push-down-mobile').hasClass('vertical-center')) $(this).siblings('.push-down-mobile').css('margin-top', ''); }); } } $(window).on('load', function(){ pushColumns(); setTimeout(function(){ pushColumns(); },1000); }); $(window).on('resize', function(){ pushColumns(); }); /* FULL HEIGHT SECTION ===================== */ function fullHeightSections() { var shim = ($('html').has('#wpadminbar').length) ? $('#wpadminbar').outerHeight() : 0; $('.full-height').each(function(){ $(this).outerHeight($(window).height()-shim); }); } $(window).on('load', function(){ fullHeightSections(); }); $(window).on('resize', function(){ fullHeightSections(); }); /* FULL CONTAINER LINKS ====================== */ function fullLinks() { $('.full-link').each(function(){ var url = $(this).find('a').eq(0).attr('href'); $(this).click(function(){ window.location.replace(url); }); }); } $(window).on('load', function(){ fullLinks(); }); /* WebP DETECTION ================ */ var webpSupport = false; function check_webp_feature(feature, callback) { var kTestImages = { lossy: "UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA", lossless: "UklGRhoAAABXRUJQVlA4TA0AAAAvAAAAEAcQERGIiP4HAA==", alpha: "UklGRkoAAABXRUJQVlA4WAoAAAAQAAAAAAAAAAAAQUxQSAwAAAARBxAR/Q9ERP8DAABWUDggGAAAABQBAJ0BKgEAAQAAAP4AAA3AAP7mtQAAAA==", animation: "UklGRlIAAABXRUJQVlA4WAoAAAASAAAAAAAAAAAAQU5JTQYAAAD/////AABBTk1GJgAAAAAAAAAAAAAAAAAAAGQAAABWUDhMDQAAAC8AAAAQBxAREYiI/gcA" }; var img = new Image(); img.onload = function () { var result = (img.width > 0) && (img.height > 0); callback(feature, result); }; img.onerror = function () { callback(feature, false); }; img.src = "data:image/webp;base64," + kTestImages[feature]; } function wepbSrcToJpg($elem) { var $img = ($elem[0].tagName == 'IMG') ? $elem : $elem.find('img'); var webpSrc = $img.attr('src'); var ext = webpSrc.split('.').pop(); var jpgScr = webpSrc.replace('.'+ext, '.jpg'); $img.attr('src', jpgScr); $img.parents('.bg-img').css('background-image', 'url('+jpgScr+')'); if($elem.hasClass('webp-bg')) $elem.css('background-image', 'url('+jpgScr+')'); return jpgScr; } function webpFallback(feature, support) { // set var status webpSupport = support; // auto fix image srcs if(!support) $('.webp-img').each(function(index){ wepbSrcToJpg($(this)); }); } $(window).on('load', function(){ check_webp_feature('animation', webpFallback); }); /* IMAGE AS BACKGROUND IMG ========================= */ function imgAsBgWork($elem) { var dataSrc = $elem.find('img').attr('data-src'); var src = (typeof dataSrc !== typeof undefined && dataSrc !== false) ? dataSrc : $elem.find('img').attr('src'); //if(($elem.hasClass('.webp-img') || $elem.find('.webp-img').length) && !webpSupport) src = wepbSrcToJpg($elem); $elem.find('img').css({'opacity':'0', 'visibility':'hidden', 'overflow':'hidden'}); $elem.find('img').parent().addClass('bg-img').css({'background-image':'url("'+src+'")'}); } function imgAsBgOuterWork($elem) { var dataSrc = $elem.find('img').attr('data-src'); var src = (typeof dataSrc !== typeof undefined && dataSrc !== false) ? dataSrc : $elem.find('img').attr('src'); //if(($elem.hasClass('.webp-img') || $elem.find('.webp-img').length) && !webpSupport) src = wepbSrcToJpg($elem); $elem.find('img').css({'opacity':'0', 'visibility':'hidden', 'overflow':'hidden'}); $elem.addClass('bg-img').css({'background-image':'url("'+src+'")'}); } function imgAsBg() { // USE FOR: closest parent $('.img-as-bg').each(function() { imgAsBgWork($(this)); }); // USE FOR: outer container $('.img-as-bg-outer').each(function() { imgAsBgOuterWork($(this)); }); } //$(window).on('load', function(){ imgAsBg(); }); $(document).ready(function(){ imgAsBg(); }); /* MOBILE FIRST IMAGES ===================== */ function mobileFirstImgs($img) { var smlScr = $img.attr('src'); var ext = smlScr.split('.').pop(); var lrgScr = smlScr.replace('.'+ext, '-lrg.'+ext); $.get(lrgScr).done(function() { if(!isMobileWidth()) { $img.attr('src', lrgScr); if($img.parents('.img-as-bg').length) imgAsBgWork($img.parents('.img-as-bg')); else if($img.parents('.img-as-bg-outer').length) imgAsBgOuterWork($img.parents('.img-as-bg-outer')); } }).fail(function() { ; }); } $(window).on('load', function(){ $('img.mob-first, .mob-first img').each(function(){ mobileFirstImgs($(this)); }); }); /* LIST COLUMNS ============== */ // setup columns function listColumns(initContClass, numColumns, sort) { if(typeof sort === "undefined" || sort === null) sort = false; var columns = null; var column = 1; var initialContainer = $(initContClass); var columnItems = $(initContClass+' li'); var avgNumColItems = 0; // sorting if(sort) { columnItems.sort(function(a, b) { return $(a).text().toUpperCase().localeCompare($(b).text().toUpperCase()); }) $.each(columnItems, function(idx, itm) { initialContainer.append(itm); }); } initialContainer = $(initContClass); columnItems = $(initContClass+' li'); avgNumColItems = Math.ceil( parseFloat(columnItems.length) / parseFloat(numColumns) ); columnItems.detach(); for(var i = 1; i < numColumns; i++) initialContainer.clone().insertBefore(initialContainer); columns = $(initContClass); columnItems.each(function(i, el) { if(i >= avgNumColItems * column) { column += 1; } $(columns.get(column-1)).append(el); }); } /* ORIGINAL IMAGE WIDTH ====================== */ function realImgWidth(img_element) { var t = new Image(); t.src = (img_element.getAttribute ? img_element.getAttribute("src") : false) || img_element.src; return t.width; } /* ORIGINAL IMAGE HEIGHT ======================= */ function realImgHeight(img_element) { var t = new Image(); t.src = (img_element.getAttribute ? img_element.getAttribute("src") : false) || img_element.src; return t.height; } /* GET URL PARAMATER =================== */ var getUrlParameter = function getUrlParameter(sParam) { var sPageURL = decodeURIComponent(window.location.search.substring(1)), sURLVariables = sPageURL.split('&'), sParameterName, i; for (i = 0; i < sURLVariables.length; i++) { sParameterName = sURLVariables[i].split('='); if (sParameterName[0] === sParam) { return sParameterName[1] === undefined ? true : sParameterName[1]; } } }; /* COPY ELEMENT EVENTS ===================== */ function copyEvents(source, destination) { // Get source events var events = source.data('events'); // Iterate through all event types $.each(events, function(eventType, eventArray) { // Iterate through every bound handler $.each(eventArray, function(index, event) { // Take event namespaces into account var eventToBind = event.namespace.length > 0 ? (event.type + '.' + event.namespace) : (event.type); // Bind event destination.bind(eventToBind, event.data, event.handler); }); }); } /* LOAD SCRIPT ============= */ function loadScript( url, callback ) { var script = document.createElement( "script" ) script.type = "text/javascript"; if(script.readyState) { //IE script.onreadystatechange = function() { if ( script.readyState === "loaded" || script.readyState === "complete" ) { script.onreadystatechange = null; callback(); } }; } else { //Others script.onload = function() { callback(); }; } script.src = url; document.getElementsByTagName( "head" )[0].appendChild( script ); } /* TC LOGO SLIDER EQUAL HEIGHTS ============================== */ function logoSliderEqualHeight(img) { var baseHeight = 140; var inverseRatio = realImgHeight($(img)[0]) / realImgWidth($(img)[0]); var ratioWeight = Math.abs(1-inverseRatio); var weightDilution = .3; $(img).css('height', baseHeight*(inverseRatio+(ratioWeight*weightDilution))+'px'); } /* CENTERED POPUP WINDOW */ /* ===================== */ function popupCenter(url, title, w, h) { // Fixes dual-screen position Most browsers Firefox var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : window.screenX; var dualScreenTop = window.screenTop != undefined ? window.screenTop : window.screenY; var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width; var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height; var systemZoom = width / window.screen.availWidth; var left = (width - w) / 2 / systemZoom + dualScreenLeft var top = (height - h) / 2 / systemZoom + dualScreenTop var newWindow = window.open(url, title, 'scrollbars=yes, width=' + w / systemZoom + ', height=' + h / systemZoom + ', top=' + top + ', left=' + left); // Puts focus on the newWindow if (window.focus) newWindow.focus(); } /* TRUNCATE STRING */ /* =============== */ function truncateString(str, len) { if (str.length > len) return str.substring(0, len) + '...'; else return str; } /* SHUFFLE ARRAY */ /* ============= */ function shuffleArray(a) { for (let i = a.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [a[i], a[j]] = [a[j], a[i]]; } return a; } /* GET TEXT NODES */ /* ============== */ function getTextNodes(el) { return $(el).find(":not(iframe)").addBack().contents().filter(function() { return this.nodeType == 3; }); }; /* COOKIE FUNCTIONS */ /* ================ */ // Create Cookie function createCookie(name, value, days) { var expires = ""; if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toUTCString(); } document.cookie = name + "=" + value + expires + "; path=/"; } // Read Cookie function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') c = c.substring(1, c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); } return null; } /* FLIP LAYOUT */ /* ============= */ function flipLayout() { // vars var parent = '.flip-cont'; var leftChild = '.flip-left'; var rightChild = '.flip-right'; var breakPoint = jRes.getBreakpoint(); // flip layouts $(parent).each(function(i){ // mobile if(!$(this).hasClass('flipped') && (breakPoint == 'small-mobile' || breakPoint == 'mobile')) { $(this).addClass('flipped'); $(this).append($(this).find(leftChild).remove()); } // desktop else if($(this).hasClass('flipped') && (breakPoint != 'small-mobile' && breakPoint != 'mobile')) { $(this).removeClass('flipped'); $(this).append($(this).find(rightChild).remove()); } }); } $(document).ready(function(){ flipLayout(); }); $(window).resize( function(){ flipLayout(); }); /* ####################################### ######## PAGE FUNCTIONALITY ######## ####################################### */ /* 'Scroll To' on load ===================== */ $(window).on('load', function(){ var hash = window.location.hash.substring(1).toLowerCase(); var slideTo = false; var heightOffset = $('#main-header').outerHeight() + $('#wpadminbar').outerHeight(); // check if hash relates to a section $('.et_pb_section, .et_pb_row').each(function(){ if(!!$(this).attr('id') && hash == $(this).attr('id').toLowerCase()) { slideTo = true; return false; // break; } }); // slide if(slideTo) $('html, body').animate({ scrollTop: ($(window.location.hash).offset().top - heightOffset) }, 1500); }); /* Main Navigation ================= */ $(document).ready(function(){ // vars var mobileSubMenuOpening = false; var mobileSubMenuAniTime = 350; // persistant hover $('.menu-item').hover(function(){ $('.menu-item').each(function(){ $(this).removeClass('hover'); }); }, function(){ var $elem = $(this); $elem.addClass('hover'); setTimeout(function(){ $elem.removeClass('hover'); }, 300); }); // mobile menu // menu button $('.mobile_menu_bar_toggle').html('
'); // menu config $(window).load(function() { // inner wrapper $('#mobile_menu').wrapInner('
'); $('#mobile_menu li a').addClass('menu-link'); // wrap social icons $('#mobile_menu #menu-item-185, #mobile_menu #menu-item-186').wrapAll('
'); // reposition account buttons $(window).resize(function(){ if(!$('#mobile_menu .header-account-cont').length && (jRes.getBreakpoint() == 'mobile' || jRes.getBreakpoint() == 'small-mobile')) { $('#mobile_menu .inner').append($('.header-account-cont').remove()); $('#mobile_menu .header-account-cont').addClass('show'); } else if($('#mobile_menu .header-account-cont').length && (jRes.getBreakpoint() != 'mobile' && jRes.getBreakpoint() != 'small-mobile')) { $('#main-header').prepend($('.header-account-cont').remove()); $('#main-header .header-account-cont').removeClass('show'); } }); // search functionality $("#et_search_icon").click(function(){ if(isMobileWidth()) $('#main-header #logo').animate({opacity: 0}, 800); }); $(".et_close_search_field, #et-main-area").click(function(){ if(isMobileWidth()) $('#main-header #logo').animate({opacity: 1}, 1500); }); // search menu item $('#menu-item-295 a').click(function(e){ $('#et_search_icon').trigger('click'); }); // sub menu functionality $('#mobile_menu .menu-item-has-children').each(function(i){ $(this).find('a').eq(0).unbind('click'); $(this).find('a').eq(0).click(function(e){ if(!$(this).hasClass('open')) { e.preventDefault(); $('#mobile_menu .menu-item-has-children').each(function(i){ $(this).removeClass('open'); $(this).find('a').removeClass('open').siblings('.sub-menu').css('height', '0px'); }); $(this).addClass('open'); $(this).parent().addClass('open'); $(this).siblings('.sub-menu').animateAuto('height', mobileSubMenuAniTime); mobileSubMenuOpening = true; setTimeout(function(){ mobileSubMenuOpening = false; }, mobileSubMenuAniTime+50); } }); }); // sub menu click away close $('#mobile_menu').click(function(e){ if(!mobileSubMenuOpening) { $('#mobile_menu .menu-item-has-children').each(function(i){ $(this).removeClass('open'); $(this).find('a').removeClass('open').siblings('.sub-menu').css('height', '0px'); }); } }); // close button $('#mobile_menu').prepend('
M
'); $('#mobile_menu .close').click(function(){ $('.mobile_menu_bar_toggle').trigger('click'); $('#mobile_menu .menu-item-has-children').each(function(i){ $(this).removeClass('open'); $(this).find('a').removeClass('open').siblings('.sub-menu').css('height', '0px'); }); }); }); }); /* Main Footer ============= */ $(document).ready(function(){ // clickable logo $('body #main-footer .footer-logo').click(function(){ window.location.href = BASE_URL; }); }); /* Obfs Email Links ================== */ $(document).ready(function(){ // obfs var ea = 'caprilac'; var eb = 'info@'; var ec = '.com'; // click $('body #page-container .e-link, body #page-container a[href="#e-link"]').click(function(e){ e.preventDefault(); window.location.href = 'mailto:'+eb+ea+ec; }); }); /* Newsletter Popup ================== */ $(document).ready(function(){ // vars var popupCookie = '_cap_nsPopup'; var popupCookieValue = 'popupShown'; var showNsPopup = false; // check cookie status if(readCookie(popupCookie) != popupCookieValue) { // set cookie createCookie(popupCookie, popupCookieValue, 30); // popup status showNsPopup = true; } // show popup if(showNsPopup && jRes.getBreakpoint() != "small-mobile" && jRes.getBreakpoint() != "mobile") { // vars var popupDelay = 15000; var animationTime = 800; // form $('.nsPopupCont .popup-text .text-inner').append($('.footer-newsletter form').clone(true)); // show popup setTimeout(function(){ $('.nsPopupCont').fadeIn(animationTime); $(window).trigger('resize'); }, popupDelay); setTimeout(function(){ $('.nsPopupCont').addClass('show'); }, popupDelay+100); // submit button $('.nsPopupCont .popup-text input[type=submit]').addClass('btn'); // close $('.nsPopupCont').click(function(e){ if($(e.target).hasClass('nsPopupCont') || $(e.target).hasClass('nsClose')) $('.nsPopupCont').removeClass('show').fadeOut(animationTime); }); } }); /* Newsletter Thankyou Popup =========================== */ $(document).ready(function(){ if(window.location.hash == '#signup-success') { // vars var popupDelay = 50; var animationTime = 800; // show popup setTimeout(function(){ $('.nsTyPopupCont').fadeIn(animationTime); $(window).trigger('resize'); }, popupDelay); setTimeout(function(){ $('.nsTyPopupCont').addClass('show'); }, popupDelay+100); // close $('.nsTyPopupCont').click(function(e){ if($(e.target).hasClass('nsTyPopupCont') || $(e.target).hasClass('nsClose')) $('.nsTyPopupCont').removeClass('show').fadeOut(animationTime); }); } }); /* Home Page =========== */ $(document).ready(function(){ if($('body').hasClass('home')) { // header banner slider $('#header-banner .et_pb_slide_description').each(function(){ $(this).wrapInner('
'); }); } }); /* 'Content Pages' Section ========================= */ /* CP flip layout */ var cpFRBound = false; function cpFlipLayout() { var smallTrigger = 720 - 17; var mediumTrigger = 1550 - 17; var documentWidth = $(document).width(); var $lastColumn = $('#content-pages .et_pb_column').eq(3); function flipColumns() { $('#content-pages .et_pb_row').append($('#content-pages .et_pb_column').eq(2).remove()); } // small if(documentWidth <= smallTrigger && !$lastColumn.hasClass('text-col')) flipColumns(); // medium if((documentWidth > smallTrigger && documentWidth <= mediumTrigger) && !$lastColumn.hasClass('img-as-bg-outer')) flipColumns(); // large if(documentWidth > mediumTrigger && !$lastColumn.hasClass('text-col')) flipColumns(); // bind resize if(!cpFRBound) { cpFRBound = true; $(window).resize(function(){ cpFlipLayout(); }); } } /* document ready */ $(document).ready(function(){ if($('body #content-pages').length) { // 'content pages' flip layout cpFlipLayout(); } }); /* Recipe Cells ============== */ $(document).ready(function(){ if($('body .recipe-cont').length && !$('body').hasClass('page-id-33')) { // init recipes $('article.type-recipes').each(function(i){ // id $(this).attr('data-id', i); // bg images var src = $(this).find('img').attr('src'); $('html head').append(''); // clickable cells var href = $(this).find('.entry-title a').attr('href'); $(this).attr('onClick', 'window.location.href = "'+href+'";'); }); } }); /* Recipe Gallery ================ */ // init filter nav // --------------- var recipes = []; function initFilterNav() { // vars var aniSpeed = 500; // init recipes $('article.type-recipes').each(function(i){ // id $(this).attr('data-id', i); // bg images var src = $(this).find('img').attr('src'); $('html head').append(''); // clickable cells var href = $(this).find('.entry-title a').attr('href'); $(this).attr('onClick', 'window.location.href = "'+href+'";'); // collect recipes.push($(this).remove()); }); $('.recipe-container .et_pb_ajax_pagination_container div').remove(); // position $('.recipe-container').before($('.recipe-filters').remove()); $('.recipe-filters').show(); // header clicks $('.filter-header').click(function(){ // open if(!$('.recipe-filters .filters').hasClass('open')) { $('.recipe-filters .filters, .filter-header').addClass('open'); $('.recipe-filters .filters').animateAuto('height', aniSpeed); } // close else { $('.recipe-filters .filters, .filter-header').removeClass('open'); $('.recipe-filters .filters').animate({'height':'0px'}, aniSpeed); } }); // filter clicks $('.recipe-filters a').click(function(e) { // setup e.preventDefault(); var slug = $(this).attr('data-slug'); $('.recipe-filters a').removeClass('active'); $(this).addClass('active'); // total number of recipes in selected filter var numRecInFilter = 0; var numRecInFilterLoaded = 0; recipes.forEach(function($recipe, i) { if(slug == 'all' || $recipe.hasClass('recipe-type-'+slug)) numRecInFilter++; }); // filter recipes $('article.type-recipes').remove(); recipes.forEach(function($recipe) { if(numRecInFilterLoaded < numRecLoaded) { if(slug == 'all' || $recipe.hasClass('recipe-type-'+slug)) { $('.recipe-container .et_pb_ajax_pagination_container').append($recipe); numRecInFilterLoaded++; } } }); // main menu underline $('#menu-item-58 .sub-menu li a').css('text-decoration', 'none'); $('#menu-item-58 .sub-menu li a[href="'+BASE_URL+'/recipes/#'+slug+'"]').css('text-decoration', 'underline'); // update header $('.current-filter strong').text($(this).text()); // update 'show more' button if(numRecInFilterLoaded >= numRecInFilter) updateRecShowMore(true); else updateRecShowMore(); }); } // update recipe show more button // ------------------------------ function updateRecShowMore(forceHide) { forceHide = typeof forceHide !== 'undefined' ? forceHide : false; // show if(!forceHide && numRecLoaded < recipes.length) { //add if(!$('.recipe-container .show-more').length) { $('.recipe-container').append(''); } // show else { $('.recipe-container .show-more').show(); } } // hide else { $('.recipe-container .show-more').hide(); } } // init recipe loader // ------------------ var loadedRecipes = []; var numRecPerPage; var numRecLoaded; function initRecipeLoader() { // setup numRecPerPage = 12; numRecLoaded = 0; updateRecShowMore(); // load recipes function loadRecipes() { if(numRecLoaded < recipes.length) { // status numRecLoaded = (recipes.length - numRecLoaded >= numRecPerPage) ? numRecLoaded + numRecPerPage : numRecLoaded + (recipes.length - numRecLoaded); loadedRecipes = []; recipes.forEach(function($recipe, i) { if(i < numRecLoaded) loadedRecipes.push($recipe); }); // show more $('article.type-recipes').remove(); loadedRecipes.forEach(function($recipe, i) { $('.recipe-container .et_pb_ajax_pagination_container').append($recipe); }); // update button updateRecShowMore(); $('.recipe-filters a.active')[0].click(); } } $('.recipe-container .show-more').click(function(){ loadRecipes(); }); loadRecipes(); } // auto filter select // ------------------ function autoFilterSelect(pageLoad) { var filterNames = []; var windowHash = window.location.hash.replace('#',''); var delay = (pageLoad) ? 400 : 0; // get filter names $('#menu-item-58 ul li a').each(function(){ var filterName = $(this).text().toLowerCase().replace(' ', '-'); filterNames.push(filterName); }); // auto select if(filterNames.includes(windowHash)) { // auto filter /*if(pageLoad) setTimeout(function(){ $('.filter-header').trigger('click'); }, delay); setTimeout(function(){ $('a[data-slug="'+windowHash+'"]').trigger('click'); }, delay*2);*/ setTimeout(function(){ $('a[data-slug="'+windowHash+'"]').trigger('click'); }, delay); // main menu underline $('#menu-item-58 .sub-menu li a').css('text-decoration', 'none'); $('#menu-item-58 .sub-menu li a[href="'+BASE_URL+'/recipes/#'+windowHash+'"]').css('text-decoration', 'underline'); } } // document ready // -------------- $(document).ready(function(){ if($('body').hasClass('page-id-33')) { // filter nav (must run first) initFilterNav(); // load recipes initRecipeLoader(); // auto filter select autoFilterSelect(true); $('#menu-item-58 .sub-menu li a').click(function(){ setTimeout(function(){ autoFilterSelect(false); }, 50); }); } }); /* Recipe Page ============= */ $(document).ready(function(){ if($('body').hasClass('single-recipes')) { // recipe sharing // position sharing container $('.recipe-row .et_pb_column:nth-child(1)').prepend($('.sharing-cont').remove()); $('.recipe-row .et_pb_column:nth-child(1) .sharing-cont').show(); // sharing popups $('.sharing-cont .s-icon.popup').click(function(e){ e.preventDefault(); var shareURL = $(this).attr('href'); var title = $(this).text(); popupCenter(shareURL, title, '660', '460'); }); // pinterest $('head').append(''); $('.sharing-cont .s-icon.p-share').click(function(e){ e.preventDefault(); }); // title $('.recipe-row .et_pb_column:nth-child(2)').prepend('

'+$('#header-banner h1').text()+'

'); // insta hashtab $('.instagram-hashtag strong').text('#caprilacgoatmilk'); // post nav // icons $('.nav-single .nav-previous .meta-nav').text('4'); $('.nav-single .nav-next .meta-nav').text('5'); // 'back to recipes' button $('.nav-single .nav-previous').after('Back to Recipes'); // format prep / cooking time // prep time var prepHours = $('li.prep-time-hours').text().replace('Hours: ',''); var prepHoursTxt = prepHours + ' Hour' + ((prepHours != 1) ? 's' : '') + ' & '; var prepMins = $('li.prep-time-mins').text().replace('Minutes: ',''); var prepTime = ((prepHours != '0') ? prepHoursTxt : '') + prepMins + ' Mins'; // cooking time var cookHours = $('li.cooking-time-hours').text().replace('Hours: ',''); var cookHoursTxt = cookHours + ' Hour' + ((cookHours != 1) ? 's' : '') + ' & '; var cookMins = $('li.cooking-time-mins').text().replace('Minutes: ',''); var cookTime = ((cookHours != '0') ? cookHoursTxt : '') + cookMins + ' Mins'; // format $('.prep-time-units, .cooking-time-units').remove(); $('li.prep-time').html($('li.prep-time').html() + prepTime); $('li.cooking-time').html($('li.cooking-time').html() + cookTime); // remove if zero if(prepHours == '0' && prepMins == '0') $('li.prep-time').remove(); if(cookHours == '0' && cookMins == '0') $('li.cooking-time').remove(); // sudo randomise other recipes var numOtherRecipes = $('#recipes .et_pb_ajax_pagination_container article').length; var recipes = []; if(numOtherRecipes > 3) { $('#recipes article').each(function(){ recipes.push($(this).remove()); }); shuffleArray(recipes); for(var i = 0; i < 3; i++) $('#recipes .et_pb_ajax_pagination_container').append(recipes[i]); } } }); /* 'Featured Content Page' Section ================================= */ $(document).ready(function(){ if($('body #content-pages').length) { // .inner wrap $('#content-pages .et_pb_column').each(function(i){ $(this).find('.et_pb_text, .et_pb_button_module_wrapper').wrapAll('
'); }); } }); /* NEW Fresh Goat Milk Carton Page ================================= */ $(document).ready(function(){ if($('body').hasClass('page-id-1482')) { // accordion // all closed $('.et_pb_accordion .et_pb_toggle_open').addClass('et_pb_toggle_close').removeClass('et_pb_toggle_open'); $('.et_pb_accordion .et_pb_toggle').click(function() { $this = $(this); setTimeout(function(){ $this.closest('.et_pb_accordion').removeClass('et_pb_accordion_toggling'); },700); }); // question content $('.et_pb_toggle_content p').addClass('small-para'); } }); /* Products General ================== */ /* 'Where To Buy' Hover */ function wtbHover() { if($('body').hasClass('page-id-37')) { // remove hover for smaller devices on 'Where To Buy' page if((jRes.getBreakpoint() == 'small-mobile' || jRes.getBreakpoint() == 'mobile') && $('body').hasClass('prod-hover')) $('body').removeClass('prod-hover'); else if((jRes.getBreakpoint() != 'small-mobile' && jRes.getBreakpoint() != 'mobile') && !$('body').hasClass('prod-hover')) $('body').addClass('prod-hover'); } } /* document ready */ $(document).ready(function(){ if($('body .products').length) { // hover $('body').addClass('prod-hover'); // remove hover for smaller devices on 'Where To Buy' page wtbHover(); $(window).resize(function(){ wtbHover(); }); } }); /* Product Page ============== */ $(document).ready(function(){ if($('body').hasClass('single-product')) { // woocommerce messages // position and show message $('.main-product').prepend($('.woocommerce-notices-wrapper').remove()); setTimeout(function(){ $('.main-product .woocommerce-notices-wrapper').addClass('show'); }, 100); if($('.woocommerce-message').length) $('html, body').animate({ scrollTop: ($('.main-product').offset().top - 200) }, 1500); // text if($('.woocommerce-message').length) { var wmText = getTextNodes($('.woocommerce-message'))[1].data; var $wmBtn = $('.woocommerce-message').find('a').remove(); $('.woocommerce-message').html('

'+wmText+'

'+$('
').append($wmBtn).html()); } // content heading $('h1.product_title').addClass('h2-size'); // lightbox $('.woocommerce-product-gallery__image').click(function(){ $('.woocommerce-product-gallery__trigger').trigger('click'); }); // position price // standard $('.summary .woocommerce-product-details__short-description').after($('.summary .price').addClass('large-para').remove()); // coming soon $('.postid-633 .summary .coming-soon-button').before($('.postid-633 .summary .price').addClass('large-para').remove()); // in-store only $('.postid-631 .summary .in-store-outer').before($('.postid-631 .summary .price').addClass('large-para').remove()); // accordion // all closed $('.et_pb_accordion .et_pb_toggle_open').addClass('et_pb_toggle_close').removeClass('et_pb_toggle_open'); $('.et_pb_accordion .et_pb_toggle').click(function() { $this = $(this); setTimeout(function(){ $this.closest('.et_pb_accordion').removeClass('et_pb_accordion_toggling'); },700); }); // question titles $('.et_pb_accordion').eq(0).find('.et_pb_toggle_title').addClass('h3-size'); // free shipping strip // reposition $('.woocommerce-tabs').before($('.free-shipping-strip').remove()); // recipe sharing // position sharing container $('.woocommerce-tabs').append($('.sharing-cont').remove()); $('.woocommerce-tabs .sharing-cont').show(); // sharing popups $('.sharing-cont .s-icon.popup').click(function(e){ e.preventDefault(); var shareURL = $(this).attr('href'); var title = $(this).text(); popupCenter(shareURL, title, '660', '460'); }); // pinterest $('head').append(''); $('.sharing-cont .s-icon.p-share').click(function(e){ e.preventDefault(); }); // faqs accordion if($('body .faq-row').length) { // status $('.woocommerce-tabs').addClass('has-faqs'); // move sharing section $('.faq-row').before($('.sharing-cont').remove()); } } }); /* Supply Chain ============== */ $(document).ready(function(){ if($('body').hasClass('page-id-30')) { // the process /*$('.the-process').wrap('
');*/ } }); /* Buy Now Page ============== */ $(document).ready(function(){ if($('body').hasClass('page-id-37')) { // product buttons $('.products .product').each(function(i){ // coming soon //if($(this).hasClass('post-633')) $(this).append(''); // in-store only if($(this).hasClass('post-631')) $(this).append(''); // standard else $(this).append('Buy Now'); }); } }); /* Contact Page ============== */ var contactInterval; $(document).ready(function(){ if($('body').hasClass('page-id-50')) { // thank you message contactInterval = setInterval(function(){ if(!$('.contact-form-col form').length) { clearInterval(contactInterval); $('.et-pb-contact-message').after('

Message Sent

'); $('.contact-msg').append('

'+$('.et-pb-contact-message p').text()+'

'); setTimeout(function(){ $('.contact-msg').addClass('show'); }, 100); } }, 100); } }); /* Login Page ============ */ $(document).ready(function(){ if($('body.woocommerce-account #customer_login').length) { // equal height forms equalHeights('#customer_login', 'form'); $(window).resize(function(){ equalHeights('#customer_login', 'form'); }); } }); /* Account Orders ================ */ $(document).ready(function(){ if($('body').hasClass('woocommerce-view-order')) { // add tracking info $trackingInfo = $('.tracking-info').remove(); $('.woocommerce-table--order-details tfoot tr:nth-child(2) td').append($trackingInfo.eq(0)); $trackingInfo.eq(0).css('display', 'block'); } }); /* Checkout Page =============== */ $(document).ready(function(){ if($('body').hasClass('woocommerce-checkout')) { // title paragraph if(!$('body').hasClass('woocommerce-order-received') && !$('body').hasClass('woocommerce-order-pay')) { var content = '

Thank you for proceeding to checkout. Please complete the form below before proceeding to payment.

' $('h1.entry-title').after(content); setTimeout(function(){ $('.large-para').addClass('show'); }, 100); } // reposition notes $('.woocommerce-billing-fields__field-wrapper').append($('.woocommerce-additional-fields').remove()); // notes label / placeholder $('label[for="order_comments"]').text('Additional delivery instructions (optional)'); $('#order_comments').attr('placeholder', 'Please enter any special delivery instructions if any, example "gate code 1478# to open".'); // address label note $(window).load(function(){ $('label[for="billing_address_1"]').text('Street address (Note: we cannot ship to PO BOX addresses) *'); }); // checkout button text setInterval(function(){ $('#place_order').text('Proceed to payment'); }, 500); } }); /* 'Pay For Your Order' Page =========================== */ $(document).ready(function(){ if($('body').hasClass('woocommerce-order-pay')) { // main heading $('h1.entry-title').text('Pay for your order'); // title paragraph var content = '

You are almost there! Please complete the details below to confirm your secure payment.

' $('h1.entry-title').after(content); setTimeout(function(){ $('.large-para').addClass('show'); }, 100); } }); /* Order Received Page ===================== */ $(document).ready(function(){ if($('body').hasClass('woocommerce-order-received')) { // title paragraph var content = '

Thank you for your purchase. While you’re waiting on your order to arrive, take a look at our recipes on how CapriLac® can easily be added to your cooking.

' $('h1.entry-title').after(content); setTimeout(function(){ $('.large-para').addClass('show'); }, 100); } }); /* Search Results Page ===================== */ // search results images var defaultImgIndex = 0; function searchImages() { $('article').each(function(){ if($(this).hasClass('updated')) return true; // update img if($(this).find('.entry-featured-image-url').length) { var bgImgSrc = $(this).find('.entry-featured-image-url img').attr('src'); var isCropped = (bgImgSrc.length - bgImgSrc.lastIndexOf("x")) == 8; var ext = bgImgSrc.substring(bgImgSrc.length-4, bgImgSrc.length); bgImgSrc = (isCropped) ? bgImgSrc.substring(0, bgImgSrc.lastIndexOf("-")) + ext : $(this).find('.entry-featured-image-url img').attr('src'); $(this).find('.entry-featured-image-url').css('background-image', 'url('+bgImgSrc+')'); } // add default img else { defaultImg1 = BASE_URL+'/wp-content/uploads/2020/03/default-img1.jpg'; defaultImg2 = BASE_URL+'/wp-content/uploads/2020/03/default-img2.jpg'; defaultImg3 = BASE_URL+'/wp-content/uploads/2020/03/default-img3.jpg'; defaultImgs = [defaultImg1, defaultImg2, defaultImg3]; linkUrl = $(this).find('a').attr('href'); title = $(this).find('h2.entry-title').text(); $(this).prepend(''); $(this).find('.entry-featured-image-url').append('

'+title+'

'); defaultImgIndex = (defaultImgIndex + 1 < defaultImgs.length) ? defaultImgIndex+1 : 0; } $(this).addClass('updated'); }); } // pagination text function searchPaginationText() { $('.pagination .alignleft a').text('More Results >'); $('.pagination .alignright a').text('< Previous Page'); } // document ready $(document).ready(function(){ if($('body').hasClass('search-results')) { // main heading $('#left-area').prepend('

Search Results

'); // descriptions $('article').each(function(i){ var desc = ''; $(this).find('p').each(function(i){ if(!$(this).hasClass('post-meta')) { desc += ' ' + $(this).text(); $(this).remove(); } }); $(this).append('

'+truncateString(desc, 200)+'

'); }); // images searchImages(); searchPaginationText(); setTimeout(function(){ searchImages(); searchPaginationText(); }, 500); } }); })(jQuery);