/** Mogul Framework Javascript **/ // ---------------------------- Enable Console.log always // usage: log('inside coolFunc', this, arguments); // paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/ window.log = function f(){ log.history = log.history || []; log.history.push(arguments); if(this.console) { var args = arguments, newarr; args.callee = args.callee.caller; newarr = [].slice.call(args); if (typeof console.log === 'object') log.apply.call(console.log, console, newarr); else console.log.apply(console, newarr);}}; (function(a){function b(){}for(var c="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),d;!!(d=c.pop());){a[d]=a[d]||b;}}) (function(){try{console.log();return window.console;}catch(a){return (window.console={});}}()); //Detect iOS and add iPhone/iPad classes to html var ua = window.navigator.userAgent; var iOS = ua.match(/iPad/i) || ua.match(/iPhone/i); var html = document.documentElement; html.classList.add(iOS); jQuery(document).ready(function($) { $('.woocommerce-variation-add-to-cart .input-text.qty.text').on('keyup mouseup', function () { if($(this).val() == 1){ $('#alg-product-input-fields-table tr:nth-child(4),#alg-product-input-fields-table tr:nth-child(5), #alg-product-input-fields-table tr:nth-child(6), #alg-product-input-fields-table tr:nth-child(7), #alg-product-input-fields-table tr:nth-child(8), #alg-product-input-fields-table tr:nth-child(9)').hide(); $('#alg-product-input-fields-table tr:nth-child(4) input').prop('required',false); $('#alg-product-input-fields-table tr:nth-child(5) input').prop('required',false); $('#alg-product-input-fields-table tr:nth-child(7) input').prop('required',false); $('#alg-product-input-fields-table tr:nth-child(8) input').prop('required',false); } else if($(this).val() == 2){ $('#alg-product-input-fields-table tr:nth-child(4),#alg-product-input-fields-table tr:nth-child(5), #alg-product-input-fields-table tr:nth-child(6)').show(); $('#alg-product-input-fields-table tr:nth-child(4) input').prop('required',true); $('#alg-product-input-fields-table tr:nth-child(5) input').prop('required',true); $('#alg-product-input-fields-table tr:nth-child(7), #alg-product-input-fields-table tr:nth-child(8), #alg-product-input-fields-table tr:nth-child(9)').hide(); $('#alg-product-input-fields-table tr:nth-child(7) input').prop('required',false); $('#alg-product-input-fields-table tr:nth-child(8) input').prop('required',false); } else if($(this).val() == 3){ $('#alg-product-input-fields-table tr:nth-child(4),#alg-product-input-fields-table tr:nth-child(5), #alg-product-input-fields-table tr:nth-child(6), #alg-product-input-fields-table tr:nth-child(7), #alg-product-input-fields-table tr:nth-child(8), #alg-product-input-fields-table tr:nth-child(9)').show(); $('#alg-product-input-fields-table tr:nth-child(4) input').prop('required',true); $('#alg-product-input-fields-table tr:nth-child(5) input').prop('required',true); $('#alg-product-input-fields-table tr:nth-child(7) input').prop('required',true); $('#alg-product-input-fields-table tr:nth-child(8) input').prop('required',true); } }); $.get('/wp-admin/admin-ajax.php?action=mogul_get_cart_count', function(data){ $('.cart-amount').text(data); }); new WOW().init(); $.stellar({ positionProperty: 'transform', hideDistantElements: false, }); // Header class change on scroll if (window.matchMedia("(min-width: 1200px)").matches) { var $document = $(document), $element = $('#header'); $document.scroll(function() { if ($document.scrollTop() >= 10){ $element.addClass('scrolled'); $('body').addClass('scrolled'); $element.removeClass('unscrolled'); $('body').removeClass('unscrolled'); } else { $element.removeClass('scrolled'); $('body').removeClass('scrolled'); $element.addClass('unscrolled'); $('body').addClass('unscrolled'); } }); } /* //Temp link breaker $(function(){ $('#header nav a, .tile a, .footer a').each(function() { $(this).attr('href', '#'); }); }); */ //scroll to // HTML e.g Go to footer $('a[href*="#"]:not([href="#"])').click(function() { if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { var target = $(this.hash); target = target.length ? target : $('[name=' + this.hash.slice(1) +']'); if (target.length) { //lets us set the vertical offest in px e.g data-offset="100" var attr = $(this).attr('data-offset'); if( attr == undefined ){ attr = 0; } //console.log(attr); $('html,body').animate({ scrollTop: target.offset().top-attr }, 600); return false; } } }); // Responsive table $('.single-column table').wrap('
'); //lets you overide the scrolljacking/stops janky stuff happening $('html,body').on("scroll mousedown wheel DOMMouseScroll mousewheel keyup touchmove", function() { $('html,body').stop(); }); var googleMaps = 'iframe[src*="google.com"][src*="map"][src*="embed"]'; $(googleMaps).wrap('').after(''); $('.google-map-wrapper').on('mousedown', function(){ $(this).removeClass('disable-pointer-events'); }); $('.google-map-wrapper').on('mouseleave', function(){ $(this).addClass('disable-pointer-events'); }); // Touch enabled dropdown nav - doubletaptogo if ($(window).width() >=800 ){ $( 'nav li:has(ul)' ).doubleTapToGo(); } //lazy load all images $(function() { $('.lazy').lazy(); }); //Magnific $('.popup-video').magnificPopup({ disableOn: 700, type: 'iframe', mainClass: 'mfp-fade', removalDelay: 160, preloader: false, fixedContentPos: false, iframe: { patterns: { wistia: { index: 'wistia.com', id: function(url) { var m = url.split('/'); if (m !== null) { return m[4]; } return null; }, src: '//fast.wistia.net/embed/iframe/%id%' }, youtube: { index: 'youtube.com', id: 'v=', src: '//www.youtube.com/embed/%id%?rel=0&autoplay=1' } } } }); //Content Tabs $('ul.tabs li').click(function(){ var tab_id = $(this).attr('data-tab'); $('ul.tabs li').removeClass('current'); $('.tab-content').removeClass('current'); $(this).addClass('current'); $("#"+tab_id).addClass('current'); window.location.hash = tab_id.substring(4); }); // Toggle mobile nav $('i[class="mdi mdi-menu"]').on('click touchstart', function(event){ event.preventDefault(); $('body').toggleClass('nav-open'); }); // Toggle mobile nav (close button) $('.mobile-nav i[class="mdi mdi-close"]').on('click touchstart', function(event){ event.preventDefault(); $('body').toggleClass('nav-open'); }); //Youtube iframe in content $('iframe[src*="youtube.com"]').each(function() { $(this).wrap(''); }); // Accordions $('.accordion').find('.accordion-head').click(function(){ if( $(this).hasClass('open') ){ $(this).removeClass('open'); $(this).next().slideToggle('fast'); } else { $('.accordion-head').removeClass('open'); $(this).addClass('open'); $(this).next().slideToggle('fast'); $('.accordion-body').not($(this).next()).slideUp('fast'); } }); // Slick slider (home-slider) $('.home-slider').slick({ speed: 800, autoplay: true, autoplaySpeed: 4000, arrows: true, dots: false, fade: true, prevArrow: $('.prev'), nextArrow: $('.next'), }); // Slick slider (gallery-slider) $('.gallery-slider').slick({ dots: true, infinite: true, speed: 300, slidesToShow: 1, centerMode: true, variableWidth: true, arrows: true, }); // Slick slider (testimonials) $('.slider').slick({ dots: true, arrows: false }); //Tile slider $('.tile-slider').slick({ speed: 300, variableWidth: false, draggable:true, slidesToShow:5, slidesToScroll:5, dots:true, infinite:false, swipeToSlide: true, prevArrow: $('.prev'), nextArrow: $('.next'), responsive: [ { breakpoint: 1420, settings: { dots:true, slidesToShow: 4, slidesToScroll: 4, } }, { breakpoint: 1024, settings: { slidesToShow: 1, slidesToScroll: 1, speed: 300, variableWidth: true, draggable:true, arrows:false, dots:true, infinite:false, swipeToSlide: true, } } ] }); if (window.matchMedia("(max-width: 1200px)").matches) { //Tile slider $('.staff-tiles .grid').slick({ speed: 300, variableWidth: true, draggable:true, arrows:false, dots:true, infinite:false, swipeToSlide: true, // You can unslick at a given breakpoint now by adding: // settings: "unslick" // instead of a settings object }); } //Content slider $('.content-slider-wrap').slick({ dots: true, }); // Magnific (gallery-slider) $('.gallery-slider').magnificPopup({ delegate: 'a.img-gallery-link', type: 'image', closeOnContentClick: false, closeBtnInside: false, mainClass: 'mfp-with-zoom mfp-img-mobile', image: { verticalFit: true, }, gallery: { enabled: true }, zoom: { enabled: true, duration: 300, // change the duration also in CSS opener: function(element) { return element; } } }); // Gallery popup $('.gallery-thumbnails .images').magnificPopup({ delegate: '.gallery-thumbnail-image', type: 'image', closeOnContentClick: false, closeBtnInside: false, mainClass: 'mfp-with-zoom mfp-img-mobile', image: { verticalFit: true, }, gallery: { enabled: true, }, zoom: { enabled: true, duration: 300, // change the duration also in CSS opener: function(element) { return element; } } }); // Gallery columns $('.gallery-columns').magnificPopup({ delegate: '.gallery-columns-image', type: 'image', closeOnContentClick: false, closeBtnInside: false, mainClass: 'mfp-with-zoom mfp-img-mobile', image: { verticalFit: true, }, gallery: { enabled: true, }, zoom: { enabled: true, duration: 300, // change the duration also in CSS opener: function(element) { return element; } } }); //Youtube videos in magnific $('a[href*="youtube/watch"]').magnificPopup({ type: 'iframe', mainClass: 'mfp-fade', preloader: false, fixedContentPos: false }); // Modal Popup $(document).on('click', 'a', function(event, ui) { var href = $(this).attr("href"); //remove http[s]:// from the href var protomatch = /^https?:\/\/|#/; var popup_data_id = href.replace(protomatch, ''); if($("[data-id='" + popup_data_id + "']").length != 0 && popup_data_id.length != 0) { event.preventDefault(); $('.popup').fadeOut(); $('.popup[data-id="' + popup_data_id + '"]').fadeIn(); $('html').addClass('popup-open'); window.location.hash = ''; } }); // Hash Modal Popup if(window.location.hash) { var popup_data_id = encodeURIComponent(window.location.hash.substring(1)); if($("[data-id='" + popup_data_id + "']").length != 0) { event.preventDefault(); $('.popup').fadeOut(); $('.popup[data-id="' + popup_data_id + '"]').fadeIn(); $('html').addClass('popup-open'); } } //close popup $('.popup .close').click(function(event){ event.preventDefault(); $(this).parents('.popup').fadeOut(); $('html').removeClass('popup-open'); window.location.hash = ''; }); // Donation popup if( $('.single-product.postid-15405 .woocommerce-message .wc-forward').length ) { //show popup $('.donation-popup').css({ display: "block" }); } //random home background image if($("#random-home-background").length != 0) { var time = new Date().getTime(); $.ajax({ type: 'GET', url: window.location+'/wp-content/themes/mogul_framework/ajax/random-home-background.php?='+time, success: function (url) { $('#random-home-background').css('background-image', 'url(' + url + ')'); }, error: function(error) { console.log(error); console.log("Something went wrong"); } }); } // Slick - product image slider $('.product-showcase-slider').slick({ slidesToShow: 1, slidesToScroll: 1, arrows: false, fade: true, asNavFor: '.product-nav-slider' }); $('.product-nav-slider').slick({ slidesToShow: 5, slidesToScroll: 1, asNavFor: '.product-showcase-slider', dots: true, focusOnSelect: true }); // product ZOOM $('.zoom_product').zoom({ magnify:1, touch:false }); /* Filtering */ if($('#filter-container').length) { // Select2 - nice styleable select boxes /* if($('.filter-group select').length) { $('.filter-group select').select2({ minimumResultsForSearch: 20 }); } */ var $grid; $('#filter-container').imagesLoaded(function() { $grid = $('#filter-container').isotope({ // set itemSelector so .grid-sizer is not used in layout itemSelector: '.tile', percentPosition: true, layoutMode: 'fitRows', // masonry: { // // use element for option // columnWidth: '.tile', // gutter: 0 // }, }); $grid.on( 'arrangeComplete', function( event, filteredItems ) { //if we have no results or not enough results, try to get more from the database if(filteredItems.length < $('#filter-container').attr('data-posts-per-page')) { filter_load_more(); } setTimeout(function(){ $('#filter-load-more').show(); }, 1200); if(filteredItems.length) { $('#filter-container').removeClass('no-results'); } }); filter(); //run filter }); //This function assembles the 'mixfilter' attributes from all .filter-group inputs and selects, and builds a string of classes to send to isotope (eg .termslug1.termslug2.termslug3) //You can add your own filter sources in here, just ensure this function is called on change/click and checks your sources for active filter values to add to the filtervalue variable function filter(){ $('#filter-load-more').show(); // get all active filters var filtervalue = ''; //radio and checkbox $('.filter-group input[type="radio"]:checked, .filter-group input[type="checkbox"]:checked').each(function(){ if( $(this).val() ) { filtervalue += '.' + $(this).val(); //each input value will include the . for the class, eg .somevalue, so we can concatenate the values easily } }); //selects $('.filter-group select').each(function(){ if( $(this).val() ) { filtervalue += '.' + $(this).val(); //each input value will include the . for the class, eg .somevalue, so we can concatenate the values easily } }); console.log('Filter value: ' + filtervalue); $grid.isotope({ filter: function() { if(filtervalue != '' && !$(this).is(filtervalue)){ //frst make sure we pass the regular class-based filter return false; } var filter_start_date = $('input[name="start_date"]').attr('data-filter_date'); console.log('filter_start_date: ' + filter_start_date) var item_start_date = $(this).attr('data-start_date'); console.log('item_start_date: ' + item_start_date) var filter_end_date = $('input[name="end_date"]').attr('data-filter_date'); var item_end_date = $(this).attr('data-end_date'); //basic filtering on start and end dates if(typeof filter_start_date != 'undefined' && item_end_date != '' && parseInt(item_end_date) < parseInt(filter_start_date)){ return false; } if(typeof filter_end_date != 'undefined' && item_start_date != '' && parseInt(item_start_date) > parseInt(filter_end_date)){ return false; } //now make sure the event has a session/performance in the filtered date range if(typeof filter_start_date != 'undefined' && typeof filter_end_date != 'undefined'){ var pass = false; for(var i = parseInt(filter_start_date); i <= parseInt(filter_end_date); i++){ var interval_year = i.toString().substring(0,4); var interval_month = i.toString().substring(4,6); var interval_day = i.toString().substring(6,8); var interval_date = new Date(interval_year, interval_month - 1, interval_day); var interval_week_day = interval_date.getDay(); if($(this).hasClass('weekly')){ //weekly events happen on one or more days of a week, so we need to check these against our filter dates if($(this).hasClass('day' + interval_week_day) && !$(this).hasClass('exclude' + interval_year + interval_month + interval_day)){ pass = true; } } else{ //regular patronbase events if($(this).hasClass('performance' + interval_year + interval_month + interval_day)){ pass = true; } } } return pass; } return true; } }); } //button / label clicks $('.filter-group input').click(function(event){ //if this is a radio button label, remove other active classes if( $(this).is('[type="radio"]') ){ $(this).parent('label').addClass('active'); $(this).parent('label').siblings().removeClass('active'); } else { $(this).parent().toggleClass('active'); } filter(); }); //set the value of data-mixfilter on selects when an option is chosen $('.filter-group select').change(function(){ filter(); }); var maxHeight = -1; $('.col.tile').each(function() { maxHeight = maxHeight > $(this).height() ? maxHeight : $(this).height(); }); $('.col.tile').each(function() { $(this).height(maxHeight); }); /* Blog filters - these have a set of taxonomy names which show and hide the relevant .filter-group */ $('.blog.filtering .filter-labels a').click(function(e){ e.preventDefault(); if($(this).hasClass('open')) { //we are closing a filter $(this).removeClass('open'); $('.filter-group').removeClass('open').slideUp(); } else { //we are opening a filter $(this).addClass('open').siblings().removeClass('open'); var tax = $(this).attr('data-taxonomy'); if( $('.filter-group[data-taxonomy="' + tax + '"]').length ){ $('.filter-group[data-taxonomy="' + tax + '"]').addClass('open').slideDown(); $('.filter-group[data-taxonomy="' + tax + '"]').siblings().removeClass('open').slideUp(); } } }); //filter-aware load more $('#filter-load-more').click(function(e){ e.preventDefault(); filter_load_more(); }); var last_load_more = 0; function filter_load_more() { console.log('filter_load_more()') var now = $.now(); //console.log(now - last_load_more + ' since last load more') if(now - last_load_more < 3000) { //don't load more often than once every 3s return false; } last_load_more = now; //hide 'no results' message if it's visible $('#filter-container').removeClass('no-results'); var filterstring = $('#isotope-filters :input, #isotope-filters select').serialize(); //turn out filter inputs into a nice query string //work out how many matching posts we have already and calculate how many posts we need var visible_tile_count = $('#filter-container .mix.tile:visible').length; var posts_per_page = $('#filter-container').attr('data-posts-per-page'); var posts_to_get = posts_per_page - (visible_tile_count % posts_per_page); //get post ids of posts we already have var post_ids = $('#filter-container .tile').map(function(){ return $(this).attr('data-postid'); }).get().join(); var post_not_in = '&post_not_in=' + post_ids; var ppp = '&posts_per_page=' + posts_to_get; filterstring = filterstring + post_not_in + ppp; console.log( filterstring ) $('#filter-load-more').text('Loading...'); $.get('?' + filterstring,function(data){ if($(data).find('#filter-container .mix.tile').length) { var $newtiles = $(data).find('#filter-container .mix.tile'); var tiles_inserted = $newtiles.length; $newtiles.imagesLoaded(function(){ $grid.isotope( 'insert', $newtiles ); //Reset (or hide) 'load more' button if($newtiles && $newtiles.length == posts_to_get){ //we found a full page of new tiles $('#filter-load-more').text('Load more'); } else if($newtiles && $newtiles.length < posts_to_get) { //we found some tiles but there are no more to get now $('#filter-load-more').hide().text('Load more'); } else { //we found some tiles but we already had them all $('#filter-load-more').text('No more results found').delay(500).fadeOut(500,function(){ $(this).text('Load more'); }); } }); } else { //no tiles found $('#filter-load-more').text('No more results found').delay(500).fadeOut(500,function(){ $(this).text('Load more'); }); if($grid.isotope('getFilteredItemElements') == 0) { $('#filter-container').addClass('no-results'); } } //finally, if we have no tiles at this point, we've failed if(tiles_inserted == 0 && $grid.isotope('getFilteredItemElements') == 0) { $('#filter-container').addClass('no-results'); } }); } }//if #filter-container // Video Background // debouncing function from John Hann (function($,sr){ var debounce = function (func, threshold, execAsap) { var timeout; return function debounced () { var obj = this, args = arguments; function delayed () { if (!execAsap) func.apply(obj, args); timeout = null; }; if (timeout) clearTimeout(timeout); else if (execAsap) func.apply(obj, args); timeout = setTimeout(delayed, threshold || 100); }; } // smartresize jQuery.fn[sr] = function(fn){ return fn ? this.bind('resize', debounce(fn)) : this.trigger(sr); }; })(jQuery,'smartresize'); (function (jQuery) { // Video background parent function resize_background_video() { jQuery('.bg-vid-parent .bg-video').each(function () { var $vid = jQuery(this), $bgvidparent = $vid.parent(), windowWidth = $bgvidparent.width(), windowHeight = $bgvidparent.outerHeight(), r_w = windowHeight / windowWidth, i_w = $vid.width(), i_h = $vid.height(), r_i = i_h / i_w, new_w, new_h; if (r_w > r_i) { new_h = windowHeight; new_w = windowHeight / r_i; } else { new_h = windowWidth * r_i; new_w = windowWidth; } $vid.css({ width : new_w, height : new_h, left : (windowWidth - new_w) / 2, top : (windowHeight - new_h) / 2 }); }); } // Video Background jQuery('.bg-vid-parent .bg-video').load(); jQuery('.bg-vid-parent .bg-video').on("loadedmetadata", function () { jQuery(this).css({ width: this.videoWidth, height: this.videoHeight }); resize_background_video(); jQuery(this).css('display', 'block'); }); jQuery(window).smartresize(function () { resize_background_video(); }); }(jQuery)); // End Video Background $('#mc-embedded-subscribe').on('click', function(event){ $('#mce-error-response').hide(); var checkbox1 = $('#mce-group-0').is(":checked"); var checkbox2 = $('#mce-group-1').is(":checked"); if( !checkbox1 && !checkbox2 ) { event.preventDefault(); $('#mce-error-response').text('Please select a group'); $('#mce-error-response').show(); } }); $('.datepicker').datepicker({ onSelect : function(datetext, dateobj) { console.log(dateobj) var year = dateobj.selectedYear.toString(); var month = (dateobj.selectedMonth + 1).toString().padStart(2,'0') ; var day = dateobj.selectedDay.padStart(2,'0'); //day is already a string var ymd = year + month + day; console.log(ymd) var id = dateobj.id; $('#' + id).attr('data-filter_date', ymd);//set the filter date as a data attribute ont he datepicker for easy retrieval filter(); } }); });//document.ready()