Move js libs into own sub-dir, change corresponding links in views, and re-version/re-comporess and delete old files

This commit is contained in:
Jonny Barnes 2016-06-14 18:04:56 +01:00
parent 4c1997827a
commit 6df4a30b0a
78 changed files with 163 additions and 159 deletions

View file

@ -0,0 +1,69 @@
var feature = {
addEventListener : !!window.addEventListener,
querySelectorAll : !!document.querySelectorAll
};
if(feature.addEventListener && feature.querySelectorAll) {
init();
}
function init() {
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;
}
}

Binary file not shown.

Binary file not shown.

View file

@ -1,69 +0,0 @@
var feature = {
addEventListener : !!window.addEventListener,
querySelectorAll : !!document.querySelectorAll,
};
if(feature.addEventListener && feature.querySelectorAll) {
this.init();
}
function init() {
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;
}
}

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,25 @@
//the autlinker object
var autolinker = new Autolinker();
//the youtube regex
var ytidregex = /watch\?v=([A-Za-z0-9\-_]+)/;
//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 id = ytid[1];
var iframe = document.createElement('iframe');
iframe.classList.add('youtube');
iframe.setAttribute('src', '//www.youtube.com/embed/' + id);
iframe.setAttribute('frameborder', 0);
iframe.setAttribute('allowfullscreen', 'true');
notes[i].appendChild(iframe);
}
//now linkify everything
var orig = notes[i].innerHTML;
var linked = autolinker.link(orig);
notes[i].innerHTML = linked;
}

Binary file not shown.

Binary file not shown.

View file

@ -1,25 +0,0 @@
//the autlinker object
var autolinker = new Autolinker();
//the youtube regex
var ytidregex = /watch\?v=([A-Za-z0-9\-_]+)/;
//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 id = ytid[1];
var iframe = document.createElement('iframe');
iframe.classList.add('youtube');
iframe.setAttribute('src', '//www.youtube.com/embed/' + id);
iframe.setAttribute('frameborder', 0);
iframe.setAttribute('allowfullscreen', 'true');
notes[i].appendChild(iframe);
}
//now linkify everything
var orig = notes[i].innerHTML;
var linked = autolinker.link(orig);
notes[i].innerHTML = linked;
}

View file

@ -1,6 +1,6 @@
//This code runs on page load and looks for <div class="map">, then adds map
var mapDivs = document.querySelectorAll('.map');
for(var i = 0; i < mapDivs.length; i++) {
for (var i = 0; i < mapDivs.length; i++) {
var mapDiv = mapDivs[i];
var latitude = mapDiv.dataset.latitude;
var longitude = mapDiv.dataset.longitude;
@ -8,8 +8,8 @@ for(var i = 0; i < mapDivs.length; i++) {
var map = L.mapbox.map(mapDiv, 'jonnybarnes.gnoihnim')
.setView([latitude, longitude], 15)
.addLayer(L.mapbox.tileLayer('jonnybarnes.gnoihnim', {
detectRetina: true,
}));
var marker = L.marker([latitude, longitude]).addTo(map);
detectRetina: true
}));
L.marker([latitude, longitude]).addTo(map);
map.scrollWheelZoom.disable();
}

Binary file not shown.

Binary file not shown.

View file

@ -39,7 +39,7 @@ function addPlaces(latitude, longitude) {
addMap(latitude, longitude);
}
}).catch(function (err) {
console.log(err);
console.error(err);
});
}
@ -57,11 +57,11 @@ function addMap(latitude, longitude, places) {
var map = L.mapbox.map('map', 'jonnybarnes.gnoihnim')
.setView([latitude, longitude], 15)
.addLayer(L.mapbox.tileLayer('jonnybarnes.gnoihnim', {
detectRetina: true,
detectRetina: true
}));
//add a marker for the current location
var marker = L.marker([latitude, longitude], {
draggable: true,
draggable: true
}).addTo(map);
//when the location marker is dragged, if the new place form elements exist
//update the lat/lng values
@ -87,7 +87,7 @@ function addMap(latitude, longitude, places) {
form.insertBefore(selectEl, div);
if (places !== null) {
//add the places both to the map and <select>
places.forEach(function (item, index, array) {
places.forEach(function (item) {
var option = document.createElement('option');
option.setAttribute('value', item[1]);
var text = document.createTextNode(item[0]);
@ -106,7 +106,7 @@ function addMap(latitude, longitude, places) {
placeMarker.bindPopup(name, {
closeButton: true
});
placeMarker.on('click', function (e) {
placeMarker.on('click', function () {
map.panTo([item[2], item[3]]);
selectPlace(item[1]);
});
@ -130,7 +130,7 @@ function addMap(latitude, longitude, places) {
//add the form elements
var nameLabel = document.createElement('label');
nameLabel.setAttribute('for', 'place-name');
nameLabel.classList.add('place-label')
nameLabel.classList.add('place-label');
nameLabel.appendChild(document.createTextNode('Place Name:'));
var nameEl = document.createElement('input');
nameEl.setAttribute('placeholder', 'Name');
@ -206,8 +206,8 @@ function addMap(latitude, longitude, places) {
form.removeChild(document.querySelector('#place-latitude'));
form.removeChild(document.querySelector('#place-longitude'));
var labels = document.querySelectorAll('.place-label');
for (var label of labels) {
form.removeChild(label);
for (i = 0; i < labels.length; ++i) {
form.removeChild(labels[i]);
}
form.removeChild(document.querySelector('#place-submit'));
form.removeChild(document.querySelector('#create-new-place'));
@ -231,16 +231,16 @@ function addMap(latitude, longitude, places) {
newPlaceMarker.bindPopup(newName, {
closeButton: true
});
newPlaceMarker.on('click', function (e) {
newPlaceMarker.on('click', function () {
map.panTo([placeJson['latitude'], placeJson['longitude']]);
selectPlace(slug);
});
//make selected
selectPlace(slug);
}).catch(function (placeError) {
console.log(placeError);
console.error(placeError);
});
})
});
});
form.insertBefore(newLocButton, div);
}

Binary file not shown.

Binary file not shown.

View file

@ -12,8 +12,6 @@ function getLocation() {
updateForm(position.coords.latitude, position.coords.longitude);
addMap(position.coords.latitude, position.coords.longitude);
});
} else {
console.log('I need to do something when geoloaction isnt available.');
}
}
@ -33,10 +31,10 @@ function addMap(latitude, longitude) {
var map = L.mapbox.map('map', 'jonnybarnes.gnoihnim')
.setView([latitude, longitude], 15)
.addLayer(L.mapbox.tileLayer('jonnybarnes.gnoihnim', {
detectRetina: true,
detectRetina: true
}));
var marker = L.marker([latitude, longitude], {
draggable: true,
draggable: true
}).addTo(map);
marker.on('dragend', function () {
var markerLocation = marker.getLatLng();

Binary file not shown.

Binary file not shown.