updated plugin GP Premium
version 2.0.3
This commit is contained in:
@ -1,25 +1,15 @@
|
||||
jQuery( document ).ready( function( $ ) {
|
||||
var throttle = function(fn, threshhold, scope) {
|
||||
threshhold || (threshhold = 250);
|
||||
var last,
|
||||
deferTimer;
|
||||
jQuery( function( $ ) {
|
||||
var throttle = function( callback, limit ) {
|
||||
var wait = false;
|
||||
|
||||
return function () {
|
||||
var context = scope || this;
|
||||
return function() {
|
||||
if ( ! wait ) {
|
||||
callback.call();
|
||||
wait = true;
|
||||
|
||||
var now = +new Date,
|
||||
args = arguments;
|
||||
|
||||
if (last && now < last + threshhold) {
|
||||
// hold on to it
|
||||
clearTimeout(deferTimer);
|
||||
deferTimer = setTimeout(function () {
|
||||
last = now;
|
||||
fn.apply(context, args);
|
||||
}, threshhold);
|
||||
} else {
|
||||
last = now;
|
||||
fn.apply(context, args);
|
||||
setTimeout( function() {
|
||||
wait = false;
|
||||
}, limit );
|
||||
}
|
||||
};
|
||||
};
|
||||
@ -46,7 +36,7 @@ jQuery( document ).ready( function( $ ) {
|
||||
} );
|
||||
|
||||
if ( generateWooCommerce.addToCartPanel ) {
|
||||
$( document.body ).on( "added_to_cart", function() {
|
||||
$( document.body ).on( 'added_to_cart', function() {
|
||||
var adminBar = $( '#wpadminbar' ),
|
||||
stickyNav = $( '.navigation-stick' ),
|
||||
top = 0;
|
||||
@ -62,7 +52,7 @@ jQuery( document ).ready( function( $ ) {
|
||||
$( '.add-to-cart-panel' ).addClass( 'item-added' ).css( {
|
||||
'-webkit-transform': 'translateY(' + top + 'px)',
|
||||
'-ms-transform': 'translateY(' + top + 'px)',
|
||||
'transform': 'translateY(' + top + 'px)'
|
||||
transform: 'translateY(' + top + 'px)',
|
||||
} );
|
||||
} );
|
||||
|
||||
@ -72,7 +62,7 @@ jQuery( document ).ready( function( $ ) {
|
||||
$( '.add-to-cart-panel' ).removeClass( 'item-added' ).css( {
|
||||
'-webkit-transform': 'translateY(-100%)',
|
||||
'-ms-transform': 'translateY(-100%)',
|
||||
'transform': 'translateY(-100%)'
|
||||
transform: 'translateY(-100%)',
|
||||
} );
|
||||
} );
|
||||
|
||||
@ -83,7 +73,7 @@ jQuery( document ).ready( function( $ ) {
|
||||
panel.removeClass( 'item-added' ).css( {
|
||||
'-webkit-transform': 'translateY(-100%)',
|
||||
'-ms-transform': 'translateY(-100%)',
|
||||
'transform': 'translateY(-100%)'
|
||||
transform: 'translateY(-100%)',
|
||||
} );
|
||||
}
|
||||
}, 250 ) );
|
||||
@ -91,6 +81,7 @@ jQuery( document ).ready( function( $ ) {
|
||||
|
||||
if ( generateWooCommerce.stickyAddToCart ) {
|
||||
var lastScroll = 0;
|
||||
|
||||
$( window ).on( 'scroll', throttle( function() {
|
||||
var adminBar = $( '#wpadminbar' ),
|
||||
stickyNav = $( '.navigation-stick' ),
|
||||
@ -125,13 +116,13 @@ jQuery( document ).ready( function( $ ) {
|
||||
panel.addClass( 'show-sticky-add-to-cart' ).css( {
|
||||
'-webkit-transform': 'translateY(' + top + 'px)',
|
||||
'-ms-transform': 'translateY(' + top + 'px)',
|
||||
'transform': 'translateY(' + top + 'px)'
|
||||
transform: 'translateY(' + top + 'px)',
|
||||
} );
|
||||
} else {
|
||||
} else {
|
||||
panel.removeClass( 'show-sticky-add-to-cart' ).css( {
|
||||
'-webkit-transform': '',
|
||||
'-ms-transform': '',
|
||||
'transform': ''
|
||||
transform: '',
|
||||
} );
|
||||
}
|
||||
}, 250 ) );
|
||||
@ -151,14 +142,14 @@ jQuery( document ).ready( function( $ ) {
|
||||
offset = offset + adminBar.outerHeight();
|
||||
}
|
||||
|
||||
$( 'html, body' ).animate({
|
||||
scrollTop: $( '.variations' ).offset().top - offset
|
||||
$( 'html, body' ).animate( {
|
||||
scrollTop: $( '.variations' ).offset().top - offset,
|
||||
}, 250 );
|
||||
} );
|
||||
}
|
||||
|
||||
$( function() {
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
if ( generateWooCommerce.quantityButtons ) {
|
||||
generateQuantityButtons();
|
||||
@ -166,7 +157,7 @@ jQuery( document ).ready( function( $ ) {
|
||||
} );
|
||||
|
||||
$( document ).ajaxComplete( function() {
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
if ( generateWooCommerce.quantityButtons ) {
|
||||
generateQuantityButtons();
|
||||
@ -174,104 +165,115 @@ jQuery( document ).ready( function( $ ) {
|
||||
} );
|
||||
|
||||
function generateQuantityButtons() {
|
||||
var quantityBoxes,
|
||||
cart = $( '.woocommerce div.product form.cart' );
|
||||
// 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;
|
||||
}
|
||||
|
||||
quantityBoxes = $( '.cart div.quantity:not(.buttons-added), .cart td.quantity:not(.buttons-added)' ).find( '.qty' );
|
||||
// Grab all the quantity boxes that need dynamic buttons adding
|
||||
var quantityBoxes;
|
||||
|
||||
if ( quantityBoxes ) {
|
||||
$.each( quantityBoxes, function( key, value ) {
|
||||
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 );
|
||||
|
||||
if ( 'date' !== box.prop( 'type' ) && 'hidden' !== box.prop( 'type' ) ) {
|
||||
// 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>');
|
||||
// Check allowed types
|
||||
if ( [ 'date', 'hidden' ].indexOf( box.prop( 'type' ) ) !== -1 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Target quantity inputs on product pages
|
||||
$( 'input.qty:not(.product-quantity input.qty)' ).each( function() {
|
||||
var min = parseFloat( $( this ).attr( 'min' ) );
|
||||
// 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>' );
|
||||
|
||||
if ( min && min > 0 && parseFloat( $( this ).val() ) < min ) {
|
||||
$( this ).val( min );
|
||||
}
|
||||
} );
|
||||
// Enforce min value on the input
|
||||
var min = parseFloat( $( this ).attr( 'min' ) );
|
||||
|
||||
// Quantity input
|
||||
if ( $( 'body' ).hasClass( 'single-product' ) && ! cart.hasClass( 'grouped_form' ) ) {
|
||||
var quantityInput = $( '.woocommerce form input[type=number].qty' );
|
||||
if ( min && min > 0 && parseFloat( $( this ).val() ) < min ) {
|
||||
$( this ).val( min );
|
||||
}
|
||||
|
||||
quantityInput.on( 'keyup', function() {
|
||||
var qty_val = $( this ).val();
|
||||
quantityInput.val( qty_val );
|
||||
} );
|
||||
// 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;
|
||||
}
|
||||
|
||||
$( '.plus, .minus' ).off( 'click' );
|
||||
if ( '' === maxQuantity || 'NaN' === maxQuantity ) {
|
||||
maxQuantity = '';
|
||||
}
|
||||
|
||||
$( '.plus, .minus' ).on( 'click', function() {
|
||||
// Quantity
|
||||
var quantityBox;
|
||||
if ( '' === minQuantity || 'NaN' === minQuantity ) {
|
||||
minQuantity = 0;
|
||||
}
|
||||
|
||||
// If floating bar is enabled
|
||||
if ( $( 'body' ).hasClass( 'single-product' ) && ! cart.hasClass( 'grouped_form' ) && ! cart.hasClass( 'cart_group' ) ) {
|
||||
quantityBox = $( '.plus, .minus' ).closest( '.quantity' ).find( '.qty' );
|
||||
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 {
|
||||
quantityBox = $( this ).closest( '.quantity' ).find( '.qty' );
|
||||
box.val( currentQuantity + parseFloat( step ) );
|
||||
}
|
||||
} else if ( minQuantity && ( minQuantity === currentQuantity || currentQuantity < minQuantity ) ) {
|
||||
box.val( minQuantity );
|
||||
} else if ( currentQuantity > 0 ) {
|
||||
box.val( currentQuantity - parseFloat( step ) );
|
||||
}
|
||||
|
||||
// Get values
|
||||
var currentQuantity = parseFloat( quantityBox.val() ),
|
||||
maxQuantity = parseFloat( quantityBox.attr( 'max' ) ),
|
||||
minQuantity = parseFloat( quantityBox.attr( 'min' ) ),
|
||||
step = quantityBox.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;
|
||||
}
|
||||
|
||||
// Change the value
|
||||
if ( $( this ).is( '.plus' ) ) {
|
||||
|
||||
if ( maxQuantity && ( maxQuantity == currentQuantity || currentQuantity > maxQuantity ) ) {
|
||||
quantityBox.val( maxQuantity );
|
||||
} else {
|
||||
quantityBox.val( currentQuantity + parseFloat( step ) );
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if ( minQuantity && ( minQuantity == currentQuantity || currentQuantity < minQuantity ) ) {
|
||||
quantityBox.val( minQuantity );
|
||||
} else if ( currentQuantity > 0 ) {
|
||||
quantityBox.val( currentQuantity - parseFloat( step ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Trigger change event
|
||||
quantityBox.trigger( 'change' );
|
||||
} );
|
||||
}
|
||||
} );
|
||||
// Trigger change event
|
||||
box.trigger( 'change' );
|
||||
} );
|
||||
};
|
||||
}
|
||||
|
||||
$.each( quantityBoxes, quantityBoxesCallback );
|
||||
}
|
||||
});
|
||||
} );
|
||||
|
Reference in New Issue
Block a user