/
var
/
www
/
barefootlaw.org
/
wp-content
/
themes
/
barefoot
/
assets
/
js
/
Upload File
HOME
/** * wooCore functions file. * * Main wooCore core javascript file */ ;(function ($, window, document, undefined) { 'use strict'; var pluginName = 'wooCore', defaults = {}; // The actual plugin constructor function Plugin(element, options) { this.element = element; this.settings = $.extend({}, defaults, options); this._defaults = defaults; this._name = pluginName; this.__constructor(); } // Avoid Plugin.prototype conflicts $.extend(Plugin.prototype, { __constructor: function () { this.buildApp(this.element, this.options); }, buildApp: function (element, options) { var that = this; // Notification logic var messages = { 'div.woocommerce-info': 'info', 'div.woocommerce-message': 'success', 'div.woocommerce-error, ul.woocommerce-error': 'error' }, $messagesContainer = $('#js-woo-messages'); $(document).on('click', '.js-woo-message-hide', function(e){ e.preventDefault(); $(this).parent().fadeOut(300, function () { $(this).remove(); }); }); function wooMessageHandler(typeResponse) { // Remove notices only for Account page (in account section) $('.woocommerce_my_account_shortcode').find('.woocommerce-info, .woocommerce-error, .woocommerce-message').remove(); var timeout = 'ajax' === typeResponse ? 500 : 1000; for (var message in messages) { var type = messages[message]; if ($(message).length > 0) { $(message).each(function () { var html = $(this).remove().html(); // Remove all li tags html = html.replace(/<li>/g, '<div>'); html = html.replace(/<\/li>/g, '</div>'); // Remove all classes html = html.replace(/(button|wc-forward)/g, ''); var templateMessage = $('#js-woo-message-template').html(); templateMessage = templateMessage.replace(/%type%/g, type); templateMessage = templateMessage.replace(/%html%/g, html); $messagesContainer.prepend(templateMessage); }); } } setTimeout(function () { $messagesContainer.children().addClass('woo-messages-scale'); }, timeout); setTimeout(function () { $messagesContainer.children().fadeOut(300, function () { $(this).remove(); }); }, 10000 + timeout); } // Init Quantity controls function quantityInit() { var $quantity = $('div.quantity'); $quantity.prepend('<div class="quantity__minus">-</div>'); $quantity.append('<div class="quantity__plus">+</div>'); } // Moved `Update` button on Cart page (count left position td.product-quantity cell) function getQuantityPos() { var leftOffset = 0, $quantity = $('td.product-quantity'); if($quantity.length > 0 ) { leftOffset = $quantity.position().left; } return leftOffset; } // Update SexyUniform select form function updatetWooSelect() { $('select:not(.js-bf-grid-filter)').uniform(); } // Moved `Update` button on Cart page function moveUpdateBtn() { $('.woo-cart-updates').css('padding-left', getQuantityPos()); } // Hide / Show related controls function carouselControlControls(relatedCarousel) { var $carousel = $('.products-single-wrapper'), ww = window.innerWidth; if($carousel.length > 0) { $carousel.each(function(i, e){ var $productCarousel = $(e).find('.row.products'), products = $productCarousel.children().size(); if ( ( ww > 300 && ww < 599 ) && products > 1) { $(e).addClass('show-controls'); } else if ( ( ww > 300 && ww < 599 ) && products === 1) { $(e).removeClass('show-controls'); } if ( ( ww > 600 && ww < 929 ) && products > 2) { $(e).addClass('show-controls'); } else if ( ( ww > 600 && ww < 929 ) && products < 2) { $(e).removeClass('show-controls'); } if ( ( ww > 930 && ww < 1279 ) && products > 3) { $(e).addClass('show-controls'); } else if ( ( ww > 930 && ww < 1279 ) && products < 3) { $(e).removeClass('show-controls'); } if ( ( ww > 1280 && ww < 1789 ) && products > 4 ) { $(e).addClass('show-controls'); } else if( ( ww > 1280 && ww < 1789 ) && products < 4 ) { $(e).removeClass('show-controls'); } if ( ww > 1790 && products > 6) { $(e).addClass('show-controls'); } else if (ww > 1790 && products < 6) { $(e).removeClass('show-controls'); } switch (true) { case (ww > 300 && ww < 599): $productCarousel.trigger('configuration', { items: { visible: 1 } }); break; case ( ww > 600 && ww < 929): $productCarousel.trigger('configuration', { items: { visible: 2 } }); break; case (ww > 930 && ww < 1279): $productCarousel.trigger('configuration', { items: { visible: 3 } }); break; case (ww > 1280 && ww < 1789): $productCarousel.trigger('configuration', { items: { visible: 4 } }); break; } $productCarousel.trigger("updateSizes"); }); } } // Style radio buttons for WooCommerce / Re-init function initWooRadioButton() { var $radios = $('.woo-cart-collaterals [type="radio"]'); $radios.uniform(); } // Stretch catalog filter function stretchCatalogFilters() { var $filters = $('#js-filters'), $filtersBar = $filters.closest('.products-top-bar'); if($filters.length > 0 && $filtersBar.length > 0) { var offsetLeft = $filtersBar.offset().left; $('.products-top-bar-bg').css({ left : -1 * offsetLeft, right : -1 * offsetLeft }); } } /*------------------------------------------------------------- CORE LOAD METHOD START ------------------------------------------------------------------------*/ $(window).load(function () { // Chosen Ordering var $wooFilter = $('.woocommerce-ordering .orderby'); if($wooFilter.length > 0) { $wooFilter.chosen({ disable_search_threshold: 10, disable_search: true }); } // Hover on product card (title product) $('.js-product-hover-trigger a').mouseenter(function () { $(this).closest('.product').find('.js-product-thumbnail').addClass('active'); }).mouseleave(function (e) { var gotoElement = event.toElement || e.relatedTarget; if(gotoElement) { if (gotoElement.className.indexOf('js-product-entry') === -1 || typeof gotoElement.className === 'undefined') { $(this).closest('.product').find('.js-product-thumbnail').removeClass('active'); } } }); // Remove active class from thumbnail $('.js-product-thumbnail').mouseenter(function () { $(this).removeClass('active'); }); $('.js-product-entry').mouseleave(function () { $(this).find('.js-product-thumbnail').removeClass('active'); }); // Change text on price box when hover - cart / more info $('.js-product-action-trigger').mouseenter(function () { var $link = $(this); if ($(this).parent('a').length > 0) { $link = $(this).parent('a'); } var text = $link.attr('title'); if (typeof text === 'undefined') { text = $link.attr('aria-label'); } var $priceBlock = $link.closest('.product').find('.price'); $priceBlock.children(':not(i)').css('opacity', '0'); $priceBlock.children('i').html(text); $priceBlock.children('i').css('opacity', '1'); }).mouseleave(function () { var $link = $(this); if ($(this).parent('a').length > 0) { $link = $(this).parent('a'); } var $priceBlock = $link.closest('.product').find('.price'); $priceBlock.children(':not(i)').css('opacity', '1'); $priceBlock.children('i').css('opacity', '0'); }); // Open/Close Catalog filters with widgets $('#js-filter-toggle').on('click', function (eventObject) { eventObject.preventDefault(); $($(this).attr('href')).fadeToggle(); }); // Hide filters after click on document $(document).on('click', function (e) { var container = $('#js-filters, #js-filter-toggle'); if (!container.is(e.target) && container.has(e.target).length === 0) { $('#js-filters').hide(); } }); // Masonry grid var $mixedProducts = $('#js-products-mixed'); if ($mixedProducts.length > 0) { $mixedProducts.imagesLoaded(function () { $mixedProducts.isotope({ // main isotope options itemSelector: '.product', // set layoutMode layoutMode: 'packery', // options for cellsByRow layout mode cellsByRow: { columnWidth: 200, rowHeight: 150 }, // options for masonry layout mode masonry: { columnWidth: '.grid-sizer' }, transitionDuration: '0.3s', percentPosition: true }) }); } // Show notice after page load update wooMessageHandler('load'); //Quick cart logic $(document).on('click','#js-woo-quick-cart-close, #js-woo-quick-cart-back', function(eventObject){ eventObject.preventDefault(); var $modal = $('#js-woo-quick-cart'); $modal.addClass('woo-page-modal--hide'); $('#js-woo-quick-cart-back').fadeOut(); setTimeout(function () { $modal.removeClass('woo-page-modal--show woo-page-modal--hide'); }, 450); }); $(document).on('click','#js-woo-cart-toggle',function(eventObject){ eventObject.preventDefault(); var $modal = $('#js-woo-quick-cart'); if (!$modal.hasClass('woo-page-modal--show')) { if (!$('.woo-page-modal.show').length) { $modal.addClass('woo-page-modal--show'); $('#js-woo-quick-cart-back').fadeIn(); } else { $modal.siblings('.woo-page-modal').addClass('hide'); setTimeout(function () { $modal.siblings('.woo-page-modal').removeClass('woo-page-modal--show woo-page-modal--hide'); $modal.addClass('woo-page-modal--show') }, 450); } } }); // Quality +/- logic var quantity = 0; $(document).on('click','.quantity__plus', function(e){ e.preventDefault(); var $quantityInput = $(this).parent().find('input'); quantity = parseInt($quantityInput.val()); $quantityInput.val(quantity + 1).trigger('change'); }); $(document).on('click','.quantity__minus', function(e){ e.preventDefault(); var $quantityInput = $(this).parent().find('input'); quantity = parseInt($quantityInput.val()); if(quantity>0){ $quantityInput.val(quantity - 1).trigger('change'); } }); // Add quantity controls after page load quantityInit(); // Moved `Update` button on Cart page moveUpdateBtn(); // Dynamic apply coupon code code on checkout page $(document).on('click', '.js-apply-coupon', function(e){ e.preventDefault(); var value = $('.js-coupon-code').val(), $form = $('.js-checkout_coupon'); if(value) { $form.html('<input type="hidden" value="'+value+'" name="coupon_code"><input type="hidden" value="s" name="apply_coupon">'); $form.submit(); } }); // Product gallery (popup/carousel - v/h) on product page var $gallery = $('.js-product-gallery .woocommerce-product-gallery__wrapper'), $galleryPagination = $('.js-product-gallery-pagination'); if($('.js-product-gallery').length > 0) { var slides = $gallery.children().size(); if(slides <= 1) { $('.js-product-gallery').addClass('woo-product-gallery__body--oneslide'); } $gallery.caroufredsel({ responsive: true, auto: false, height: 'variable', infinity : false, circular : false, swipe : { onTouch : true, onMouse : false }, prev : '.woo-product-gallery-arrow--prev', next : '.woo-product-gallery-arrow--next', pagination : '.woo-product-gallery-pagination', items: { visible: 1, width: 370, height: 'variable' }, onCreate: function () { var center = $gallery.triggerHandler('currentPosition'); $gallery.find('.woocommerce-product-gallery__image').eq(center).addClass('selected-gallery'); }, scroll: { fx: 'crossfade', items: 1, onBefore: function( data ) { var src = data.items.visible.first().data( 'thumb' ), center = $galleryPagination.triggerHandler('currentPosition'); $galleryPagination.trigger( 'slideTo', [ 'li[data-thumb="'+ src +'"]', -center ] ); }, onAfter : function(data) { var $current = data.items.visible; $current.addClass('selected-gallery').siblings().removeClass('selected-gallery'); } } }); if($galleryPagination.length > 0) { $galleryPagination.carouFredSel({ auto: false, width: 91, direction: 'up', scroll : { items: 1, duration : 500 }, items: { height: 151, visible : 4 }, onCreate: function () { var center = $galleryPagination.triggerHandler('currentPosition'); $galleryPagination.trigger( 'slideTo', [ -center, { duration: 0 } ] ); $galleryPagination.find('.woo-product-gallery__image').eq(center).addClass('selected'); } }); $galleryPagination.find('.woo-product-gallery__image a').on('click', function(e){ e.preventDefault(); var src = $(this).parent('li').data('thumb'); $(this).closest('.woo-product-gallery__image').addClass('selected').siblings().removeClass('selected'); $gallery.trigger( 'slideTo', [ 'div[data-thumb="'+ src +'"]' ] ); }); } } $('.js-product-gallery .woocommerce-product-gallery__image a').magnificPopup({ type: 'image', tLoading: '', gallery: { enabled: true, tCounter: '<span class="mfp-counter">%curr%<ins></ins>%total%</span>', navigateByImgClick: true }, closeMarkup : '<button class="mfp-close"></button>', fixedContentPos: false, callbacks: { open: function() { $('body').addClass('noscroll'); }, close: function() { $('body').removeClass('noscroll'); }, markupParse: function(template, values, item) { template.find('.mfp-caption').html(item.el.data('cats')); } }, iframe : { markup: '<div class="mfp-iframe-scaler">'+ '<div class="mfp-close"></div>'+ '<iframe class="mfp-iframe" frameborder="0" allowfullscreen></iframe>'+ '<div class="mfp-bottom-bar">'+ '<div class="mfp-title-table"><div class="mfp-title-row"><div class="mfp-title"></div><div class="mfp-counter"></div></div></div>'+ '</div>'+ '</div>' }, image: { markup: '<div class="mfp-brd"></div><div class="mfp-figure">'+ '<div class="mfp-close"></div>'+ '<div class="mfp-top-bar"></div>'+ '<div class="mfp-img"></div>'+ '<div class="mfp-caption"></div>'+ '<div class="mfp-bottom-bar">'+ '<div class="mfp-title-table"><div class="mfp-title-row"><div class="mfp-title"></div><div class="mfp-counter"></div></div></div>'+ '</div>'+ '</div>', titleSrc: function(item) { return item.el.attr('title'); } } }); // Review scroll -> to review tab $('a[href="#reviews"]').on('click', function() { $('a[href="#tab-reviews"]').trigger('click'); 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) { var moreSpace = 20, $header = $('header[role="banner"]'); if($header.hasClass('affix-top') || $header.hasClass('affix')) { moreSpace += $header.outerHeight(true); } $('html, body').animate({ scrollTop: target.offset().top - moreSpace }, 1000); return false; } } }); // Rating Stars on review var $raty = $('.raty'); if ($raty.length > 0) { $raty.raty({ starType: 'i', readOnly: function () { return $(this).data('readonly'); }, score: function () { return $(this).data('score'); }, click: function(score, evt) { $(this).closest('.comment-form-rating').find('#raty-rating').attr('value',score).val(score).trigger('change'); }, starOff: 'icon-star star-off', starOn: 'icon-star', starHalf: 'icon-star' }); } // Related / Up|Cross Sells Carousel var $related = $('.related.products, .upsells.products, .cross-sells'); if($related.length > 0 ) { $related.each(function(i, e){ var $carousel = $(e).find('.row.products'), next = $(e).find('.products-single-wrapper__arrow--next'), prev = $(e).find('.products-single-wrapper__arrow--prev'), pagination = $(e).find('.js-products-single-wrapper-pagination'), options = { auto: false, height: 'variable', scroll: { items: 1 }, swipe : { onTouch : true, onMouse : false }, prev : prev, next : next, pagination : pagination, items : { height: 'variable' } }; if($carousel.length > 0) { $carousel.carouFredSel(options); } }); } // Show / Hide controls for (Related / Up|Cross Sells Carousel) carouselControlControls('.products-single-wrapper'); // Account Form Validation (login) var $formAccountLogin = $('.js-login-form'), $formResetAccount = $('.js-login-reset-form'); if($formAccountLogin.length > 0) { $formAccountLogin.validate({ errorClass: 'wpcf7-not-valid', errorPlacement: function () { return true }, highlight: function (element, errorClass, validClass) { $(element).addClass(errorClass).removeClass(validClass); }, focusInvalid: false, unhighlight: function (element, errorClass, validClass) { $(element).removeClass(errorClass).addClass(validClass); } }); } if($formResetAccount.length > 0 ) { $formResetAccount.validate({ errorClass: 'wpcf7-not-valid', rules: { password_1: "required", password_2: { equalTo: "#password_1" } }, errorPlacement: function(error,element) { return true; }, highlight: function (element, errorClass, validClass) { $(element).addClass(errorClass).removeClass(validClass); }, focusInvalid: false, unhighlight: function (element, errorClass, validClass) { $(element).removeClass(errorClass).addClass(validClass); } }); } // Fire some handlers after AJAX event $(document).ajaxComplete(function () { // Show notice after page AJAX update wooMessageHandler('ajax'); // Add quantity controls after AJAX quantityInit(); // Update select/radio Uniform after AJAX updatetWooSelect(); initWooRadioButton(); // Moved `Update` button on Cart page moveUpdateBtn(); }); // Sexy radio buttons initWooRadioButton(); // Catalog filters stretch stretchCatalogFilters(); }); /*------------------------------------------------------------- CORE LOAD METHOD END ------------------------------------------------------------------------*/ /*------------------------------------------------------------- CORE RESIZE METHOD START ------------------------------------------------------------------------*/ var now = Date.now || function () { return new Date().getTime(); }; var debounce = function (func, wait, immediate) { var timeout, args, context, timestamp, result; var later = function () { var last = now() - timestamp; if (last < wait && last >= 0) { timeout = setTimeout(later, wait - last); } else { timeout = null; if (!immediate) { result = func.apply(context, args); if (!timeout) context = args = null; } } }; return function () { context = this; args = arguments; timestamp = now(); var callNow = immediate && !timeout; if (!timeout) timeout = setTimeout(later, wait); if (callNow) { result = func.apply(context, args); context = args = null; } return result; }; }; var resizeDebounce = debounce(function () { // Show / Hide controls carouselControlControls('.products-single-wrapper'); // Moved `Update` button on Cart page moveUpdateBtn(); // Catalog filters stretch stretchCatalogFilters(); }, 200); window.addEventListener('resize', resizeDebounce); /*------------------------------------------------------------- CORE RESIZE METHOD END ------------------------------------------------------------------------*/ $(document.body).on('update_checkout updated_cart_totals country_to_state_changed updated_shipping_method updated_wc_div',function(){ // Update select/radio Uniform after WooCommerce Triggers updatetWooSelect(); initWooRadioButton(); }); } }); $.fn[pluginName] = function (options) { return this.each(function () { if (!$.data(this, 'plugin_' + pluginName)) { $.data(this, 'plugin_' + pluginName, new Plugin(this, options)); } }); }; })(jQuery, window, document); jQuery(document).ready(function ($) { $(document.body).wooCore(); });