/** * Frontend scripts. * */ /* global Themeoo, themeoo_ajax, console */ ( function( $, window, document ) { /** * File skip-link-focus-fix.js. * * Helps with accessibility for keyboard only users. * * This is the source file for what is minified in the twenty_twenty_one_skip_link_focus_fix() PHP function. * * Learn more: https://git.io/vWdr2 */ ( function() { var isIe = /(trident|msie)/i.test( navigator.userAgent ); if ( isIe && document.getElementById && window.addEventListener ) { window.addEventListener( 'hashchange', function() { var id = location.hash.substring( 1 ), element; if ( ! ( /^[A-z0-9_-]+$/.test( id ) ) ) { return; } element = document.getElementById( id ); if ( element ) { if ( ! ( /^(?:a|select|input|button|textarea)$/i.test( element.tagName ) ) ) { element.tabIndex = -1; } element.focus(); } }, false ); } }() ); // on ready. $(document).ready( function () { $('.themeoo-countdown').each(function () { var $countdown = $(this); $countdown.countdown($countdown.data('date'), function(event) { $(this).html(event.strftime('
%D
'+ 'Days' +'
%H
'+ 'Hrs' +'
%M
'+ 'Mins' +'
%S
'+ 'Secs' +'
')); }); }); // Prevent Disable Functions $('.disabled').click(function(e) { e.preventDefault(); } ); $('.variations_form .variations ul.variable-items-wrapper').each(function () { var select = $(this).prev('select'); var li = $(this).find('li'); $(this).on('click', 'li:not(.selected)', function () { var value = $(this).data('value'); li.removeClass('selected'); select.val(value).trigger('change'); $(this).addClass('selected'); }); $(this).on('click', 'li.selected', function () { li.removeClass('selected'); select.val('').trigger('change'); select.trigger('click'); select.trigger('focusin'); select.trigger('touchstart'); }); }); $('.quantity input.qty').after('+-'); $(document).on('click', 'span.qty-btn', function ( event ) { var $target = $(event.target), $input = $target.parents('.quantity').find('input[type="number"]'), max = Number( $input.attr('max') ), min = Number( $input.attr('min') ), step = Number( $input.attr('step') ), value = Number( $input.val() ); if( $target.hasClass('inc') ) { value = value+step; if( max !== 0 && value > max ) return; $input.val( value ); $input.trigger('change'); } if( $target.hasClass('dec') ) { value = value - step; if( value < min ) return; $input.val( value ); $input.trigger('change'); } }); $(document).on('click', '.mini_cart_item a.remove', function (e) { e.preventDefault(); var product_id = $(this).attr("data-product_id"), cart_item_key = $(this).attr("data-cart_item_key"), product_container = $(this).parents('.mini_cart_item'); // Add loader product_container.block({ message: null, overlayCSS: { cursor: 'none' } }); $.ajax({ type: 'POST', dataType: 'json', url: wc_add_to_cart_params.ajax_url, data: { action: "product_remove", product_id: product_id, cart_item_key: cart_item_key }, success: function(response) { if ( ! response || response.error ) return; var fragments = response.fragments; // Replace fragments if ( fragments ) { $.each( fragments, function( key, value ) { $( key ).replaceWith( value ); }); } } }); }); $(document).on('change', '.themeoo-attributes input', function() { $('.themeoo-attributes input:checked').each(function(index, element) { const $el = $(element); $('select[name="'+$el.attr('name')+'"]').val($el.attr('value')).trigger('change'); }); }); $(document).on('woocommerce_update_variation_values', function() { $('.themeoo-attributes input').each(function(index, element) { const $el = $(element); $el.removeAttr('disabled'); if($('select[name="'+$el.attr('name')+'"] option[value="'+$el.attr('value')+'"]').is(':disabled')) { $el.prop('disabled', true); } }); }); $( '.variations_form' ).on('click', '.reset_variations', function() { $( '.themeoo-attributes input' ).val( '' ).removeAttr( 'checked' ).prop( 'checked', false ); } ); $('.post-medium').each( function() { const self = $(this); self.find('.post-image').css('height', self.height()); } ); //masonary for blog grid layout $('.grid-container').masonry({ // options itemSelector: '.post-grid-wrap', }); }); $("#preloader").hide(); }( jQuery, window, document ) );