modified file plugins
This commit is contained in:
@ -0,0 +1,285 @@
|
||||
jQuery( function( $ ) {
|
||||
var debounce = function( callback, wait ) {
|
||||
var timeout;
|
||||
|
||||
return function() {
|
||||
clearTimeout( timeout );
|
||||
|
||||
timeout = setTimeout( function() {
|
||||
timeout = undefined;
|
||||
callback.call();
|
||||
}, wait );
|
||||
};
|
||||
};
|
||||
|
||||
$( 'body' ).on( 'added_to_cart', function() {
|
||||
if ( ! $( '.wc-menu-item' ).hasClass( 'has-items' ) ) {
|
||||
$( '.wc-menu-item' ).addClass( 'has-items' );
|
||||
}
|
||||
|
||||
if ( ! $( '.wc-mobile-cart-items' ).hasClass( 'has-items' ) ) {
|
||||
$( '.wc-mobile-cart-items' ).addClass( 'has-items' );
|
||||
}
|
||||
} );
|
||||
|
||||
$( 'body' ).on( 'removed_from_cart', function() {
|
||||
var numberOfItems = $( '.number-of-items' );
|
||||
|
||||
if ( numberOfItems.length ) {
|
||||
if ( numberOfItems.hasClass( 'no-items' ) ) {
|
||||
$( '.wc-menu-item' ).removeClass( 'has-items' );
|
||||
$( '.wc-mobile-cart-items' ).removeClass( 'has-items' );
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
if ( generateWooCommerce.addToCartPanel ) {
|
||||
$( document.body ).on( 'added_to_cart', function() {
|
||||
var adminBar = $( '#wpadminbar' ),
|
||||
stickyNav = $( '.navigation-stick' ),
|
||||
top = 0;
|
||||
|
||||
if ( adminBar.length ) {
|
||||
top = adminBar.outerHeight();
|
||||
}
|
||||
|
||||
if ( stickyNav.length && '0px' === stickyNav.css( 'top' ) ) {
|
||||
top = top + stickyNav.outerHeight();
|
||||
}
|
||||
|
||||
$( '.add-to-cart-panel' ).addClass( 'item-added' ).css( {
|
||||
'-webkit-transform': 'translateY(' + top + 'px)',
|
||||
'-ms-transform': 'translateY(' + top + 'px)',
|
||||
transform: 'translateY(' + top + 'px)',
|
||||
} );
|
||||
} );
|
||||
|
||||
$( '.add-to-cart-panel .continue-shopping' ).on( 'click', function( e ) {
|
||||
e.preventDefault();
|
||||
|
||||
$( '.add-to-cart-panel' ).removeClass( 'item-added' ).css( {
|
||||
'-webkit-transform': 'translateY(-100%)',
|
||||
'-ms-transform': 'translateY(-100%)',
|
||||
transform: 'translateY(-100%)',
|
||||
} );
|
||||
} );
|
||||
|
||||
$( window ).on( 'scroll', debounce( function() {
|
||||
var panel = $( '.add-to-cart-panel' );
|
||||
|
||||
if ( panel.hasClass( 'item-added' ) ) {
|
||||
panel.removeClass( 'item-added' ).css( {
|
||||
'-webkit-transform': 'translateY(-100%)',
|
||||
'-ms-transform': 'translateY(-100%)',
|
||||
transform: 'translateY(-100%)',
|
||||
} );
|
||||
}
|
||||
}, 250 ) );
|
||||
}
|
||||
|
||||
if ( generateWooCommerce.stickyAddToCart ) {
|
||||
var lastScroll = 0;
|
||||
var scrollDownTimeout = 300;
|
||||
|
||||
$( window ).on( 'scroll', debounce( function() {
|
||||
var adminBar = $( '#wpadminbar' ),
|
||||
stickyNav = $( '.navigation-stick' ),
|
||||
stuckElement = $( '.stuckElement' ),
|
||||
top = 0,
|
||||
scrollTop = $( window ).scrollTop(),
|
||||
panel = $( '.add-to-cart-panel' ),
|
||||
panelPosition = panel.offset().top + panel.outerHeight(),
|
||||
button = $( '.single_add_to_cart_button' ),
|
||||
buttonTop = button.offset().top,
|
||||
buttonHeight = button.outerHeight(),
|
||||
footerTop = $( '.site-footer' ).offset().top;
|
||||
|
||||
if ( stuckElement.length === 0 ) {
|
||||
scrollDownTimeout = 0;
|
||||
}
|
||||
|
||||
if ( scrollTop > ( buttonTop + buttonHeight ) && panelPosition < footerTop ) {
|
||||
setTimeout( function() {
|
||||
if ( adminBar.length ) {
|
||||
top = adminBar.outerHeight();
|
||||
}
|
||||
|
||||
if ( stickyNav.length ) {
|
||||
if ( stickyNav.hasClass( 'auto-hide-sticky' ) ) {
|
||||
if ( scrollTop < lastScroll && '0px' === stickyNav.css( 'top' ) ) {
|
||||
top = top + stickyNav.outerHeight();
|
||||
} else {
|
||||
top = top;
|
||||
}
|
||||
|
||||
lastScroll = scrollTop;
|
||||
} else {
|
||||
top = top + stickyNav.outerHeight();
|
||||
}
|
||||
}
|
||||
|
||||
panel.addClass( 'show-sticky-add-to-cart' ).css( {
|
||||
'-webkit-transform': 'translateY(' + top + 'px)',
|
||||
'-ms-transform': 'translateY(' + top + 'px)',
|
||||
transform: 'translateY(' + top + 'px)',
|
||||
} );
|
||||
}, scrollDownTimeout );
|
||||
} else {
|
||||
panel.removeClass( 'show-sticky-add-to-cart' ).css( {
|
||||
'-webkit-transform': '',
|
||||
'-ms-transform': '',
|
||||
transform: '',
|
||||
} );
|
||||
}
|
||||
}, 50 ) );
|
||||
|
||||
$( '.go-to-variables' ).on( 'click', function( e ) {
|
||||
e.preventDefault();
|
||||
|
||||
var offset = 0,
|
||||
stickyNav = $( '.navigation-stick' ),
|
||||
adminBar = $( '#wpadminbar' );
|
||||
|
||||
if ( stickyNav.length ) {
|
||||
offset = stickyNav.outerHeight();
|
||||
}
|
||||
|
||||
if ( adminBar.length ) {
|
||||
offset = offset + adminBar.outerHeight();
|
||||
}
|
||||
|
||||
$( 'html, body' ).animate( {
|
||||
scrollTop: $( '.variations' ).offset().top - offset,
|
||||
}, 250 );
|
||||
} );
|
||||
}
|
||||
|
||||
$( function() {
|
||||
'use strict';
|
||||
|
||||
if ( generateWooCommerce.quantityButtons ) {
|
||||
generateQuantityButtons();
|
||||
}
|
||||
} );
|
||||
|
||||
$( document ).ajaxComplete( function() {
|
||||
'use strict';
|
||||
|
||||
if ( generateWooCommerce.quantityButtons ) {
|
||||
generateQuantityButtons();
|
||||
}
|
||||
} );
|
||||
|
||||
function generateQuantityButtons() {
|
||||
// Check if we have an overwrite hook for this function
|
||||
try {
|
||||
return generateWooCommerce.hooks.generateQuantityButtons();
|
||||
} catch ( e ) {
|
||||
// No hook in place, carry on
|
||||
}
|
||||
|
||||
// Grab the FIRST available cart form on the page
|
||||
var cart = $( '.woocommerce div.product form.cart' ).first();
|
||||
|
||||
// Check if we see elementor style classes
|
||||
if ( cart.closest( '.elementor-add-to-cart' ).length ) {
|
||||
// Found classes, remove them and finish here
|
||||
$( '.elementor.product' ).removeClass( 'do-quantity-buttons' );
|
||||
return;
|
||||
}
|
||||
|
||||
// Grab all the quantity boxes that need dynamic buttons adding
|
||||
var quantityBoxes;
|
||||
|
||||
try {
|
||||
// Is there a hook available?
|
||||
quantityBoxes = generateWooCommerce.selectors.generateQuantityButtons.quantityBoxes;
|
||||
} catch ( e ) {
|
||||
// Use the default plugin selector functionality
|
||||
quantityBoxes = $( '.cart div.quantity:not(.buttons-added), .cart td.quantity:not(.buttons-added)' ).find( '.qty' );
|
||||
}
|
||||
|
||||
// Test the elements have length and greater than 0
|
||||
// Try, catch here to provide basic error checking on hooked data
|
||||
try {
|
||||
// Nothing found... stop here
|
||||
if ( quantityBoxes.length === 0 ) {
|
||||
return false;
|
||||
}
|
||||
} catch ( e ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Allow the each loop callback to be completely overwritten
|
||||
var quantityBoxesCallback;
|
||||
|
||||
try {
|
||||
// Try assign a hooked callback
|
||||
quantityBoxesCallback = generateWooCommerce.callbacks.generateQuantityButtons.quantityBoxes;
|
||||
} catch ( e ) {
|
||||
// Use the default callback handler
|
||||
quantityBoxesCallback = function( key, value ) {
|
||||
var box = $( value );
|
||||
|
||||
// Check allowed types
|
||||
if ( [ 'date', 'hidden' ].indexOf( box.prop( 'type' ) ) !== -1 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add plus and minus icons
|
||||
box.parent().addClass( 'buttons-added' ).prepend( '<a href="javascript:void(0)" class="minus">-</a>' );
|
||||
box.after( '<a href="javascript:void(0)" class="plus">+</a>' );
|
||||
|
||||
// Enforce min value on the input
|
||||
var min = parseFloat( $( this ).attr( 'min' ) );
|
||||
|
||||
if ( min && min > 0 && parseFloat( $( this ).val() ) < min ) {
|
||||
$( this ).val( min );
|
||||
}
|
||||
|
||||
// Add event handlers to plus and minus (within this scope)
|
||||
box.parent().find( '.plus, .minus' ).on( 'click', function() {
|
||||
// Get values
|
||||
var currentQuantity = parseFloat( box.val() ),
|
||||
maxQuantity = parseFloat( box.attr( 'max' ) ),
|
||||
minQuantity = parseFloat( box.attr( 'min' ) ),
|
||||
step = box.attr( 'step' );
|
||||
|
||||
// Fallback default values
|
||||
if ( ! currentQuantity || '' === currentQuantity || 'NaN' === currentQuantity ) {
|
||||
currentQuantity = 0;
|
||||
}
|
||||
|
||||
if ( '' === maxQuantity || 'NaN' === maxQuantity ) {
|
||||
maxQuantity = '';
|
||||
}
|
||||
|
||||
if ( '' === minQuantity || 'NaN' === minQuantity ) {
|
||||
minQuantity = 0;
|
||||
}
|
||||
|
||||
if ( 'any' === step || '' === step || undefined === step || 'NaN' === parseFloat( step ) ) {
|
||||
step = 1;
|
||||
}
|
||||
|
||||
if ( $( this ).is( '.plus' ) ) {
|
||||
if ( maxQuantity && ( maxQuantity === currentQuantity || currentQuantity > maxQuantity ) ) {
|
||||
box.val( maxQuantity );
|
||||
} else {
|
||||
box.val( currentQuantity + parseFloat( step ) );
|
||||
}
|
||||
} else if ( minQuantity && ( minQuantity === currentQuantity || currentQuantity < minQuantity ) ) {
|
||||
box.val( minQuantity );
|
||||
} else if ( currentQuantity > 0 ) {
|
||||
box.val( currentQuantity - parseFloat( step ) );
|
||||
}
|
||||
|
||||
// Trigger change event
|
||||
box.trigger( 'change' );
|
||||
} );
|
||||
};
|
||||
}
|
||||
|
||||
$.each( quantityBoxes, quantityBoxesCallback );
|
||||
}
|
||||
} );
|
@ -0,0 +1 @@
|
||||
jQuery(function(d){function t(t,a){var e;return function(){clearTimeout(e),e=setTimeout(function(){e=void 0,t.call()},a)}}var m,u;function a(){try{return generateWooCommerce.hooks.generateQuantityButtons()}catch(t){}var a,e;if(d(".woocommerce div.product form.cart").first().closest(".elementor-add-to-cart").length)d(".elementor.product").removeClass("do-quantity-buttons");else{try{a=generateWooCommerce.selectors.generateQuantityButtons.quantityBoxes}catch(t){a=d(".cart div.quantity:not(.buttons-added), .cart td.quantity:not(.buttons-added)").find(".qty")}try{if(0===a.length)return}catch(t){return}try{e=generateWooCommerce.callbacks.generateQuantityButtons.quantityBoxes}catch(t){e=function(t,a){var s=d(a);-1===["date","hidden"].indexOf(s.prop("type"))&&(s.parent().addClass("buttons-added").prepend('<a href="javascript:void(0)" class="minus">-</a>'),s.after('<a href="javascript:void(0)" class="plus">+</a>'),(a=parseFloat(d(this).attr("min")))&&0<a&&parseFloat(d(this).val())<a&&d(this).val(a),s.parent().find(".plus, .minus").on("click",function(){var t=parseFloat(s.val()),a=parseFloat(s.attr("max")),e=parseFloat(s.attr("min")),o=s.attr("step");t&&""!==t&&"NaN"!==t||(t=0),""!==a&&"NaN"!==a||(a=""),""!==e&&"NaN"!==e||(e=0),"any"!==o&&""!==o&&void 0!==o&&"NaN"!==parseFloat(o)||(o=1),d(this).is(".plus")?a&&(a===t||a<t)?s.val(a):s.val(t+parseFloat(o)):e&&(e===t||t<e)?s.val(e):0<t&&s.val(t-parseFloat(o)),s.trigger("change")}))}}d.each(a,e)}}d("body").on("added_to_cart",function(){d(".wc-menu-item").hasClass("has-items")||d(".wc-menu-item").addClass("has-items"),d(".wc-mobile-cart-items").hasClass("has-items")||d(".wc-mobile-cart-items").addClass("has-items")}),d("body").on("removed_from_cart",function(){var t=d(".number-of-items");t.length&&t.hasClass("no-items")&&(d(".wc-menu-item").removeClass("has-items"),d(".wc-mobile-cart-items").removeClass("has-items"))}),generateWooCommerce.addToCartPanel&&(d(document.body).on("added_to_cart",function(){var t=d("#wpadminbar"),a=d(".navigation-stick"),e=0;t.length&&(e=t.outerHeight()),a.length&&"0px"===a.css("top")&&(e+=a.outerHeight()),d(".add-to-cart-panel").addClass("item-added").css({"-webkit-transform":"translateY("+e+"px)","-ms-transform":"translateY("+e+"px)",transform:"translateY("+e+"px)"})}),d(".add-to-cart-panel .continue-shopping").on("click",function(t){t.preventDefault(),d(".add-to-cart-panel").removeClass("item-added").css({"-webkit-transform":"translateY(-100%)","-ms-transform":"translateY(-100%)",transform:"translateY(-100%)"})}),d(window).on("scroll",t(function(){var t=d(".add-to-cart-panel");t.hasClass("item-added")&&t.removeClass("item-added").css({"-webkit-transform":"translateY(-100%)","-ms-transform":"translateY(-100%)",transform:"translateY(-100%)"})},250))),generateWooCommerce.stickyAddToCart&&(m=0,u=300,d(window).on("scroll",t(function(){var t=d("#wpadminbar"),a=d(".navigation-stick"),e=d(".stuckElement"),o=0,s=d(window).scrollTop(),r=d(".add-to-cart-panel"),n=r.offset().top+r.outerHeight(),i=d(".single_add_to_cart_button"),c=i.offset().top,i=i.outerHeight(),l=d(".site-footer").offset().top;0===e.length&&(u=0),c+i<s&&n<l?setTimeout(function(){t.length&&(o=t.outerHeight()),a.length&&(a.hasClass("auto-hide-sticky")?(s<m&&"0px"===a.css("top")&&(o+=a.outerHeight()),m=s):o+=a.outerHeight()),r.addClass("show-sticky-add-to-cart").css({"-webkit-transform":"translateY("+o+"px)","-ms-transform":"translateY("+o+"px)",transform:"translateY("+o+"px)"})},u):r.removeClass("show-sticky-add-to-cart").css({"-webkit-transform":"","-ms-transform":"",transform:""})},50)),d(".go-to-variables").on("click",function(t){t.preventDefault();var t=0,a=d(".navigation-stick"),e=d("#wpadminbar");a.length&&(t=a.outerHeight()),e.length&&(t+=e.outerHeight()),d("html, body").animate({scrollTop:d(".variations").offset().top-t},250)})),d(function(){"use strict";generateWooCommerce.quantityButtons&&a()}),d(document).ajaxComplete(function(){"use strict";generateWooCommerce.quantityButtons&&a()})});
|
Reference in New Issue
Block a user