{"size": 1602, "ext": "js", "max_stars_repo_path": "assets/scripts/wc-quantity-increments.js", "max_stars_repo_name": "WPVillain/ianua", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assets/scripts/wc-quantity-increments.js", "max_issues_repo_name": "WPVillain/ianua", "max_issues_repo_issues_event_min_datetime": "2022-02-12T11:28:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-12T11:28:56.000Z", "max_forks_repo_path": "assets/scripts/wc-quantity-increments.js", "max_forks_repo_name": "WPVillain/ianua", "max_forks_repo_forks_event_min_datetime": "2021-08-19T22:27:02.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-19T22:27:02.000Z"}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": 1, "avg_line_length": 29.6666666667, "max_line_length": 223, "alphanum_fraction": 0.5436953808}
( function( $ ) {
	'use strict';

	function wcQuantityIncrementPrepend() {
		$( 'div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)' ).addClass( 'buttons_added' ).append( '<input type="button" value="+" class="plus" />' ).prepend( '<input type="button" value="-" class="minus" />' );
	}
	wcQuantityIncrementPrepend();

	$( document ).on( 'click', '.plus, .minus', function() {

		// Get values
		var $qty		= $( this ).closest( '.quantity' ).find( '.qty' ),
			currentVal	= parseFloat( $qty.val() ),
			max			= parseFloat( $qty.attr( 'max' ) ),
			min			= parseFloat( $qty.attr( 'min' ) ),
			step		= $qty.attr( 'step' );

		// Format values
		if ( ! currentVal || currentVal === '' || currentVal === 'NaN' ) {currentVal = 0;}
		if ( max === '' || max === 'NaN' ) {max = '';}
		if ( min === '' || min === 'NaN' ) {min = 0;}
		if ( step === 'any' || step === '' || step === undefined || parseFloat( step ) === 'NaN' ) {step = 1;}

		// Change the value
		if ( $( this ).is( '.plus' ) ) {

			if ( max && ( max === currentVal || currentVal > max ) ) {
				$qty.val( max );
			} else {
				console.log( currentVal );
				$qty.val( currentVal + parseFloat( step ) );
			}

		} else {

			if ( min && ( min === currentVal || currentVal < min ) ) {
				$qty.val( min );
			} else if ( currentVal > 0 ) {
				console.log( currentVal );
				$qty.val( currentVal - parseFloat( step ) );
			}

		}

		// Trigger change event
		$qty.trigger( 'change' );

	});

	// Run on cart update
	$( document.body ).on( 'updated_wc_div', function( event ) {
		wcQuantityIncrementPrepend();
	} );
} ( jQuery ) );