|
1 |
| -import Litepicker from 'litepicker/dist/nocss/litepicker.umd.js'; |
2 |
| -import dayjs from 'dayjs'; |
| 1 | +import VanillaCalendar, { Options, FormatDateString } from 'vanilla-calendar-pro'; |
| 2 | +import 'vanilla-calendar-pro/build/vanilla-calendar.min.css'; |
| 3 | +import * as dayjs from 'dayjs' |
3 | 4 |
|
4 |
| -$(function () { |
5 |
| - $('[data-toggle="popover"]').popover({ html : true }); |
| 5 | +import {initializeSingleAutoComplete} from './suggest/locations'; |
| 6 | +import * as L from 'leaflet'; |
6 | 7 |
|
7 |
| - $("#mothertongue").select2({ |
8 |
| - theme: 'bootstrap4', |
9 |
| - placeholder: 'Select a language', |
10 |
| - allowClear: true, |
11 |
| - width: 'auto' |
12 |
| - }); |
| 8 | +import 'leaflet.fullscreen'; |
| 9 | +import 'leaflet.fullscreen/Control.FullScreen.css'; |
| 10 | + |
| 11 | +const htmlTag = document.getElementsByTagName('html')[0]; |
| 12 | +const lang = htmlTag.attributes['lang'].value; |
13 | 13 |
|
| 14 | +const minimumAge = dayjs().subtract(18, 'year'); |
| 15 | +const maximumAge = minimumAge.subtract(122, 'year'); |
14 | 16 |
|
15 |
| - let birthdate = document.getElementById('birthdate'); |
16 |
| - let maxDate = dayjs().subtract(18, "years"); |
17 |
| - |
18 |
| - if (birthdate) { |
19 |
| - const picker = new Litepicker({ |
20 |
| - element: birthdate, |
21 |
| - singleMode: true, |
22 |
| - allowRepick: true, |
23 |
| - dropdowns: { |
24 |
| - "minYear":1900, |
25 |
| - "maxYear":2004, |
26 |
| - "months":true, |
27 |
| - "years":true}, |
28 |
| - maxDate: maxDate, |
29 |
| - numberOfMonths: 1, |
30 |
| - numberOfColumns: 1, |
31 |
| - format: "YYYY-MM-DD", |
32 |
| - position: 'top left', |
33 |
| - showTooltip: false, |
34 |
| - lang: document.documentElement.lang, |
35 |
| - setup: (picker) => { |
36 |
| - picker.on('selected', (start, end) => { |
37 |
| - }); |
| 17 | +const options: Options = { |
| 18 | + input: true, |
| 19 | + type: 'default', |
| 20 | + date: { |
| 21 | + max: <FormatDateString>minimumAge.format('YYYY-MM-DD'), |
| 22 | + min: <FormatDateString>maximumAge.format('YYYY-MM-DD') |
| 23 | + }, |
| 24 | + actions: { |
| 25 | + changeToInput(e, calendar, self) { |
| 26 | + if (!self.HTMLInputElement) return; |
| 27 | + if (self.selectedDates[0]) { |
| 28 | + self.HTMLInputElement.value = self.selectedDates[0]; |
| 29 | + calendar.hide(); |
| 30 | + } else { |
| 31 | + self.HTMLInputElement.value = ''; |
38 | 32 | }
|
39 |
| - }); |
40 |
| - } |
| 33 | + }, |
| 34 | + }, |
| 35 | + settings: { |
| 36 | + lang: lang, |
| 37 | + visibility: { |
| 38 | + positionToInput: 'center', |
| 39 | + theme: 'light', |
| 40 | + disabled: false, |
| 41 | + }, |
| 42 | + }, |
| 43 | +}; |
| 44 | + |
| 45 | +const birthDate = document.getElementById('signup_form_finalize_birthdate'); |
| 46 | +const calendar = new VanillaCalendar(birthDate, options); |
| 47 | +calendar.init(); |
| 48 | + |
| 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'); |
| 55 | + |
| 56 | +const myIcon = L.icon({ |
| 57 | + iconUrl: 'images/icons/marker_drop.png', |
| 58 | + iconSize: [29, 24], |
| 59 | + iconAnchor: [9, 21], |
| 60 | + popupAnchor: [0, -14] |
| 61 | +}); |
| 62 | +let marker = L.marker([locationLatitude.value, locationLongitude.value], { |
| 63 | + icon: myIcon, |
| 64 | + draggable: true |
41 | 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 | + |
| 72 | +// callback when a selection is done from the list of possible results |
| 73 | +const addMarkerAndMoveToNewLocation = function(element, result) { |
| 74 | + locationGeonameId.value = result.id; |
| 75 | + locationLatitude.value = result.latitude; |
| 76 | + locationLongitude.value = result.longitude; |
| 77 | + originalLatitude.value = result.latitude; |
| 78 | + originalLongitude.value = result.longitude; |
| 79 | + |
| 80 | + map.removeLayer(marker); |
| 81 | + |
| 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 | +}; |
| 91 | + |
| 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; |
| 97 | +} |
| 98 | + |
| 99 | +initializeSingleAutoComplete("/suggest/locations/places/exact", 'js-location-picker', addMarkerAndMoveToNewLocation); |
| 100 | + |
| 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); |
| 105 | + |
| 106 | +L.control.scale().addTo(map); |
| 107 | + |
0 commit comments