File: D:/HostingSpaces/SBogers10/zelfverkopen.komma.pro/resources/assets/js/site/profitCalculator.js
var ProfitCalculator = {
// Slider settings
sliderObject: '',
slider: '',
fillOut: '',
marker: '',
valuePlaceholder: '',
inputField: '',
value: 350000,
valuePercentage: 0.35,
minValue: 100000,
maxValue: 1000000,
// Pricing settings
pricingObject: '',
priceEstateAgentPercentage: 0.0165,
btwPercentage: 1.21,
zelfverkopenPrice: 1098,
priceEstateAgent: 5690,
init : function()
{
ProfitCalculator.sliderObject = document.getElementById("calculatorSlider");
ProfitCalculator.pricingObject = document.getElementById("profitPricing");
if( isset(ProfitCalculator.sliderObject) ){
ProfitCalculator.slider = ProfitCalculator.sliderObject.querySelector('.slider');
ProfitCalculator.fillOut = ProfitCalculator.sliderObject.querySelector(".fill-out span");
ProfitCalculator.marker = ProfitCalculator.sliderObject.querySelector(".marker");
ProfitCalculator.inputField = ProfitCalculator.sliderObject.querySelector("#house-price");
ProfitCalculator.valuePlaceholder = ProfitCalculator.sliderObject.querySelector(".tooltip .estimated-value .value-placeholder");
ProfitCalculator.value = parseInt(ProfitCalculator.slider.value);
ProfitCalculator.minValue = parseInt(ProfitCalculator.slider.min);
ProfitCalculator.maxValue = parseInt(ProfitCalculator.slider.max);
ProfitCalculator.updateValue();
if(document.querySelector('html').classList.contains('ie')){
var stepSlider = document.getElementById('slider-step');
noUiSlider.create(stepSlider, {
start: [ ProfitCalculator.value ],
step: 5000,
range: {
'min': [ ProfitCalculator.minValue ],
'max': [ ProfitCalculator.maxValue ]
}
});
stepSlider.noUiSlider.on('update', function( values, handle ) {
ProfitCalculator.updateValueIe(parseInt(values[handle]));
});
}
ProfitCalculator.slider.oninput = function () {
ProfitCalculator.updateValue();
};
var submitButton = ProfitCalculator.sliderObject.querySelector('.calculate-button');
submitButton.addEventListener('click', function () {
ProfitCalculator.sliderObject.querySelector('form').submit();
});
}
},
updateValue: function () {
// Update values based upon the value
ProfitCalculator.value = ProfitCalculator.slider.value;
ProfitCalculator.valuePercentage = (ProfitCalculator.value - ProfitCalculator.minValue) / (ProfitCalculator.maxValue - ProfitCalculator.minValue);
// Update hidden input field
ProfitCalculator.inputField.value = ProfitCalculator.value;
// Convert value to percentage and update styling
ProfitCalculator.fillOut.style.width = (ProfitCalculator.valuePercentage * 100) + '%';
ProfitCalculator.marker.style.left = (ProfitCalculator.valuePercentage * 100) + '%';
// Convert value to visual pricing
var showNumber = ProfitCalculator.numberWithSeperator(ProfitCalculator.value, '.');
ProfitCalculator.valuePlaceholder.setAttribute('data-value', (showNumber + ',-'));
//Calculated Estate agent pricing
ProfitCalculator.priceEstateAgent = ProfitCalculator.value * ( ProfitCalculator.priceEstateAgentPercentage * ProfitCalculator.btwPercentage );
ProfitCalculator.updatePricing();
},
updateValueIe: function (sliderValue){
ProfitCalculator.value = sliderValue;
ProfitCalculator.inputField.value = sliderValue;
// Convert value to visual pricing
var showNumber = ProfitCalculator.numberWithSeperator(ProfitCalculator.value, '.');
ProfitCalculator.valuePlaceholder.setAttribute('data-value', (showNumber + ',-'));
//Calculated Estate agent pricing
ProfitCalculator.priceEstateAgent = ProfitCalculator.value * ( ProfitCalculator.priceEstateAgentPercentage * ProfitCalculator.btwPercentage );
ProfitCalculator.updatePricing();
},
updatePricing: function(){
// Check if pricing object is defined
if( isset(ProfitCalculator.pricingObject) ){
var estateAgentPricingObject = ProfitCalculator.pricingObject.querySelector('#estateAgentPrice');
var yourProfitObject = ProfitCalculator.pricingObject.querySelector('#profitPrice');
// Also check if the to be changed object are defined
if( isset(estateAgentPricingObject) && isset(yourProfitObject) ){
var priceEstateAgent = ProfitCalculator.priceEstateAgent.toFixed(2).toString().replace('.', ',');
var profitValue = (ProfitCalculator.priceEstateAgent - ProfitCalculator.zelfverkopenPrice).toFixed(2);
profitValue = profitValue.toString().replace('.', ',');
if(priceEstateAgent.substr(priceEstateAgent.length - 3) === ',00') priceEstateAgent = priceEstateAgent.replace(',00', ',-');
if(profitValue.substr(profitValue.length - 3) === ',00') profitValue = profitValue.replace(',00', ',-');
estateAgentPricingObject.setAttribute('data-value', (ProfitCalculator.numberWithSeperator(priceEstateAgent, '.')));
yourProfitObject.setAttribute('data-value', ProfitCalculator.numberWithSeperator(profitValue, '.'));
}
}
},
numberWithSeperator: function(x, seperator) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, seperator);
}
};
ProfitCalculator.init();