<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">// Setup

var debug = true;
var minLength = "1";
var maxLength = "100";

$(document).ready(function() {

	// Options styling 
	
	$('#fabric-length').wrap('&lt;div class="card border-top"&gt;&lt;div class="card-body"&gt;&lt;/div&gt;&lt;/div&gt;');
	$('#fabric-length .control-label').html($('#fabric-length .control-label').html().replace('*', '(metres) *'));
	$('#fabric-length').append("&lt;small&gt;Min: " + minLength + "m, Max: " + maxLength + "m.&lt;/small&gt;");

	$('#fabric-unit').find('.checkbox').addClass('checked').find('input').prop('checked', 'checked');

	// Run the calculate price script on button click

	$( "#calculate-price" ).click(function() {
	    calculateFabricPrice(pricing);
	});

	// Submit on return

	$( "#product-options input" ).keypress(function (e) {
		if (e.which == 13) {
			calculateFabricPrice(pricing);
			return false;
		}
	});

	// Handle the options before adding to basket

	$( "#custom-button-cart" ).click(function() {
		calculateFabricPrice(pricing);
		controlOptions(pricing);
		$('#button-cart').click();
		$('#calculate-reset').show();
		$('#calculate-price').hide();
		resetPage();
	});


	// // // Calculate the fabric prices // // //

	function calculateFabricPrice(pricing) {

		// Hide the product pricing area 

		$( "#product-pricing" ).hide();

		// Get the fabric Size

		var size = {
		    length : Number( $( "#fabric-length input" ).val().replace(/[^\d.-]/g, '') ),
		};
		console.log(size);

		// Form Validation

		$( "#product-options .form-group" ).removeClass('invalid');

		var valid = true;

		if ( size.length &gt; maxLength || size.length &lt; minLength ) {
			$( "#fabric-length" ).addClass('invalid');
			valid = false;
		}

		if ( valid ) {

			$( ".form-group-calculate" ).hide();
			$( '#calculation-alert' ).html('');

			// Set the fabric variables from product attributes 

			var fabric = {
			    fabricWidth : attributes.fabricWidth,
			    patternRepeat : attributes.patternRepeat,
			    fabricPrice : attributes.fabricPrice,
			};

			// // // Calculate the number of fabric units // // //

			// Get the unit price and quantities from the attributes

			pricing.unitPrice = $('#fabric-unit .option_price').html().replace('Â£', '');
			pricing.unitQuantity = Math.ceil( size.length * 2 );

			// Calculate the total price for customer

			pricing.totalPrice = (pricing.unitPrice * pricing.unitQuantity).toFixed(2);

			// Update the product page with pricing information

			$( "#unitQuantity" ).html(pricing.unitQuantity);
			$( "#unitPrice" ).html(pricing.unitPrice);
			$( "#input-unit-quantity" ).val(pricing.unitQuantity);


			// If fabric discounted calculate and show price before discount
			pricing.totalDiscount = 0;
			if ( attributes.discount ){
				pricing.priceBeforeDiscount = (pricing.totalPrice / ( ( 100 - attributes.discount ) / 100 ) ).toFixed(2);
				pricing.totalDiscount = parseFloat(pricing.totalDiscount) + parseFloat(pricing.priceBeforeDiscount - pricing.totalPrice);
			}else{
				pricing.priceBeforeDiscount = parseFloat(pricing.totalPrice).toFixed(2);
			}

			// Apply total discounts

			if (pricing.totalDiscount &gt; 0) {
				$( "#totalPriceBeforeDiscount" ).html("Was: &lt;span class=\"c-contrast line-through\"&gt;&amp;pound;" + pricing.priceBeforeDiscount + "&lt;/span&gt;");
				pricing.totalPrice = (pricing.priceBeforeDiscount - pricing.totalDiscount).toFixed(2);
				$( "#totalDiscount" ).html( parseFloat(pricing.totalDiscount).toFixed(2) );
				$( "#product-discount" ).show();
				var totalPriceText = "Now: &amp;pound;" + pricing.totalPrice;
			}else{
				$( "#totalDiscount" ).html("");
				$( "#totalPriceBeforeDiscount" ).html("");
				var totalPriceText = "Our Price: &amp;pound;" + pricing.totalPrice;
			}

			$( "#totalPrice" ).html(totalPriceText);



			// Reveal the product pricing area 

			if ( pricing.totalPrice &gt; 5 &amp;&amp; pricing.totalPrice != "NaN" ){
				$( "#product-pricing" ).show();

				// Setup Worksheet Data
				worksheet.fabricLength = size.length;
				worksheet.totalFabricPrice = pricing.totalPrice;
				$( "#worksheet textarea" ).val(JSON.stringify(worksheet));
				
			}
			if (debug) { console.log(pricing); }
			if (debug) { console.log(attributes); }

		}else{
			$( '#calculation-alert' ).html('&lt;p class="c-danger"&gt;&lt;i class="fa fa-exclamation-triangle"&gt;&lt;/i&gt; There is a problem with your order, please try again.&lt;/p&gt;');
			if (debug) { console.log(pricing); }
		}

	}

	function controlOptions(pricing) {
		// Clear the cloned checkboxes then add in the checkboxes according to current sizes
		$( ".checkbox.clone" ).remove();
		var i;
		// Fabric unit checkboxes
		for (i = 1; i &lt; pricing.unitQuantity; i++) {
			var checked = $( "#fabric-unit .checkbox.checked" );
			$( checked ).clone().insertAfter( checked ).removeClass('checked').addClass('clone');
		}
	}

});</pre></body></html>