1
- import VanillaCalendar , { Options , FormatDateString } from 'vanilla-calendar-pro' ;
1
+ import VanillaCalendar from 'vanilla-calendar-pro' ;
2
2
import 'vanilla-calendar-pro/build/vanilla-calendar.min.css' ;
3
3
import * as dayjs from 'dayjs'
4
4
5
+ import 'leaflet' ;
6
+ import 'leaflet/dist/leaflet.css' ;
5
7
import { initializeSingleAutoComplete } from './suggest/locations' ;
6
- import * as L from 'leaflet' ;
7
-
8
8
import 'leaflet.fullscreen' ;
9
9
import 'leaflet.fullscreen/Control.FullScreen.css' ;
10
+ import { default as rangeslider } from 'rangeslider-pure' ;
10
11
11
12
const htmlTag = document . getElementsByTagName ( 'html' ) [ 0 ] ;
12
13
const lang = htmlTag . attributes [ 'lang' ] . value ;
13
14
14
15
const minimumAge = dayjs ( ) . subtract ( 18 , 'year' ) ;
15
16
const maximumAge = minimumAge . subtract ( 122 , 'year' ) ;
16
17
17
- const options : Options = {
18
+ const options = {
18
19
input : true ,
19
20
type : 'default' ,
20
21
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 ( ) ,
23
25
} ,
24
26
actions : {
25
27
changeToInput ( e , calendar , self ) {
@@ -34,74 +36,83 @@ const options: Options = {
34
36
} ,
35
37
settings : {
36
38
lang : lang ,
39
+ range : {
40
+ max : minimumAge . format ( 'YYYY-MM-DD' ) ,
41
+ min : maximumAge . format ( 'YYYY-MM-DD' ) ,
42
+ } ,
37
43
visibility : {
38
44
positionToInput : 'center' ,
39
45
theme : 'light' ,
40
46
disabled : false ,
41
- } ,
47
+ weekend : false ,
48
+ today : false , } ,
42
49
} ,
43
50
} ;
44
51
45
52
const birthDate = document . getElementById ( 'signup_form_finalize_birthdate' ) ;
46
53
const calendar = new VanillaCalendar ( birthDate , options ) ;
47
54
calendar . init ( ) ;
48
55
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' ) ;
55
60
56
61
const myIcon = L . icon ( {
57
62
iconUrl : 'images/icons/marker_drop.png' ,
58
63
iconSize : [ 29 , 24 ] ,
59
64
iconAnchor : [ 9 , 21 ] ,
60
65
popupAnchor : [ 0 , - 14 ]
61
66
} ) ;
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);
71
67
72
68
// callback when a selection is done from the list of possible results
73
- const addMarkerAndMoveToNewLocation = function(element, result) {
69
+ const storeLocation = function ( element , result ) {
74
70
locationGeonameId . value = result . id ;
75
71
locationLatitude . value = result . latitude ;
76
72
locationLongitude . value = result . longitude ;
77
- originalLatitude . value = result . latitude ;
78
- originalLongitude . value = result . longitude ;
73
+ } ;
79
74
80
- map . removeLayer ( marker ) ;
75
+ initializeSingleAutoComplete ( "/suggest/locations/places/exact" , 'js-location-picker' , storeLocation ) ;
81
76
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"]' ) ;
91
78
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
+ }
97
84
}
98
85
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
+ } ;
100
96
101
- L.tileLayer('https://{ s } .tile.openstreetmap.org/{ z } /{ x } /{ y } .png', {
102
- attribution : '© <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
+ }
105
113
106
- L.control.scale().addTo(map);
114
+ for ( let radio of accommodationRadiobuttons ) {
115
+ radio . addEventListener ( "click" , radioHandler )
116
+ }
107
117
118
+ console . log ( accommodationRadiobuttons )
0 commit comments