Skip to content

Commit

Permalink
added many features and bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gine committed Jan 29, 2017
1 parent 751c2f6 commit 25db86f
Show file tree
Hide file tree
Showing 14 changed files with 1,289 additions and 857 deletions.
Empty file modified assets/css/styles.css
100644 → 100755
Empty file.
50 changes: 25 additions & 25 deletions assets/js/ipq_input_value_validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jQuery(document).ready( function($) {

/*
* Quantity Rule Validation
*
* If user enters a value that is out of bounds,
*
* If user enters a value that is out of bounds,
* it will be auto corrected to a valid value.
*/
*/
$(document).on('change', '.qty', function(e) {
var $input = $(e.currentTarget);
// Get values from input box
Expand All @@ -32,84 +32,84 @@ jQuery(document).ready( function($) {

return parseInt(mult);
};

// Adjust default values if values are blank
if ( min == '' || typeof min == 'undefined' )
if ( min == '' || typeof min == 'undefined' )
min = 1;
if ( step == '' || typeof step == 'undefined')

if ( step == '' || typeof step == 'undefined')
step = 1;

// Max Value Validation
if ( +new_qty > +max && max != '' ) {
new_qty = max;

// Min Value Validation
} else if ( +new_qty < +min && min != '' ) {
new_qty = min;
}

// Calculate remainder
step = step * multiplier();
new_qty = new_qty * multiplier();
min = min * multiplier();
max = max* multiplier();

var rem = ( new_qty - min ) % step;

// Step Value Value Validation
if ( rem != 0 ) {
new_qty = +new_qty + (+step - +rem);

// Max Value Validation
if ( +new_qty > +max ) {
new_qty = +new_qty - +step;
}
}

// Set the new value
$input.val( (new_qty/multiplier()).toFixed(stepOrig.getDecimals()) );
});

/*
* Make sure minimum equals value
* To Fix: when min = 0 and val = 1
* Make sure minimum equals value
* To Fix: when min = 0 and val = 1
*/
if ( $("body.single-product .qty").val() != $("body.single-product .qty").attr('min') && $("body.single-product .qty").attr('min') != '' ) {
$("body.single-product .qty").val( $("body.single-product .qty").attr('min') );
}

/*
* Variable Product Support
*
*
* Need to overwrite what WC changes with their js
*/

// Get localized Variables
if ( typeof ipq_validation !== 'undefined' ) {
var start_min = ipq_validation.min;
var start_max = ipq_validation.max;
var start_step = ipq_validation.step;
}

// Update input box after variaiton selects are blured
$('.variations select').bind('blur',function() {

// Update min
if ( start_min != $('.qty').attr('min') && start_min != '' ) {
$('.qty').attr('min', start_min );
}

// Update max
if ( start_max != $('.qty').attr('max') && start_max != '' ) {
$('.qty').attr('max', start_max );
}

// Update step
if ( start_step != $('.qty').attr('step') && start_step != '' ) {
$('.qty').attr('step', start_step );
}

// Make sure intput value is in bounds
if ( start_min > $('.qty').attr('value') && start_min != '' ) {
$('.qty').attr('value', start_min );
Expand Down
Loading

0 comments on commit 25db86f

Please sign in to comment.