From 98ce7daf5650ebd7e6f6bbaca6e57069ffccae55 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Tue, 29 Dec 2009 16:17:17 -0500 Subject: Implement user interface for user to preview what location they are sharing with a notice --- js/util.js | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) (limited to 'js/util.js') diff --git a/js/util.js b/js/util.js index 0987c6cc0..f52c70ba4 100644 --- a/js/util.js +++ b/js/util.js @@ -50,7 +50,9 @@ var SN = { // StatusNet NoticeLat: 'notice_data-lat', NoticeLon: 'notice_data-lon', NoticeLocationId: 'notice_data-location_id', - NoticeLocationNs: 'notice_data-location_ns' + NoticeLocationNs: 'notice_data-location_ns', + NoticeLocationName: 'notice_data-location_name', + NoticeLocationCookieName: 'location_enabled' } }, @@ -436,10 +438,44 @@ var SN = { // StatusNet }, NoticeLocationAttach: function() { - if(navigator.geolocation) navigator.geolocation.watchPosition(function(position) { - $('#'+SN.C.S.NoticeLat).val(position.coords.latitude); - $('#'+SN.C.S.NoticeLon).val(position.coords.longitude); - }); + if($('#notice_data-location_enabled').size()) { + if(navigator.geolocation) { + $('#notice_data-location_enabled').change(function() { + $.cookie(SN.C.S.NoticeLocationCookieName, $('#notice_data-location_enabled').attr('checked')); + if($('#notice_data-location_enabled').attr('checked')) { + $('#'+SN.C.S.NoticeLocationName).show(); + $('#'+SN.C.S.NoticeLocationName).addClass('processing'); + navigator.geolocation.getCurrentPosition(function(position) { + $('#'+SN.C.S.NoticeLat).val(position.coords.latitude); + $('#'+SN.C.S.NoticeLon).val(position.coords.longitude); + var data = {'lat': position.coords.latitude,'lon': position.coords.longitude, 'token': $('#token').val()}; + $.getJSON($('#notice_data-location_enabled_container').attr('data-geocode-url'), data,function(location) { + $('#'+SN.C.S.NoticeLocationName).removeClass('processing'); + if(typeof(location.location_ns)!="undefined") $('#'+SN.C.S.NoticeLocationNs).val(location.location_ns); + if(typeof(location.location_id)!="undefined") $('#'+SN.C.S.NoticeLocationId).val(location.location_id); + if(typeof(location.name)=="undefined") { + $('#'+SN.C.S.NoticeLocationName).text(position.coords.latitude + ' ' + position.coords.longitude); + } else { + $('#'+SN.C.S.NoticeLocationName).text(location.name); + $('#'+SN.C.S.NoticeLocationName).attr('href',location.url); + } + }); + }); + } else { + $('#'+SN.C.S.NoticeLocationName).hide(); + $('#'+SN.C.S.NoticeLat).val(""); + $('#'+SN.C.S.NoticeLon).val(""); + $('#'+SN.C.S.NoticeLocationNs).val(""); + $('#'+SN.C.S.NoticeLocationId).val(""); + } + }); + var cookieVal = $.cookie(SN.C.S.NoticeLocationCookieName); + $('#notice_data-location_enabled').attr('checked',(cookieVal == null || cookieVal == 'true')); + $('#notice_data-location_enabled').change(); + } else { + $('#notice_data-location_enabled_container').remove(); + } + } }, NewDirectMessage: function() { -- cgit v1.2.3-54-g00ecf