Skip to content

Commit bfef096

Browse files
yarn encore dev broke on TypeScript content in signup.js.
1 parent 399f166 commit bfef096

File tree

1 file changed

+57
-46
lines changed

1 file changed

+57
-46
lines changed

assets/js/signup.js

+57-46
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
1-
import VanillaCalendar, { Options, FormatDateString } from 'vanilla-calendar-pro';
1+
import VanillaCalendar from 'vanilla-calendar-pro';
22
import 'vanilla-calendar-pro/build/vanilla-calendar.min.css';
33
import * as dayjs from 'dayjs'
44

5+
import 'leaflet';
6+
import 'leaflet/dist/leaflet.css';
57
import {initializeSingleAutoComplete} from './suggest/locations';
6-
import * as L from 'leaflet';
7-
88
import 'leaflet.fullscreen';
99
import 'leaflet.fullscreen/Control.FullScreen.css';
10+
import { default as rangeslider } from 'rangeslider-pure';
1011

1112
const htmlTag = document.getElementsByTagName('html')[0];
1213
const lang = htmlTag.attributes['lang'].value;
1314

1415
const minimumAge = dayjs().subtract(18, 'year');
1516
const maximumAge = minimumAge.subtract(122, 'year');
1617

17-
const options: Options = {
18+
const options = {
1819
input: true,
1920
type: 'default',
2021
date: {
21-
max: <FormatDateString>minimumAge.format('YYYY-MM-DD'),
22-
min: <FormatDateString>maximumAge.format('YYYY-MM-DD')
22+
max: minimumAge.format('YYYY-MM-DD'),
23+
min: maximumAge.format('YYYY-MM-DD'),
24+
today: minimumAge.toDate(),
2325
},
2426
actions: {
2527
changeToInput(e, calendar, self) {
@@ -34,74 +36,83 @@ const options: Options = {
3436
},
3537
settings: {
3638
lang: lang,
39+
range: {
40+
max: minimumAge.format('YYYY-MM-DD'),
41+
min: maximumAge.format('YYYY-MM-DD'),
42+
},
3743
visibility: {
3844
positionToInput: 'center',
3945
theme: 'light',
4046
disabled: false,
41-
},
47+
weekend: false,
48+
today: false, },
4249
},
4350
};
4451

4552
const birthDate = document.getElementById('signup_form_finalize_birthdate');
4653
const calendar = new VanillaCalendar(birthDate, options);
4754
calendar.init();
4855

49-
const labelText = document.getElementById('marker_label_text').value;
50-
const locationGeonameId = document.getElementById('set_location_geoname_id');
51-
const locationLatitude = document.getElementById('set_location_latitude');
52-
const locationLongitude = document.getElementById('set_location_longitude');
53-
const originalLatitude = document.getElementById('original_latitude');
54-
const originalLongitude = document.getElementById('original_longitude');
56+
const labelText = 'marker-label'; // document.getElementById('marker_label_text').value;
57+
const locationGeonameId = document.getElementById('signup_form_finalize_location_geoname_id');
58+
const locationLatitude = document.getElementById('signup_form_finalize_location_latitude');
59+
const locationLongitude = document.getElementById('signup_form_finalize_location_longitude');
5560

5661
const myIcon = L.icon({
5762
iconUrl: 'images/icons/marker_drop.png',
5863
iconSize: [29, 24],
5964
iconAnchor: [9, 21],
6065
popupAnchor: [0, -14]
6166
});
62-
let marker = L.marker([locationLatitude.value, locationLongitude.value], {
63-
icon: myIcon,
64-
draggable: true
65-
});
66-
marker.bindPopup(labelText);
67-
marker.on('dragend', dragend);
68-
const map = L.map('map');
69-
marker.addTo(map);
70-
map.setView([locationLatitude.value, locationLongitude.value], 12);
7167

7268
// callback when a selection is done from the list of possible results
73-
const addMarkerAndMoveToNewLocation = function(element, result) {
69+
const storeLocation = function(element, result) {
7470
locationGeonameId.value = result.id;
7571
locationLatitude.value = result.latitude;
7672
locationLongitude.value = result.longitude;
77-
originalLatitude.value = result.latitude;
78-
originalLongitude.value = result.longitude;
73+
};
7974

80-
map.removeLayer(marker);
75+
initializeSingleAutoComplete("/suggest/locations/places/exact", 'js-location-picker', storeLocation);
8176

82-
marker = L.marker([locationLatitude.value, locationLongitude.value], {
83-
icon: myIcon,
84-
draggable: true
85-
});
86-
marker.bindPopup(labelText);
87-
marker.on('dragend', dragend);
88-
marker.addTo(map);
89-
map.setView(new L.LatLng(locationLatitude.value, locationLongitude.value), 12, {animate: true});
90-
};
77+
const slider = document.querySelectorAll('input[type="range"]');
9178

92-
// Dragging the marker around on the map changes the stored lat, long
93-
function dragend(e) {
94-
const originalLatLng = L.latLng(originalLatitude.value, originalLongitude.value);
95-
locationLatitude.value = e.target._latlng.lat;
96-
locationLongitude.value = e.target._latlng.lng;
79+
function updateValueOutput(value) {
80+
const valueOutput = document.getElementsByClassName('rangeSlider__value-output');
81+
if (valueOutput.length) {
82+
valueOutput[0].innerHTML = markers[value];
83+
}
9784
}
9885

99-
initializeSingleAutoComplete("/suggest/locations/places/exact", 'js-location-picker', addMarkerAndMoveToNewLocation);
86+
const initializeSlider = () => {
87+
return rangeslider.create(slider, {
88+
onInit: function() {
89+
updateValueOutput(0);
90+
},
91+
onSlide: function(value, percent, position) {
92+
updateValueOutput(value);
93+
}
94+
});
95+
};
10096

101-
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
102-
attribution: '&copy; <a href="https://openstreetmap.org/copyright">OpenStreetMap contributors</a>',
103-
subdomains: ['a', 'b', 'c']
104-
}).addTo(map);
97+
initializeSlider();
98+
99+
const accommodationRadiobuttons = document.querySelectorAll(".btn-light");
100+
const hostingInterest = document.getElementById('hosting_interest');
101+
const radioHandler = (event) => {
102+
if (event.target.type === 'radio') {
103+
console.log("Clicked: ", event.target.type, event.target.checked, event.target.value);
104+
if (event.target.value === 'no') {
105+
hostingInterest.classList.remove('u-block');
106+
hostingInterest.classList.add('u-hidden');
107+
} else {
108+
hostingInterest.classList.remove('u-hidden');
109+
hostingInterest.classList.add('u-block');
110+
}
111+
}
112+
}
105113

106-
L.control.scale().addTo(map);
114+
for (let radio of accommodationRadiobuttons) {
115+
radio.addEventListener("click", radioHandler)
116+
}
107117

118+
console.log(accommodationRadiobuttons)

0 commit comments

Comments
 (0)