aboutsummaryrefslogtreecommitdiffstats
path: root/web/js
diff options
context:
space:
mode:
Diffstat (limited to 'web/js')
-rw-r--r--web/js/front.js13
-rw-r--r--web/js/geolocation.js42
2 files changed, 55 insertions, 0 deletions
diff --git a/web/js/front.js b/web/js/front.js
new file mode 100644
index 000000000..d2c814490
--- /dev/null
+++ b/web/js/front.js
@@ -0,0 +1,13 @@
+document.getElementById('pc').focus();
+
+(function(){
+ var around_forms = document.querySelectorAll('form[action*="around"]');
+ for (var i=0; i<around_forms.length; i++) {
+ var form = around_forms[i];
+ var el = document.createElement('input');
+ el.type = 'hidden';
+ el.name = 'js';
+ el.value = 1;
+ form.insertBefore(el, form.firstChild);
+ }
+})();
diff --git a/web/js/geolocation.js b/web/js/geolocation.js
new file mode 100644
index 000000000..5ff9fe9dc
--- /dev/null
+++ b/web/js/geolocation.js
@@ -0,0 +1,42 @@
+var fixmystreet = fixmystreet || {};
+
+fixmystreet.geolocate = function(element, success_callback) {
+ element.addEventListener('click', function(e) {
+ var link = this;
+ e.preventDefault();
+ link.className += ' loading';
+ navigator.geolocation.getCurrentPosition(function(pos) {
+ link.className = link.className.replace(/loading/, ' ');
+ success_callback(pos);
+ }, function(err) {
+ link.className = link.className.replace(/loading/, ' ');
+ if (err.code === 1) { // User said no
+ link.innerHTML = translation_strings.geolocation_declined;
+ } else if (err.code === 2) { // No position
+ link.innerHTML = translation_strings.geolocation_no_position;
+ } else if (err.code === 3) { // Too long
+ link.innerHTML = translation_strings.geolocation_no_result;
+ } else { // Unknown
+ link.innerHTML = translation_strings.geolocation_unknown;
+ }
+ }, {
+ enableHighAccuracy: true,
+ timeout: 10000
+ });
+ });
+};
+
+(function(){
+ var link = document.getElementById('geolocate_link');
+ if (!link) { return; }
+ if ('geolocation' in navigator) {
+ fixmystreet.geolocate(link, function(pos) {
+ var latitude = pos.coords.latitude.toFixed(6);
+ var longitude = pos.coords.longitude.toFixed(6);
+ var coords = 'latitude=' + latitude + ';longitude=' + longitude;
+ location.href = link.href + (link.href.indexOf('?') > -1 ? ';' : '?') + coords;
+ });
+ } else {
+ link.style.display = 'none';
+ }
+})();