|
|
@ -24,22 +24,17 @@ function runSimulation(parameters: SimulationParameters): Simulator.SimulationRe |
|
|
|
return simulationResult; |
|
|
|
return simulationResult; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function() { |
|
|
|
function initializeSimulator(container: HTMLElement) { |
|
|
|
// Load CSS
|
|
|
|
|
|
|
|
document.getElementsByTagName('head')[0].innerHTML += (<any>window)['simulator.css']; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let container = document.getElementById('simulator'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Insert HTML code in the container
|
|
|
|
// Insert HTML code in the container
|
|
|
|
container.innerHTML += (<any>window)['simulator.html']; |
|
|
|
container.innerHTML += (<any>window)['simulator.html']; |
|
|
|
|
|
|
|
|
|
|
|
// In order to be able to style SVG elements with CSS, and register events with javascript, we must use inline SVG (we can't use an img tag)
|
|
|
|
// In order to be able to style SVG elements with CSS, and register events with javascript, we must use inline SVG (we can't use an img tag)
|
|
|
|
// For this purpose, the SVG file contents are embedded in a javascript file
|
|
|
|
// For this purpose, the SVG file contents are embedded in a javascript file
|
|
|
|
container.querySelector('#zones-map').innerHTML = (<any>window)['climate-zones-map.svg']; |
|
|
|
container.querySelector('.zones-map').innerHTML = (<any>window)['climate-zones-map.svg']; |
|
|
|
|
|
|
|
|
|
|
|
container.querySelectorAll("[data-activate-modal]").forEach(elt => { |
|
|
|
container.querySelectorAll("[data-activate-modal]").forEach(elt => { |
|
|
|
elt.addEventListener('click', e => { |
|
|
|
elt.addEventListener('click', e => { |
|
|
|
container.querySelector('#'+elt.getAttribute('data-activate-modal')).classList.toggle('is-active', true); |
|
|
|
container.querySelector('.'+elt.getAttribute('data-activate-modal')).classList.toggle('is-active', true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
@ -49,7 +44,7 @@ document.addEventListener('DOMContentLoaded', function() { |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
let zoneSelector = <HTMLSelectElement>container.querySelector('#zone-selector'); |
|
|
|
let zoneSelector = <HTMLSelectElement>container.querySelector('.zone-selector'); |
|
|
|
container.querySelectorAll('.climate-zone').forEach(elt => { |
|
|
|
container.querySelectorAll('.climate-zone').forEach(elt => { |
|
|
|
elt.addEventListener('click', e => { |
|
|
|
elt.addEventListener('click', e => { |
|
|
|
let zoneName = elt.getAttribute('id'); |
|
|
|
let zoneName = elt.getAttribute('id'); |
|
|
@ -58,11 +53,11 @@ document.addEventListener('DOMContentLoaded', function() { |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
container.querySelector('#simulate-button').addEventListener('click', e => { |
|
|
|
container.querySelector('.simulate-button').addEventListener('click', e => { |
|
|
|
let parameters: SimulationParameters = { |
|
|
|
let parameters: SimulationParameters = { |
|
|
|
batteryCapacity: Number((<HTMLInputElement>container.querySelector('[name=battery-capacity]')).value), |
|
|
|
batteryCapacity: Number((<HTMLInputElement>container.querySelector('[name=battery-capacity]')).value), |
|
|
|
additionalWeight: Number((<HTMLInputElement>container.querySelector('[name=additional-weight]')).value), |
|
|
|
additionalWeight: Number((<HTMLInputElement>container.querySelector('[name=additional-weight]')).value), |
|
|
|
climateZone: (<HTMLSelectElement>container.querySelector('#zone-selector')).value, |
|
|
|
climateZone: (<HTMLSelectElement>container.querySelector('.zone-selector')).value, |
|
|
|
dailyDistance: Number((<HTMLInputElement>container.querySelector('[name=daily-distance]')).value), |
|
|
|
dailyDistance: Number((<HTMLInputElement>container.querySelector('[name=daily-distance]')).value), |
|
|
|
dailyAscendingElevation: Number((<HTMLInputElement>container.querySelector('[name=daily-elevation]')).value), |
|
|
|
dailyAscendingElevation: Number((<HTMLInputElement>container.querySelector('[name=daily-elevation]')).value), |
|
|
|
}; |
|
|
|
}; |
|
|
@ -114,4 +109,12 @@ document.addEventListener('DOMContentLoaded', function() { |
|
|
|
|
|
|
|
|
|
|
|
resultsContainer.classList.toggle('is-hidden', false); |
|
|
|
resultsContainer.classList.toggle('is-hidden', false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function() { |
|
|
|
|
|
|
|
// Load CSS
|
|
|
|
|
|
|
|
document.getElementsByTagName('head')[0].innerHTML += (<any>window)['simulator.css']; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let container = document.getElementById('simulator'); |
|
|
|
|
|
|
|
initializeSimulator(container); |
|
|
|
}); |
|
|
|
}); |
|
|
|