/**
* 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', '.variation-radios input', function() {
$('.variation-radios input:checked').each(function(index, element) {
var $el = $(element);
var thisName = $el.attr('name');
var thisVal = $el.attr('value');
$('select[name="'+thisName+'"]').val(thisVal).trigger('change');
});
});
$(document).on('woocommerce_update_variation_values', function() {
$('.variation-radios input').each(function(index, element) {
var $el = $(element);
var thisName = $el.attr('name');
var thisVal = $el.attr('value');
$el.removeAttr('disabled');
if($('select[name="'+thisName+'"] option[value="'+thisVal+'"]').is(':disabled')) {
$el.prop('disabled', true);
}
});
});
$('.post-medium').each( function() {
const self = $(this);
self.find('.post-image').css('height', self.height());
} );
});
$("#preloader").hide();
}( jQuery, window, document ) );