$(document).ready(function () { window.getUrlParameter = function getUrlParameter(sParam) { var sPageURL = decodeURIComponent(window.location.search.substring(1)), sURLVariables = sPageURL.split('&'), sParameterName, i; for (i = 0; i < sURLVariables.length; i++) { sParameterName = sURLVariables[i].split('='); if (sParameterName[0] === sParam) { return sParameterName[1] === undefined ? true : sParameterName[1]; } } }; // //$('#pnlExistingPlant input[name="numberOfPersons"]').val(); var sliderEnergyDemandByNumberOfPersonsNumberOfPersons = $('#pnlEnergyDemandByNumberOfPersons .slider').get(0); noUiSlider.create(sliderEnergyDemandByNumberOfPersonsNumberOfPersons, { animate: false, start: [2], range: { 'min': 1, 'max': 6 }, step: 1, pips: { // mode: 'count', // values: 6, // density: 4, // stepped: true mode: 'values', values: ['1', '2', '3', '4', '5', '6'], density: 4, stepped: true } }); sliderEnergyDemandByNumberOfPersonsNumberOfPersons.noUiSlider.on('update', function (values, handle, unencoded, tap, positions) { // values: Current slider values; // handle: Handle that caused the event; // unencoded: Slider values without formatting; // tap: Event was caused by the user tapping the slider (boolean); // positions: Left offset of the handles in relation to the slider // console.log(parseInt(values[0])); var numberOfPersons = parseInt(values[0]); var url = $('#pnlEnergyDemandByNumberOfPersons img.numberOfPersons').attr('src'); var fileName = url.split('/').pop(); var path = url.substr(0, url.length - fileName.length); $('#pnlEnergyDemandByNumberOfPersons img.numberOfPersons').attr('src', path + 'persons-' + numberOfPersons + '.png'); // $('#pnlEnergyDemandByNumberOfPersons img.numberOfPersons').attr('src', '/assets/frontend/customer/1/persons-' + numberOfPersons + '.png'); // $('#pnlEnergyDemandByNumberOfPersons .area .degree').html(value + '°'); $('#pnlEnergyDemandByNumberOfPersons input[name="numberOfPersons"]').val(numberOfPersons); // ajax $.ajax({ url: 'plugin/top50solar/common/enterEnergyDemandByNumberOfPersons/ajax?key=' + getUrlParameter('key'), // ?method=checkZipCode&zipCode=' + zipCode, //context: document.body, context: $(this), headers: { 'Accept': 'application/json' }, method: 'POST', data: { method: 'calculateEnergyDemand', numberOfPersons: numberOfPersons } }).done(function (data) { // update input field var energyDemand = parseInt(data) / 1000; // convert to kWh $('#pnlEnergyDemandByNumberOfPersons input[name=annualPowerConsumption]').val(energyDemand); }); }); var getEnergyDemand = function (numberOfPersons) { $.ajax({ url: 'plugin/top50solar/common/enterEnergyDemandByNumberOfPersons/ajax?key=' + getUrlParameter('key'), context: $(this), headers: { 'Accept': 'application/json' }, method: 'POST', data: { method: 'calculateEnergyDemand', numberOfPersons: numberOfPersons } }).done(function (data) { // update input field var energyDemand = parseInt(data) / 1000; // convert to kWh $('#pnlEnergyDemandByNumberOfPersons input[name=annualPowerConsumption]').val(energyDemand); }); }; $('#pnlEnergyDemandByNumberOfPersons .slider .noUi-value').bind('click', function () { var value = parseInt($(this).text()); sliderEnergyDemandByNumberOfPersonsNumberOfPersons.noUiSlider.set(value); }); });