Staging
This commit is contained in:
33
frontend/logbook.ts
Normal file
33
frontend/logbook.ts
Normal file
@ -0,0 +1,33 @@
|
||||
/*document.addEventListener('DOMContentLoaded', function() {
|
||||
setDistance('.set-distance-js');
|
||||
});
|
||||
|
||||
function setDistance(selector: string) {
|
||||
const fields = document.querySelectorAll(selector);
|
||||
if(fields) {
|
||||
Array.prototype.forEach.call(fields, (field: HTMLInputElement) => {
|
||||
if(field.dataset.relation){
|
||||
const relatedField = <HTMLInputElement>document.getElementById(field.dataset.relation);
|
||||
|
||||
if(relatedField) {
|
||||
field.addEventListener('input', (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
const dataList = <HTMLDataListElement>document.getElementById('destinations');
|
||||
if(dataList) {
|
||||
var option = Array.prototype.find.call(dataList.options, function(option) {
|
||||
return option.value === field.value;
|
||||
});
|
||||
|
||||
// Get distance
|
||||
const distance = option.getAttribute('distance');
|
||||
if(distance) relatedField.value = distance;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
*/
|
||||
export {}
|
@ -202,9 +202,22 @@ function initTripSidebar(triggerElement: HTMLElement) {
|
||||
}
|
||||
});
|
||||
|
||||
const prefixedContent = <NodeListOf<HTMLElement>>bodyElement.querySelectorAll('.change-id-js');
|
||||
Array.prototype.forEach.call(prefixedContent, (content: HTMLElement) => {
|
||||
if(content) {
|
||||
content.id += 'js';
|
||||
|
||||
if(content.dataset.relation){
|
||||
content.dataset.relation += 'js';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if(bodyContainerElement) {
|
||||
bodyContainerElement.innerHTML = '';
|
||||
bodyContainerElement.append(bodyElement);
|
||||
|
||||
addRelationMagic(bodyElement);
|
||||
}
|
||||
if(triggerElement.dataset.day) {
|
||||
let hiddenElement = <HTMLInputElement>bodyElement.querySelector('.day-js');
|
||||
@ -220,6 +233,33 @@ function initTripSidebar(triggerElement: HTMLElement) {
|
||||
}
|
||||
}
|
||||
|
||||
function addRelationMagic(bodyElement: HTMLElement) {
|
||||
const fields = bodyElement.querySelectorAll('.set-distance-js');
|
||||
if(fields) {
|
||||
Array.prototype.forEach.call(fields, (field: HTMLInputElement) => {
|
||||
if(field.dataset.relation){
|
||||
const relatedField = <HTMLInputElement>bodyElement.querySelector('#' + field.dataset.relation);
|
||||
|
||||
if(relatedField) {
|
||||
field.addEventListener('input', (e) => {
|
||||
e.preventDefault();
|
||||
const dataList = <HTMLDataListElement>document.getElementById('destinations');
|
||||
if(dataList) {
|
||||
var option = Array.prototype.find.call(dataList.options, function(option) {
|
||||
return option.value === field.value;
|
||||
});
|
||||
|
||||
// Get distance
|
||||
const distance = option.getAttribute('distance');
|
||||
if(distance) relatedField.value = distance;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function replaceStrings() {
|
||||
const weekdays = document.querySelectorAll('.weekday-js');
|
||||
Array.prototype.forEach.call(weekdays, (weekday: HTMLElement) => {
|
||||
|
@ -17,6 +17,7 @@ export default defineConfig({
|
||||
rollupOptions: {
|
||||
input: {
|
||||
main: './main.ts',
|
||||
logbook: './logbook.ts',
|
||||
// Example for more entry points
|
||||
// test: './src/test.ts',
|
||||
},
|
||||
|
Reference in New Issue
Block a user