Get rid of old es5 javascript files

This commit is contained in:
Jonny Barnes 2017-11-08 14:38:57 +00:00
parent 09bb56b418
commit 6730e732ce
5 changed files with 0 additions and 516 deletions

View file

@ -1,69 +0,0 @@
/* global alertify, store */
var feature = {
addEventListener : !!window.addEventListener,
querySelectorAll : !!document.querySelectorAll
};
if (feature.addEventListener && feature.querySelectorAll) {
var keys = getKeys();
for (var i = 0; i < keys.length; i++) {
if (store.get(keys[i])) {
var formId = keys[i].split('~')[1];
document.getElementById(formId).value = store.get(keys[i]);
}
}
}
var timerId = window.setInterval(function() {
var saved = false;
var inputs = document.querySelectorAll('input[type=text], textarea');
for (var i = 0; i < inputs.length; i++) {
var key = getFormElement(inputs[i]).id + '~' + inputs[i].id;
if (store.get(key) !== inputs[i].value && inputs[i].value !== '') {
store.set(key, inputs[i].value);
saved = true;
}
}
if (saved === true) {
alertify.logPosition('top right');
alertify.success('Auto saved text');
}
}, 5000);
var forms = document.querySelectorAll('form');
for (var f = 0; f < forms.length; f++) {
var form = forms[f];
form.addEventListener('submit', function() {
window.clearInterval(timerId);
var formId = form.id;
var storedKeys = store.keys();
for (var i = 0; i < storedKeys.length; i++) {
if (storedKeys[i].indexOf(formId) > -1) {
store.remove(storedKeys[i]);
}
}
});
}
function getKeys() {
var keys = [];
var formFields = document.querySelectorAll('input[type=text], textarea');
for (var f = 0; f < formFields.length; f++) {
var parent = getFormElement(formFields[f]);
if (parent !== false) {
var key = parent.id + '~' + formFields[f].id;
keys.push(key);
}
}
return keys;
}
function getFormElement(elem) {
if (elem.nodeName.toLowerCase() !== 'body') {
var parent = elem.parentNode;
if (parent.nodeName.toLowerCase() === 'form') {
return parent;
} else {
return getFormElement(parent);
}
} else {
return false;
}
}

View file

@ -1,39 +0,0 @@
/* global Autolinker */
//the autlinker object
var autolinker = new Autolinker();
//the youtube regex
var ytidregex = /watch\?v=([A-Za-z0-9\-_]+)/;
var spotifyregex = /https\:\/\/play\.spotify\.com\/(.*)\b/;
//grab the notes and loop through them
var notes = document.querySelectorAll('.e-content');
for (var i = 0; i < notes.length; i++) {
//get Youtube ID
var ytid = notes[i].textContent.match(ytidregex);
if (ytid !== null) {
var yid = ytid[1];
var yiframe = document.createElement('iframe');
yiframe.classList.add('youtube');
yiframe.setAttribute('src', '//www.youtube.com/embed/' + yid);
yiframe.setAttribute('frameborder', 0);
yiframe.setAttribute('allowfullscreen', 'true');
notes[i].appendChild(yiframe);
}
//get Spotify ID
var spotifyid = notes[i].textContent.match(spotifyregex);
if (spotifyid !== null) {
var sid = spotifyid[1].replace('/', ':');
var 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');
notes[i].appendChild(siframe);
}
//now linkify everything
var orig = notes[i].innerHTML;
var linked = autolinker.link(orig);
notes[i].innerHTML = linked;
}

View file

@ -1,50 +0,0 @@
/* global mapboxgl */
//This code runs on page load and looks for <div class="map">, then adds map
var mapDivs = document.querySelectorAll('.map');
mapboxgl.accessToken = 'pk.eyJ1Ijoiam9ubnliYXJuZXMiLCJhIjoiY2l2cDhjYW04MDAwcjJ0cG1uZnhqcm82ayJ9.qA2zeVA-nsoMh9IFrd5KQw';
for (var i = 0; i < mapDivs.length; i++) {
var mapDiv = mapDivs[i];
var latitude = mapDiv.dataset.latitude;
var longitude = mapDiv.dataset.longitude;
var el = document.createElement('div');
el.classList.add('marker');
var mapMenu = document.createElement('div');
mapMenu.classList.add('map-menu');
var streetsInput = document.createElement('input');
streetsInput.setAttribute('id', 'streets');
streetsInput.setAttribute('type', 'radio');
streetsInput.setAttribute('name', 'toggle');
streetsInput.setAttribute('value', 'streets');
streetsInput.setAttribute('checked', 'checked');
streetsInput.addEventListener('click', function () {
map.setStyle('mapbox://styles/mapbox/streets-v9');
});
var streetsLabel = document.createElement('label');
streetsLabel.setAttribute('for', 'streets');
streetsLabel.appendChild(document.createTextNode('Streets'));
var satelliteInput = document.createElement('input');
satelliteInput.setAttribute('id', 'satellite');
satelliteInput.setAttribute('type', 'radio');
satelliteInput.setAttribute('name', 'toggle');
satelliteInput.setAttribute('value', 'streets');
satelliteInput.addEventListener('click', function () {
map.setStyle('mapbox://styles/mapbox/satellite-v9');
});
var satelliteLabel = document.createElement('label');
satelliteLabel.setAttribute('for', 'satellite');
satelliteLabel.appendChild(document.createTextNode('Satellite'));
mapMenu.appendChild(streetsInput);
mapMenu.appendChild(streetsLabel);
mapMenu.appendChild(satelliteInput);
mapMenu.appendChild(satelliteLabel);
var map = new mapboxgl.Map({
container: mapDiv,
style: 'mapbox://styles/mapbox/streets-v9',
center: [longitude, latitude],
zoom: 15,
scrollZoom: false
});
map.addControl(new mapboxgl.NavigationControl());
new mapboxgl.Marker(el, {offset: [-10, -20]}).setLngLat([longitude, latitude]).addTo(map);
mapDiv.appendChild(mapMenu);
}

View file

@ -1,314 +0,0 @@
/* global mapboxgl, alertify */
if ('geolocation' in navigator) {
var button = document.querySelector('#locate');
if (button.addEventListener) {
//if we have javascript, event listeners and geolocation, make the locate
//button clickable and add event
button.disabled = false;
button.addEventListener('click', getLocation);
}
}
function getLocation() {
navigator.geolocation.getCurrentPosition(function (position) {
//the locate button has been clicked so add the places/map
addPlacesMap(position.coords.latitude, position.coords.longitude, position.coords.accuracy);
});
}
function addPlacesMap(latitude, longitude, uncertainty) {
//get the nearby places
fetch('/places/near/' + latitude + '/' + longitude + '?u=' + uncertainty, {
credentials: 'same-origin',
method: 'get'
}).then(function (response) {
return response.json();
}).then(function (j) {
if (j.error === true) {
alertify.reset();
alertify.error(j.error_description);
}
if (j.places.length > 0) {
var i;
var places = [];
for (i = 0; i < j.places.length; ++i) {
var latlng = parseLocation(j.places[i].location);
var name = j.places[i].name;
var uri = j.places[i].uri;
places.push([name, uri, latlng[0], latlng[1]]);
}
//add a map with the nearby places
addMap(latitude, longitude, places);
} else {
//add a map with just current location
addMap(latitude, longitude);
}
}).catch(function (err) {
console.error(err);
});
}
function addMap(latitude, longitude, places) {
//make places null if not supplied
if (arguments.length == 2) {
places = null;
}
// the form has a fieldset element that we are actually targetting
var form = document.querySelector('.note-ui');
var mapDiv = document.createElement('div');
mapDiv.classList.add('map');
//add the map div
form.appendChild(mapDiv);
//set up the mapbox gl map
mapboxgl.accessToken = 'pk.eyJ1Ijoiam9ubnliYXJuZXMiLCJhIjoiY2l2cDhjYW04MDAwcjJ0cG1uZnhqcm82ayJ9.qA2zeVA-nsoMh9IFrd5KQw';
var map = new mapboxgl.Map({
container: mapDiv,
style: 'mapbox://styles/mapbox/streets-v9',
center: [longitude, latitude],
zoom: 15
});
map.addControl(new mapboxgl.NavigationControl());
//create the current location marker
var el = document.createElement('div');
el.classList.add('marker');
//create the map style menu
var mapMenu = document.createElement('div');
mapMenu.classList.add('map-menu');
var streetsInput = document.createElement('input');
streetsInput.setAttribute('id', 'streets');
streetsInput.setAttribute('type', 'radio');
streetsInput.setAttribute('name', 'toggle');
streetsInput.setAttribute('value', 'streets');
streetsInput.setAttribute('checked', 'checked');
streetsInput.addEventListener('click', function () {
map.setStyle('mapbox://styles/mapbox/streets-v9');
});
var streetsLabel = document.createElement('label');
streetsLabel.setAttribute('for', 'streets');
streetsLabel.appendChild(document.createTextNode('Streets'));
var satelliteInput = document.createElement('input');
satelliteInput.setAttribute('id', 'satellite');
satelliteInput.setAttribute('type', 'radio');
satelliteInput.setAttribute('name', 'toggle');
satelliteInput.setAttribute('value', 'streets');
satelliteInput.addEventListener('click', function () {
map.setStyle('mapbox://styles/mapbox/satellite-v9');
});
var satelliteLabel = document.createElement('label');
satelliteLabel.setAttribute('for', 'satellite');
satelliteLabel.appendChild(document.createTextNode('Satellite'));
mapMenu.appendChild(streetsInput);
mapMenu.appendChild(streetsLabel);
mapMenu.appendChild(satelliteInput);
mapMenu.appendChild(satelliteLabel);
//add the map menu
mapDiv.appendChild(mapMenu);
//add a marker for the current location
new mapboxgl.Marker(el, {offset: [-10, -20]}).setLngLat([longitude, latitude]).addTo(map);
//create containing div for flexbox
var containingDiv = document.createElement('div');
//create the <select> element and give it a no location default
var selectEl = document.createElement('select');
selectEl.setAttribute('name', 'location');
var noLocation = document.createElement('option');
noLocation.setAttribute('value', 'no-location');
noLocation.appendChild(document.createTextNode('Dont send location'));
selectEl.appendChild(noLocation);
var geoLocation = document.createElement('option');
geoLocation.setAttribute('selected', 'selected');
geoLocation.setAttribute('id', 'option-coords');
geoLocation.setAttribute('value', 'geo:' + latitude + ',' + longitude);
geoLocation.dataset.latitude = latitude;
geoLocation.dataset.longitude = longitude;
geoLocation.appendChild(document.createTextNode('Send co-ordinates'));
selectEl.appendChild(geoLocation);
containingDiv.appendChild(selectEl);
form.insertBefore(containingDiv, mapDiv);
if (places !== null) {
//add the places both to the map and <select>
places.forEach(function (item) {
var option = document.createElement('option');
option.setAttribute('value', item[1]);
var text = document.createTextNode(item[0]);
option.appendChild(text);
option.dataset.latitude = item[2];
option.dataset.longitude = item[3];
selectEl.appendChild(option);
var placeMarkerIcon = document.createElement('div');
placeMarkerIcon.classList.add('marker');
new mapboxgl.Marker(placeMarkerIcon, {offset: [-10, -20]}).setLngLat([item[3], item[2]]).addTo(map);
placeMarkerIcon.addEventListener('click', function () {
map.flyTo({
center: [
item[3],
item[2]
]
});
selectPlace(item[1]);
});
});
//add an event listener
selectEl.addEventListener('change', function () {
if (selectEl.value !== 'no-location') {
var placeLat = selectEl[selectEl.selectedIndex].dataset.latitude;
var placeLon = selectEl[selectEl.selectedIndex].dataset.longitude;
map.flyTo({
center: [
placeLon,
placeLat
]
});
}
});
}
//add a button to add a new place
var newLocButton = document.createElement('button');
newLocButton.setAttribute('type', 'button');
newLocButton.setAttribute('id', 'create-new-place');
newLocButton.appendChild(document.createTextNode('Create New Place?'));
//the event listener
newLocButton.addEventListener('click', function() {
//add the form elements
var nameDiv = document.createElement('div');
var nameLabel = document.createElement('label');
nameLabel.setAttribute('for', 'place-name');
nameLabel.classList.add('place-label');
nameLabel.appendChild(document.createTextNode('Place Name:'));
var nameEl = document.createElement('input');
nameEl.setAttribute('placeholder', 'Name');
nameEl.setAttribute('name', 'place-name');
nameEl.setAttribute('id', 'place-name');
nameEl.setAttribute('type', 'text');
nameDiv.appendChild(nameLabel);
nameDiv.appendChild(nameEl);
var descDiv = document.createElement('div');
var descLabel = document.createElement('label');
descLabel.setAttribute('for', 'place-description');
descLabel.classList.add('place-label');
descLabel.appendChild(document.createTextNode('Place Description:'));
var descEl = document.createElement('input');
descEl.setAttribute('placeholder', 'Description');
descEl.setAttribute('name', 'place-description');
descEl.setAttribute('id', 'place-description');
descEl.setAttribute('type', 'text');
descDiv.appendChild(descLabel);
descDiv.appendChild(descEl);
var latDiv = document.createElement('div');
var latLabel = document.createElement('label');
latLabel.setAttribute('for', 'place-latitude');
latLabel.classList.add('place-label');
latLabel.appendChild(document.createTextNode('Place Latitude:'));
var latEl = document.createElement('input');
latEl.setAttribute('name', 'place-latitude');
latEl.setAttribute('id', 'place-latitude');
latEl.setAttribute('type', 'text');
latEl.value = getLatitudeFromMapbox(map.getCenter());
latDiv.appendChild(latLabel);
latDiv.appendChild(latEl);
var lonDiv = document.createElement('div');
var lonLabel = document.createElement('label');
lonLabel.setAttribute('for', 'place-longitude');
lonLabel.classList.add('place-label');
lonLabel.appendChild(document.createTextNode('Place Longitude:'));
var lonEl = document.createElement('input');
lonEl.setAttribute('name', 'place-longitude');
lonEl.setAttribute('id', 'place-longitude');
lonEl.setAttribute('type', 'text');
lonEl.value = getLongitudeFromMapbox(map.getCenter());
lonDiv.appendChild(lonLabel);
lonDiv.appendChild(lonEl);
var placeSubmit = document.createElement('button');
placeSubmit.setAttribute('id', 'place-submit');
placeSubmit.setAttribute('value', 'Submit New Place');
placeSubmit.setAttribute('name', 'place-submit');
placeSubmit.setAttribute('type', 'button');
placeSubmit.appendChild(document.createTextNode('Submit New Place'));
form.appendChild(nameDiv);
form.appendChild(descDiv);
form.appendChild(latDiv);
form.appendChild(lonDiv);
form.appendChild(placeSubmit);
//the event listener for the new place form
placeSubmit.addEventListener('click', function () {
//create the form data to send
var 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('/places/new', {
//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
//iterate through labels and remove parent div elements
var labels = document.querySelectorAll('.place-label');
for (var i = 0; i < labels.length; ++i) {
form.removeChild(labels[i].parentNode);
}
form.removeChild(document.querySelector('#place-submit'));
var 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);
//add place marker
var newOption = document.createElement('option');
newOption.setAttribute('value', placeJson.uri);
newOption.appendChild(document.createTextNode(placeJson.name));
newOption.dataset.latitude = placeJson.latitude;
newOption.dataset.longitude = placeJson.longitude;
selectEl.appendChild(newOption);
var newPlaceMarkerIcon = document.createElement('div');
newPlaceMarkerIcon.classList.add('marker');
new mapboxgl.Marker(newPlaceMarkerIcon, {offset: [-10, -20]}).setLngLat([placeJson.longitude, placeJson.latitude]).addTo(map);
map.flyTo({center: [placeJson.longitude, placeJson.latitude]});
newPlaceMarkerIcon.addEventListener('click', function () {
map.flyTo({center: [placeJson.longitude, placeJson.latitude]});
selectPlace(placeJson.uri);
});
//make selected
selectPlace(placeJson.uri);
}).catch(function (placeError) {
alertify.reset();
alertify.error(placeError);
});
});
});
containingDiv.appendChild(newLocButton);
}
function parseLocation(point) {
var re = /\((.*)\)/;
var resultArray = re.exec(point);
var location = resultArray[1].split(' ');
return [location[1], location[0]];
}
function selectPlace(uri) {
document.querySelector('select [value="' + uri + '"]').selected = true;
}
function getLatitudeFromMapbox(lnglat) {
var resultArray = /\((.*)\)/.exec(lnglat);
var location = resultArray[1].split(' ');
return location[1];
}
function getLongitudeFromMapbox(lnglat) {
var resultArray = /\((.*)\)/.exec(lnglat);
var location = resultArray[1].split(' ');
return location[0].replace(',', '');
}

View file

@ -1,44 +0,0 @@
/* global L */
var button = document.querySelector('#locate');
if (button.addEventListener) {
button.addEventListener('click', getLocation);
} else {
button.attachEvent('onclick', getLocation);
}
function getLocation() {
if ('geolocation' in navigator) {
navigator.geolocation.getCurrentPosition(function(position) {
updateForm(position.coords.latitude, position.coords.longitude);
addMap(position.coords.latitude, position.coords.longitude);
});
}
}
function updateForm(latitude, longitude) {
var inputLatitude = document.querySelector('#latitude');
var inputLongitude = document.querySelector('#longitude');
inputLatitude.value = latitude;
inputLongitude.value = longitude;
}
function addMap(latitude, longitude) {
var form = document.querySelector('form');
var div = document.createElement('div');
div.setAttribute('id', 'map');
form.appendChild(div);
L.mapbox.accessToken = 'pk.eyJ1Ijoiam9ubnliYXJuZXMiLCJhIjoiVlpndW1EYyJ9.aP9fxAqLKh7lj0LpFh5k1w';
var map = L.mapbox.map('map', 'jonnybarnes.gnoihnim')
.setView([latitude, longitude], 15)
.addLayer(L.mapbox.tileLayer('jonnybarnes.gnoihnim', {
detectRetina: true
}));
var marker = L.marker([latitude, longitude], {
draggable: true
}).addTo(map);
marker.on('dragend', function () {
var markerLocation = marker.getLatLng();
updateForm(markerLocation.lat, markerLocation.lng);
});
}