// JavaScript Document var keypressSlider = document.getElementById('keypress'); var input0 = document.getElementById('input-with-keypress-0'); var input1 = document.getElementById('input-with-keypress-1'); var inputs = [input0, input1]; var minimo = 17.65; var maximo = 57.6; if (typeof(sessionStorage.ver_producto) != "undefined" && typeof(sessionStorage.ver_arti) != "undefined") { if (sessionStorage.ver_producto.indexOf(sessionStorage.ver_arti)> 0) { //console.log("por aki --"+ sessionStorage.ver_precio_0+"- "+sessionStorage.precio_0 +" - "+sessionStorage.precio_0 +" - "+typeof(sessionStorage.precio_0)); if (sessionStorage.ver_precio_0 != "" && sessionStorage.ver_precio_0 != "undefined" && typeof(sessionStorage.ver_precio_0) != "undefined") {minimo = sessionStorage.ver_precio_0;} if (sessionStorage.ver_precio_1 != "" && sessionStorage.ver_precio_1 != "undefined" && typeof(sessionStorage.ver_precio_1) != "undefined") maximo = sessionStorage.ver_precio_1; } } noUiSlider.create(keypressSlider, { start: [minimo, maximo], connect: true, range: { 'min': 17.65, 'max': 57.6 } }); keypressSlider.noUiSlider.on('update', function( values, handle ) { inputs[handle].value = values[handle]; }); keypressSlider.noUiSlider.on('set', function(values, handle){ recarga_resultados(); //console.log("cambiado----"+handle+": "+values[handle]); // eval("window.precio_"+handle+" = "+ values[handle]); }); function updateSliderRange ( min, max ) { keypressSlider.noUiSlider.updateOptions({ range: { 'min': min, 'max': max } }); } function setSliderHandle(i, value) { var r = [null,null]; r[i] = value; keypressSlider.noUiSlider.set(r); } // Listen to keydown events on the input field. inputs.forEach(function(input, handle) { input.addEventListener('change', function(){ setSliderHandle(handle, this.value); }); input.addEventListener('keydown', function( e ) { var values = keypressSlider.noUiSlider.get(); var value = Number(values[handle]); // [[handle0_down, handle0_up], [handle1_down, handle1_up]] var steps = keypressSlider.noUiSlider.steps(); // [down, up] var step = steps[handle]; var position; // 13 is enter, // 38 is key up, // 40 is key down. switch ( e.which ) { case 13: setSliderHandle(handle, this.value); break; case 38: // Get step to go increase slider value (up) position = step[1]; // false = no step is set if ( position === false ) { position = 1; } // null = edge of slider if ( position !== null ) { setSliderHandle(handle, value + position); } break; case 40: position = step[0]; if ( position === false ) { position = 1; } if ( position !== null ) { setSliderHandle(handle, value - position); } break; } }); });