PageSourceSearch

https://www.gresb.com/wp-content/themes/framework/assets/js/components/_1_number-input.js?ver=1790907545

js gresb.com collected 2026-10-02 02:38:13 UTC 2,511 bytes, 66 lines download raw bytes

1// File#: _1_number-input
2// Usage: codyhouse.co/license
3(function() {
4	var InputNumber = function(element) {
5		this.element = element;
6		this.input = this.element.getElementsByClassName('js-number-input__value')[0];
7		this.min = parseFloat(this.input.getAttribute('min'));
8		this.max = parseFloat(this.input.getAttribute('max'));
9		this.step = parseFloat(this.input.getAttribute('step'));
10		if(isNaN(this.step)) this.step = 1;
11		this.precision = getStepPrecision(this.step);
12		initInputNumberEvents(this);
13	};
14
15	function initInputNumberEvents(input) {
16		// listen to the click event on the custom increment buttons
17		input.element.addEventListener('click', function(event){ 
18			var increment = event.target.closest('.js-number-input__btn');
19			if(increment) {
20				event.preventDefault();
21				updateInputNumber(input, increment);
22			}
23		});
24
25		// when input changes, make sure the new value is acceptable
26		input.input.addEventListener('focusout', function(event){
27			var value = parseFloat(input.input.value);
28			if( value < input.min ) value = input.min;
29			if( value > input.max ) value = input.max;
30			// check value is multiple of step
31			value = checkIsMultipleStep(input, value);
32			if( value != parseFloat(input.input.value)) input.input.value = value;
33
34		});
35	};
36
37	function getStepPrecision(step) {
38		// if step is a floating number, return its precision
39		return (step.toString().length - Math.floor(step).toString().length - 1);
40	};
41
42	function updateInputNumber(input, btn) {
43		var value = ( Util.hasClass(btn, 'number-input__btn--plus') ) ? parseFloat(input.input.value) + input.step : parseFloat(input.input.value) - input.step;
44		if( input.precision > 0 ) value = value.toFixed(input.precision);
45		if( value < input.min ) value = input.min;
46		if( value > input.max ) value = input.max;
47		input.input.value = value;
48		input.input.dispatchEvent(new CustomEvent('change', {bubbles: true})); // trigger change event
49	};
50
51	function checkIsMultipleStep(input, value) {
52		// check if the number inserted is a multiple of the step value
53		var remain = (value*10*input.precision)%(input.step*10*input.precision);
54		if( remain != 0) value = value - remain;
55		if( input.precision > 0 ) value = value.toFixed(input.precision);
56		return value;
57	};
58
59	//initialize the InputNumber objects
60	var inputNumbers = document.getElementsByClassName('js-number-input');
61	if( inputNumbers.length > 0 ) {
62		for( var i = 0; i < inputNumbers.length; i++) {
63			(function(i){new InputNumber(inputNumbers[i]);})(i);
64		}
65	}
66}());

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.