diff options
-rw-r--r-- | templates/web/base/alert/index.html | 3 | ||||
-rw-r--r-- | templates/web/base/common_scripts.html | 18 | ||||
-rw-r--r-- | templates/web/base/report/_inspect.html | 2 | ||||
-rw-r--r-- | web/cobrands/fixmystreet.com/layout.scss | 3 | ||||
-rw-r--r-- | web/cobrands/fixmystreet/fixmystreet.js | 47 | ||||
-rw-r--r-- | web/cobrands/fixmystreet/staff.js | 3 | ||||
-rw-r--r-- | web/cobrands/sass/_base.scss | 10 | ||||
-rw-r--r-- | web/cobrands/sass/_layout.scss | 3 | ||||
-rw-r--r-- | web/js/geolocation.js | 41 |
9 files changed, 79 insertions, 51 deletions
diff --git a/templates/web/base/alert/index.html b/templates/web/base/alert/index.html index 38ed6f6f5..1442e6bdc 100644 --- a/templates/web/base/alert/index.html +++ b/templates/web/base/alert/index.html @@ -1,4 +1,5 @@ -[% INCLUDE 'header.html', title = loc('Local RSS feeds and email alerts'), bodyclass = 'fullwidthpage' %] +[% SET bodyclass = 'alertpage fullwidthpage' %] +[% INCLUDE 'header.html', title = loc('Local RSS feeds and email alerts') %] <h1>[% loc('Local RSS feeds and email alerts') %]</h1> diff --git a/templates/web/base/common_scripts.html b/templates/web/base/common_scripts.html index cecf9da5b..b04404f06 100644 --- a/templates/web/base/common_scripts.html +++ b/templates/web/base/common_scripts.html @@ -12,7 +12,18 @@ scripts.push( version('/cobrands/fixmystreet/fixmystreet.js'), ); -IF NOT bodyclass.match('frontpage'); +SET geolocation_loaded = 0; +IF bodyclass.match('frontpage'); + SET geolocation_loaded = 1; + scripts.push( + version('/js/geolocation.js'), + ); +ELSIF bodyclass.match('alertpage'); + SET geolocation_loaded = 1; + scripts.push( + version('/js/geolocation.js'), + ); +ELSE; scripts.push( version('/js/validation_rules.js'), version('/vendor/jquery.validate.min.js'), @@ -24,6 +35,11 @@ FOR script IN extra_js; END; IF c.user_exists AND (c.user.from_body OR c.user.is_superuser); + IF NOT geolocation_loaded; + scripts.push( + version('/js/geolocation.js'), + ); + END; scripts.push( version('/cobrands/fixmystreet/staff.js') ); diff --git a/templates/web/base/report/_inspect.html b/templates/web/base/report/_inspect.html index e4e3ac9e6..5088332ce 100644 --- a/templates/web/base/report/_inspect.html +++ b/templates/web/base/report/_inspect.html @@ -44,7 +44,7 @@ <a target="_blank" href="https://www.google.com/maps/dir/Current+Location/[% problem.latitude %],[% problem.longitude %]" class="btn btn--block btn--navigate">[% loc('Navigate to this problem') %]</a> </p> <p> - <a href="#" class="btn btn--block btn--geolocate" id="geolocate_link">[% loc('Set to my current location') %]</a> + <a href="#" class="btn btn--block btn--geolocate">[% loc('Set to my current location') %]</a> </p> </div> diff --git a/web/cobrands/fixmystreet.com/layout.scss b/web/cobrands/fixmystreet.com/layout.scss index 46ff83274..e42dbacf7 100644 --- a/web/cobrands/fixmystreet.com/layout.scss +++ b/web/cobrands/fixmystreet.com/layout.scss @@ -160,6 +160,9 @@ body.fullwidthpage { background-size: 22px 34px; } } + a#geolocate_link.loading { + background: url("/cobrands/fixmystreet/images/spinner-yellow.gif") 100% 33% no-repeat + } } } diff --git a/web/cobrands/fixmystreet/fixmystreet.js b/web/cobrands/fixmystreet/fixmystreet.js index 1333517ac..84dc4b112 100644 --- a/web/cobrands/fixmystreet/fixmystreet.js +++ b/web/cobrands/fixmystreet/fixmystreet.js @@ -205,40 +205,6 @@ fixmystreet.resize_to = { } }; -fixmystreet.geolocate = { - setup: function(success_callback) { - $('#geolocate_link').click(function(e) { - var $link = $(this); - e.preventDefault(); - // Spinny thing! - if ($('.mobile').length) { - $link.append(' <img src="/cobrands/fixmystreet/images/spinner-black.gif" alt="" align="bottom">'); - } else { - var spincolor = $('<span>').css("color","white").css("color") === $('#front-main').css("background-color") ? 'white' : 'yellow'; - $link.append(' <img src="/cobrands/fixmystreet/images/spinner-' + spincolor + '.gif" alt="" align="bottom">'); - } - navigator.geolocation.getCurrentPosition(function(pos) { - $link.find('img').remove(); - success_callback(pos); - }, function(err) { - $link.find('img').remove(); - if (err.code === 1) { // User said no - $link.html(translation_strings.geolocation_declined); - } else if (err.code === 2) { // No position - $link.html(translation_strings.geolocation_no_position); - } else if (err.code === 3) { // Too long - $link.html(translation_strings.geolocation_no_result); - } else { // Unknown - $link.html(translation_strings.geolocation_unknown); - } - }, { - enableHighAccuracy: true, - timeout: 10000 - }); - }); - } -}; - fixmystreet.update_list_item_buttons = function($list) { if (!$list) { return; @@ -410,19 +376,6 @@ $.extend(fixmystreet.set_up, { }); }, - report_geolocation: function() { - if ('geolocation' in navigator) { - fixmystreet.geolocate.setup(function(pos) { - var latitude = pos.coords.latitude; - var longitude = pos.coords.longitude; - var page = $('#geolocate_link').attr('href'); - location.href = page + '?latitude=' + latitude + ';longitude=' + longitude; - }); - } else { - $('#geolocate_link').hide(); - } - }, - category_change: function() { // Deal with changes to report category. diff --git a/web/cobrands/fixmystreet/staff.js b/web/cobrands/fixmystreet/staff.js index ffc529250..f1e07ed6b 100644 --- a/web/cobrands/fixmystreet/staff.js +++ b/web/cobrands/fixmystreet/staff.js @@ -314,7 +314,8 @@ $.extend(fixmystreet.set_up, { } if ('geolocation' in navigator) { - fixmystreet.geolocate.setup(function(pos) { + var el = document.querySelector('.btn--geolocate'); + fixmystreet.geolocate(el, function(pos) { var latlon = new OpenLayers.LonLat(pos.coords.longitude, pos.coords.latitude); var bng = latlon.clone().transform( new OpenLayers.Projection("EPSG:4326"), diff --git a/web/cobrands/sass/_base.scss b/web/cobrands/sass/_base.scss index 016967457..34fa74200 100644 --- a/web/cobrands/sass/_base.scss +++ b/web/cobrands/sass/_base.scss @@ -1957,11 +1957,21 @@ label .muted { background:#2a2a2a; } } + a#geolocate_link.loading { + background: #1a1a1a url("/cobrands/fixmystreet/images/spinner-black.gif") 100% 50% no-repeat; + border-right: solid 0.5em #1a1a1a; + padding-right: 1.5em; + } } .no-js #geolocate_link { display: none !important; } +a#geolocate_link.loading, .btn--geolocate.loading { + background: url("/cobrands/fixmystreet/images/spinner-white.gif") 100% 50% no-repeat; + padding-right: 1.5em; +} + #front-howto { #front_stats { display:table; diff --git a/web/cobrands/sass/_layout.scss b/web/cobrands/sass/_layout.scss index fce99c3de..a7f6bbd9a 100644 --- a/web/cobrands/sass/_layout.scss +++ b/web/cobrands/sass/_layout.scss @@ -912,6 +912,9 @@ textarea.form-error { background:none; } } + a#geolocate_link.loading { + border-right: none; + } } .ie7 #front-main { #postcodeForm { diff --git a/web/js/geolocation.js b/web/js/geolocation.js new file mode 100644 index 000000000..a5c229c19 --- /dev/null +++ b/web/js/geolocation.js @@ -0,0 +1,41 @@ +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; + var longitude = pos.coords.longitude; + location.href = link.href + '?latitude=' + latitude + ';longitude=' + longitude; + }); + } else { + link.style.display = 'none'; + } +})(); |