Get repo up to date with changes in laravel/laravel (issue #95)
Squashed commit of the following: commit 850a0dfe70412f0851d1f40fe96c7afdc8348aab Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sun Jan 27 13:42:09 2019 +0000 Persist data cache commit fc80710c96b33bf387e346f97a58ed3965520427 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sun Jan 27 13:15:10 2019 +0000 Added another laravel dependency commit 1a9ed1bc71e3a11624e4924ae75c4284e6071f6d Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sun Jan 27 13:14:50 2019 +0000 Fix trailing comma commit 81f31ae7116146b073c8f886cb74e32d806eba60 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sat Jan 26 19:07:55 2019 +0000 Add Laravel’s illustration SVGs commit d1f99e4ec2b39d0159689f586f37465cbf867c2b Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sat Jan 26 19:07:34 2019 +0000 Add the dump-server commit 28a09927a32d20510f6bc236d14daf948c5dd547 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sat Jan 26 18:58:27 2019 +0000 Add mailgin endpoint commit e80e3a9d53852d5f137918d79969f5a3a93fad81 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sat Jan 26 18:55:11 2019 +0000 Update cache config commit 3db2f952d420be7e49041d495db6ee59ee310841 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sat Jan 26 18:50:02 2019 +0000 Update session config commit 0b431150616cb15f17b571e9340e6805723344d6 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sat Jan 26 18:46:05 2019 +0000 Add faker locale setting commit 048e8ee0c7969ed9b2251f270aea8fee25b3bf98 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sat Jan 26 18:44:09 2019 +0000 Add new Stripe webhook config values commit 18ce7bee19fca7f920fdcca72049108fd5a7a9b6 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sat Jan 26 18:42:57 2019 +0000 Add Authenticate to middleware commit 05007f1f038cac4453e4b5d82cb04d6f0820606c Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sat Jan 26 18:34:28 2019 +0000 Update phpunit config commit 5c033735fbe148b3f3e3950ae97a21977895eeb7 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sat Jan 26 18:32:18 2019 +0000 Update queue config commit fe92a6f2896a52ab1486288878055cd81abe28e7 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sat Jan 26 18:27:22 2019 +0000 Update database config commit 19036d7cb1ffc583a571451a7ea00fb421beef8f Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sat Jan 26 18:22:41 2019 +0000 Add asset_url config option commit ce4b1e3195a6c43fdc4f6fabb2a41b68344220fc Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sat Jan 26 18:20:40 2019 +0000 Allow custom compiled views path commit b503bca8c6a27fef44d34b826c75a2ee68e0a178 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sat Jan 26 18:20:18 2019 +0000 Add mail logging setting commit 2988ba197bbd1b0ac78a17ad796f31cc0bb803df Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sat Jan 26 18:17:41 2019 +0000 normalize composer.json commit a1ff37d716c68f1dedec9644e9fe6f3a7a5ad04f Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sat Jan 26 18:11:58 2019 +0000 Allow env for defining app base commit e662de24e3a2b7f170c6fb0860c6c16f192aa642 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sat Jan 26 18:10:17 2019 +0000 Get kernel/middleware upto date commit 2f8c9de52bec8a54fa6745a42c9a8974de0a1467 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sat Jan 26 18:04:44 2019 +0000 Update validation lang file commit 8f6bf24eec602b21d28b0b6bae6e274c175ff643 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sat Jan 26 18:02:28 2019 +0000 Update .gitignore commit e219cc454f3e77b822fe761c672bf24824c06d0c Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sat Jan 26 17:59:32 2019 +0000 Update logging.php config file commit 5a13e1b89f9311918f3f9756d9607424f42e72c5 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sat Jan 26 17:56:36 2019 +0000 Remove extra whitespace commit 68edee0a9dca0d11d18964329d7f0ec49d32c6e8 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sat Jan 26 17:53:30 2019 +0000 Recompile assets from new resources folder structure commit 7ec8441a802cb1385fb40cdd22b2398180287512 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sat Jan 26 17:44:56 2019 +0000 Change reference to assets files in various scripts commit c2f6dfccf2843b25038475d2a5f492decc9e8124 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sat Jan 26 17:42:25 2019 +0000 Flatten assets directory
This commit is contained in:
parent
acbb04f5a9
commit
76d474b335
66 changed files with 384 additions and 151 deletions
45
resources/es6/a11y.js
vendored
Normal file
45
resources/es6/a11y.js
vendored
Normal file
|
@ -0,0 +1,45 @@
|
|||
//a11y.css.js
|
||||
|
||||
let checkbox = document.querySelector('input[name="a11y.css"]');
|
||||
|
||||
checkbox.addEventListener('change', function () {
|
||||
if (this.checked) {
|
||||
addA11yCss();
|
||||
} else {
|
||||
removeA11yCss();
|
||||
}
|
||||
});
|
||||
|
||||
function addA11yCss() {
|
||||
let exists = a11yCssExists();
|
||||
if (exists == false) {
|
||||
//add a11y.css link
|
||||
let link = document.createElement('link');
|
||||
link.setAttribute('rel', 'stylesheet');
|
||||
link.setAttribute('href', '/assets/frontend/a11y.css/a11y-en.css');
|
||||
let head = document.querySelector('head');
|
||||
head.appendChild(link);
|
||||
}
|
||||
}
|
||||
|
||||
function removeA11yCss() {
|
||||
let exists = a11yCssExists();
|
||||
if (exists == true) {
|
||||
//remove a11y.css link
|
||||
let link = document.querySelector('link[href="/assets/frontend/a11y.css/a11y-en.css"]');
|
||||
let head = document.querySelector('head');
|
||||
head.removeChild(link);
|
||||
}
|
||||
}
|
||||
|
||||
function a11yCssExists() {
|
||||
let css = document.querySelectorAll('link[rel=stylesheet]');
|
||||
let exists = false;
|
||||
for (let link of css) {
|
||||
if (link.attributes.href.nodeValue == '/assets/frontend/a11y.css/a11y-en.css') {
|
||||
exists = true;
|
||||
}
|
||||
}
|
||||
|
||||
return exists;
|
||||
}
|
30
resources/es6/colours.js
vendored
Normal file
30
resources/es6/colours.js
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
//colours.js
|
||||
|
||||
let link = document.querySelector('#colourScheme');
|
||||
|
||||
let css = link.getAttribute('href').split('/').pop();
|
||||
|
||||
// update selected item in colour scheme list
|
||||
document.getElementById('colourSchemeSelect').value = css;
|
||||
|
||||
// fix form
|
||||
let form = document.getElementById('colourSchemeForm');
|
||||
let btn = form.childNodes[5];
|
||||
btn.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
let newCss = document.getElementById('colourSchemeSelect').value;
|
||||
let link = document.querySelector('#colourScheme');
|
||||
let css = link.getAttribute('href');
|
||||
let parts = css.split('/');
|
||||
parts.pop();
|
||||
parts.push(newCss);
|
||||
link.setAttribute('href', parts.join('/'));
|
||||
let formData = new FormData(form);
|
||||
fetch('/update-colour-scheme', {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
body: formData
|
||||
}).catch(function (error) {
|
||||
console.warn(error);
|
||||
});
|
||||
});
|
7
resources/es6/edit-place-icon.js
vendored
Normal file
7
resources/es6/edit-place-icon.js
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
//edit-place-icon.js
|
||||
|
||||
export default function getIcon() {
|
||||
let iconOption = document.querySelector('#icon');
|
||||
|
||||
return iconOption.value;
|
||||
}
|
31
resources/es6/links.js
vendored
Normal file
31
resources/es6/links.js
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
//links.js
|
||||
|
||||
let youtubeRegex = /watch\?v=([A-Za-z0-9\-_]+)\b/;
|
||||
let spotifyRegex = /https:\/\/play\.spotify\.com\/(.*)\b/;
|
||||
|
||||
let notes = document.querySelectorAll('.e-content');
|
||||
|
||||
for (let note of notes) {
|
||||
let ytid = note.textContent.match(youtubeRegex);
|
||||
if (ytid) {
|
||||
let ytcontainer = document.createElement('div');
|
||||
ytcontainer.classList.add('container');
|
||||
let ytiframe = document.createElement('iframe');
|
||||
ytiframe.classList.add('youtube');
|
||||
ytiframe.setAttribute('src', 'https://www.youtube.com/embed/' + ytid[1]);
|
||||
ytiframe.setAttribute('frameborder', 0);
|
||||
ytiframe.setAttribute('allowfullscreen', 'true');
|
||||
ytcontainer.appendChild(ytiframe);
|
||||
note.appendChild(ytcontainer);
|
||||
}
|
||||
let spotifyid = note.textContent.match(spotifyRegex);
|
||||
if (spotifyid) {
|
||||
let sid = spotifyid[1].replace('/', ':');
|
||||
let siframe = document.createElement('iframe');
|
||||
siframe.classList.add('spotify');
|
||||
siframe.setAttribute('src', 'https://embed.spotify.com/?uri=spotify:' + sid);
|
||||
siframe.setAttribute('frameborder', 0);
|
||||
siframe.setAttribute('allowtransparency', 'true');
|
||||
note.appendChild(siframe);
|
||||
}
|
||||
}
|
182
resources/es6/mapbox-utils.js
vendored
Normal file
182
resources/es6/mapbox-utils.js
vendored
Normal file
|
@ -0,0 +1,182 @@
|
|||
//mapbox-utils.js
|
||||
import mapboxgl from 'mapbox-gl/dist/mapbox-gl.js';
|
||||
import parseLocation from './parse-location';
|
||||
import selectPlaceInForm from './select-place';
|
||||
|
||||
mapboxgl.accessToken = 'pk.eyJ1Ijoiam9ubnliYXJuZXMiLCJhIjoiY2l2cDhjYW04MDAwcjJ0cG1uZnhqcm82ayJ9.qA2zeVA-nsoMh9IFrd5KQw';
|
||||
|
||||
// Define some functions to be used in the default function.
|
||||
const titlecase = (string) => {
|
||||
return string.split('-').map(([first,...rest]) => first.toUpperCase() + rest.join('').toLowerCase()).join(' ');
|
||||
};
|
||||
|
||||
// Get the ID for the map, i.e. get the u-url of the containing note.
|
||||
const getId = (map) => {
|
||||
let href = map._container.parentNode.querySelector('.u-url').getAttribute('href');
|
||||
return href.substr(href.lastIndexOf('/') + 1);
|
||||
};
|
||||
|
||||
const addMapTypeOption = (map, menu, option, checked = false) => {
|
||||
let div = document.createElement('div');
|
||||
let input = document.createElement('input');
|
||||
let id = option + getId(map);
|
||||
input.setAttribute('id', id);
|
||||
input.setAttribute('type', 'radio');
|
||||
input.setAttribute('name', 'map' + getId(map));
|
||||
input.setAttribute('value', option);
|
||||
if (checked == true) {
|
||||
input.setAttribute('checked', 'checked');
|
||||
}
|
||||
input.addEventListener('click', function () {
|
||||
let source = map.getSource('points');
|
||||
map.setStyle('mapbox://styles/mapbox/' + option + '-v9');
|
||||
map.on('style.load', function () {
|
||||
map.addLayer({
|
||||
'id': 'points',
|
||||
'type': 'symbol',
|
||||
'source': {
|
||||
'type': 'geojson',
|
||||
'data': source._data
|
||||
},
|
||||
'layout': {
|
||||
'icon-image': '{icon}-15',
|
||||
'text-field': '{title}',
|
||||
'text-offset': [0, 1]
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
let label = document.createElement('label');
|
||||
label.setAttribute('for', option + getId(map));
|
||||
label.appendChild(document.createTextNode(titlecase(option)));
|
||||
div.appendChild(input);
|
||||
div.appendChild(label);
|
||||
menu.appendChild(div);
|
||||
};
|
||||
|
||||
const makeMapMenu = (map) => {
|
||||
let mapMenu = document.createElement('fieldset');
|
||||
let legend = document.createElement('legend');
|
||||
let title = document.createTextNode('Map Style');
|
||||
legend.appendChild(title);
|
||||
mapMenu.appendChild(legend);
|
||||
mapMenu.classList.add('map-menu');
|
||||
addMapTypeOption(map, mapMenu, 'streets', true);
|
||||
addMapTypeOption(map, mapMenu, 'satellite-streets');
|
||||
return mapMenu;
|
||||
};
|
||||
|
||||
// The main function.
|
||||
export default function addMap(div, position = null, places = null) {
|
||||
let data;
|
||||
let dataLatitude = div.dataset.latitude;
|
||||
let dataLongitude = div.dataset.longitude;
|
||||
let dataName = div.dataset.name;
|
||||
let dataMarker = div.dataset.marker;
|
||||
if (dataMarker == '') {
|
||||
dataMarker = 'circle';
|
||||
}
|
||||
if (dataName == null) {
|
||||
data = {
|
||||
'type': 'FeatureCollection',
|
||||
'features': [{
|
||||
'type': 'Feature',
|
||||
'geometry': {
|
||||
'type': 'Point',
|
||||
'coordinates': [dataLongitude, dataLatitude]
|
||||
},
|
||||
'properties': {
|
||||
'title': 'Current Location',
|
||||
'icon': 'circle-stroked',
|
||||
'uri': 'current-location'
|
||||
}
|
||||
}]
|
||||
};
|
||||
} else {
|
||||
data = {
|
||||
'type': 'FeatureCollection',
|
||||
'features': [{
|
||||
'type': 'Feature',
|
||||
'geometry': {
|
||||
'type': 'Point',
|
||||
'coordinates': [dataLongitude, dataLatitude]
|
||||
},
|
||||
'properties': {
|
||||
'title': dataName,
|
||||
'icon': dataMarker,
|
||||
}
|
||||
}]
|
||||
};
|
||||
}
|
||||
if (places != null) {
|
||||
for (let place of places) {
|
||||
let placeLongitude = parseLocation(place.location).longitude;
|
||||
let placeLatitude = parseLocation(place.location).latitude;
|
||||
data.features.push({
|
||||
'type': 'Feature',
|
||||
'geometry': {
|
||||
'type': 'Point',
|
||||
'coordinates': [placeLongitude, placeLatitude]
|
||||
},
|
||||
'properties': {
|
||||
'title': place.name,
|
||||
'icon': 'circle',
|
||||
'uri': place.slug
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
if (position != null) {
|
||||
dataLongitude = position.coords.longitude;
|
||||
dataLatitude = position.coords.latitude;
|
||||
}
|
||||
let map = new mapboxgl.Map({
|
||||
container: div,
|
||||
style: 'mapbox://styles/mapbox/streets-v9',
|
||||
center: [dataLongitude, dataLatitude],
|
||||
zoom: 15
|
||||
});
|
||||
if (position == null) {
|
||||
map.scrollZoom.disable();
|
||||
}
|
||||
map.addControl(new mapboxgl.NavigationControl());
|
||||
div.appendChild(makeMapMenu(map));
|
||||
map.on('load', function () {
|
||||
map.addLayer({
|
||||
'id': 'points',
|
||||
'type': 'symbol',
|
||||
'source': {
|
||||
'type': 'geojson',
|
||||
'data': data
|
||||
},
|
||||
'layout': {
|
||||
'icon-image': '{icon}-15',
|
||||
'text-field': '{title}',
|
||||
'text-offset': [0, 1]
|
||||
}
|
||||
});
|
||||
});
|
||||
if (position != null) {
|
||||
map.on('click', function (e) {
|
||||
let features = map.queryRenderedFeatures(e.point, {
|
||||
layer: ['points']
|
||||
});
|
||||
// if there are features within the given radius of the click event,
|
||||
// fly to the location of the click event
|
||||
if (features.length) {
|
||||
// Get coordinates from the symbol and center the map on those coordinates
|
||||
map.flyTo({center: features[0].geometry.coordinates});
|
||||
selectPlaceInForm(features[0].properties.uri);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (data.features && data.features.length > 1) {
|
||||
let bounds = new mapboxgl.LngLatBounds();
|
||||
for (let feature of data.features) {
|
||||
bounds.extend(feature.geometry.coordinates);
|
||||
}
|
||||
map.fitBounds(bounds, { padding: 65});
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
8
resources/es6/maps.js
vendored
Normal file
8
resources/es6/maps.js
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
//maps.js
|
||||
import addMap from './mapbox-utils';
|
||||
|
||||
let mapDivs = document.querySelectorAll('.map');
|
||||
|
||||
for (let div of mapDivs) {
|
||||
addMap(div);
|
||||
}
|
10
resources/es6/parse-location.js
vendored
Normal file
10
resources/es6/parse-location.js
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
//parse-location.js
|
||||
|
||||
//text = `POINT(lon lat)`
|
||||
export default function parseLocation(text) {
|
||||
let coords = /POINT\((.*)\)/.exec(text);
|
||||
let parsedLongitude = coords[1].split(' ')[0];
|
||||
let parsedLatitude = coords[1].split(' ')[1];
|
||||
|
||||
return {'latitude': parsedLatitude, 'longitude': parsedLongitude};
|
||||
}
|
12
resources/es6/piwik.js
vendored
Normal file
12
resources/es6/piwik.js
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
/* global process */
|
||||
|
||||
// Piwik in its own js file to allow usage with a CSP policy
|
||||
var idSite = process.env.PIWIK_ID;
|
||||
var piwikTrackingApiUrl = process.env.PIWIK_URL;
|
||||
|
||||
var _paq = _paq || [];
|
||||
// tracker methods like "setCustomDimension" should be called before "trackPageView"
|
||||
_paq.push(['setTrackerUrl', piwikTrackingApiUrl]);
|
||||
_paq.push(['setSiteId', idSite]);
|
||||
_paq.push(['trackPageView']);
|
||||
_paq.push(['enableLinkTracking']);
|
83
resources/es6/places.js
vendored
Normal file
83
resources/es6/places.js
vendored
Normal file
|
@ -0,0 +1,83 @@
|
|||
//places.js
|
||||
|
||||
import addMap from './mapbox-utils';
|
||||
import getIcon from './edit-place-icon';
|
||||
|
||||
let div = document.querySelector('.map');
|
||||
let map = addMap(div);
|
||||
let isDragging;
|
||||
let isCursorOverPoint;
|
||||
let canvas = map.getCanvasContainer();
|
||||
|
||||
let selectElem = document.querySelector('select[name="icon"]');
|
||||
selectElem.addEventListener('click', function () {
|
||||
let newIcon = getIcon();
|
||||
let source = map.getSource('points');
|
||||
if (source._data.features[0].properties.icon != newIcon) {
|
||||
source._data.features[0].properties.icon = newIcon;
|
||||
map.getSource('points').setData(source._data);
|
||||
}
|
||||
});
|
||||
|
||||
function updateFormCoords(coords) {
|
||||
let latInput = document.querySelector('#latitude');
|
||||
let lonInput = document.querySelector('#longitude');
|
||||
latInput.value = coords.lat.toPrecision(6);
|
||||
lonInput.value = coords.lng.toPrecision(6);
|
||||
}
|
||||
|
||||
function mouseDown() {
|
||||
if (!isCursorOverPoint) return;
|
||||
|
||||
isDragging = true;
|
||||
|
||||
// Set a cursor indicator
|
||||
canvas.style.cursor = 'grab';
|
||||
|
||||
// Mouse events
|
||||
map.on('mousemove', onMove);
|
||||
map.once('mouseup', onUp);
|
||||
}
|
||||
|
||||
function onMove(e) {
|
||||
if (!isDragging) return;
|
||||
let coords = e.lngLat;
|
||||
let source = map.getSource('points');
|
||||
|
||||
// Set a UI indicator for dragging.
|
||||
canvas.style.cursor = 'grabbing';
|
||||
|
||||
// Update the Point feature in `geojson` coordinates
|
||||
// and call setData to the source layer `point` on it.
|
||||
source._data.features[0].geometry.coordinates = [coords.lng, coords.lat];
|
||||
map.getSource('points').setData(source._data);
|
||||
}
|
||||
|
||||
function onUp(e) {
|
||||
if (!isDragging) return;
|
||||
let coords = e.lngLat;
|
||||
|
||||
// Print the coordinates of where the point had
|
||||
// finished being dragged to on the map.
|
||||
updateFormCoords(coords);
|
||||
canvas.style.cursor = '';
|
||||
isDragging = false;
|
||||
|
||||
// Unbind mouse events
|
||||
map.off('mousemove', onMove);
|
||||
}
|
||||
|
||||
// When the cursor enters a feature in the point layer, prepare for dragging.
|
||||
map.on('mouseenter', 'points', function() {
|
||||
canvas.style.cursor = 'move';
|
||||
isCursorOverPoint = true;
|
||||
map.dragPan.disable();
|
||||
});
|
||||
|
||||
map.on('mouseleave', 'points', function() {
|
||||
canvas.style.cursor = '';
|
||||
isCursorOverPoint = false;
|
||||
map.dragPan.enable();
|
||||
});
|
||||
|
||||
map.on('mousedown', mouseDown);
|
11
resources/es6/select-place.js
vendored
Normal file
11
resources/es6/select-place.js
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
//select-place.js
|
||||
|
||||
export default function selectPlaceInForm(uri) {
|
||||
if (document.querySelector('select')) {
|
||||
if (uri == 'current-location') {
|
||||
document.querySelector('select [id="option-coords"]').selected = true;
|
||||
} else {
|
||||
document.querySelector('select [value="' + uri + '"]').selected = true;
|
||||
}
|
||||
}
|
||||
}
|
71
resources/es6/submit-place.js
vendored
Normal file
71
resources/es6/submit-place.js
vendored
Normal file
|
@ -0,0 +1,71 @@
|
|||
//submit-place.js
|
||||
|
||||
import alertify from 'alertify.js';
|
||||
|
||||
export default function submitNewPlace(map) {
|
||||
//create the form data to send
|
||||
let formData = new FormData();
|
||||
formData.append('place-name', document.querySelector('#place-name').value);
|
||||
formData.append('place-description', document.querySelector('#place-description').value);
|
||||
formData.append('place-latitude', document.querySelector('#place-latitude').value);
|
||||
formData.append('place-longitude', document.querySelector('#place-longitude').value);
|
||||
//post the new place
|
||||
fetch('/micropub/places', {
|
||||
//send cookies with the request
|
||||
credentials: 'same-origin',
|
||||
method: 'post',
|
||||
body: formData
|
||||
}).then(function (response) {
|
||||
return response.json();
|
||||
}).then(function (placeJson) {
|
||||
if (placeJson.error === true) {
|
||||
throw new Error(placeJson.error_description);
|
||||
}
|
||||
//remove un-needed form elements
|
||||
let form = document.querySelector('fieldset');
|
||||
//iterate through labels and remove parent div elements
|
||||
let labels = document.querySelectorAll('.place-label');
|
||||
for (let label of labels) {
|
||||
form.removeChild(label.parentNode);
|
||||
}
|
||||
form.removeChild(document.querySelector('#place-submit'));
|
||||
let newPlaceButton = document.querySelector('#create-new-place');
|
||||
//in order to remove a DOM Node, you need to run removeChild on the parent Node
|
||||
newPlaceButton.parentNode.removeChild(newPlaceButton);
|
||||
//remove current location from map
|
||||
let source = map.getSource('points');
|
||||
let newFeatures = source._data.features.filter(function (item) {
|
||||
return item.properties.title != 'Current Location';
|
||||
});
|
||||
//add new place to map
|
||||
newFeatures.push({
|
||||
'type': 'Feature',
|
||||
'geometry': {
|
||||
'type': 'Point',
|
||||
'coordinates': [placeJson.longitude, placeJson.latitude]
|
||||
},
|
||||
'properties': {
|
||||
'title': placeJson.name,
|
||||
'icon': 'circle',
|
||||
'uri': placeJson.uri
|
||||
}
|
||||
});
|
||||
let newSource = {
|
||||
'type': 'FeatureCollection',
|
||||
'features': newFeatures
|
||||
};
|
||||
map.getSource('points').setData(newSource);
|
||||
//add new place to select menu
|
||||
let selectElement = document.querySelector('select');
|
||||
let newlyCreatedPlaceOption = document.createElement('option');
|
||||
newlyCreatedPlaceOption.setAttribute('value', placeJson.uri);
|
||||
newlyCreatedPlaceOption.appendChild(document.createTextNode(placeJson.name));
|
||||
newlyCreatedPlaceOption.dataset.latitude = placeJson.latitude;
|
||||
newlyCreatedPlaceOption.dataset.longitude = placeJson.longitude;
|
||||
selectElement.appendChild(newlyCreatedPlaceOption);
|
||||
document.querySelector('select [value="' + placeJson.uri + '"]').selected = true;
|
||||
}).catch(function (placeError) {
|
||||
alertify.reset();
|
||||
alertify.error(placeError);
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue