diff options
author | Evan Prodromou <evan@status.net> | 2009-12-31 09:14:55 -1000 |
---|---|---|
committer | Evan Prodromou <evan@status.net> | 2009-12-31 09:14:55 -1000 |
commit | 053b8c600d7db73ec19e5f1d3e26c4c98fdf3d8c (patch) | |
tree | 5664c78f951e91827c810b745a771aeb21ab9dbf /js/util.js | |
parent | ad8ea98cd72855f61c71945b533331b6f30d04b6 (diff) | |
parent | 01dbee2ba5280d97ddd0bb82217e8b3e7680e67b (diff) |
Merge branch '0.9.x' of git@gitorious.org:statusnet/mainline into 0.9.x
Diffstat (limited to 'js/util.js')
-rw-r--r-- | js/util.js | 80 |
1 files changed, 75 insertions, 5 deletions
diff --git a/js/util.js b/js/util.js index 0987c6cc0..dd7a74a7a 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,78 @@ 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').length > 0) { + var NLE = $('#notice_data-location_wrap'); + var geocodeURL = NLE.attr('title'); + + NLE.insertAfter('#'+SN.C.S.FormNotice+' fieldset'); + + if (navigator.geolocation) { + NLE.change(function() { + NLE.removeAttr('title'); + + $.cookie(SN.C.S.NoticeLocationCookieName, $('#notice_data-location_enabled').attr('checked')); + + var NLN = $('#'+SN.C.S.NoticeLocationName); + if (NLN.length > 0) { + NLN.remove(); + } + + NLE.prepend('<span id="'+SN.C.S.NoticeLocationName+'">Geo</span>'); + NLN = $('#'+SN.C.S.NoticeLocationName); + + if ($('#notice_data-location_enabled').attr('checked') === true) { + NLN.show(); + NLN.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(geocodeURL, data, function(location) { + NLN.replaceWith('<a id="notice_data-location_name"/>'); + NLN = $('#'+SN.C.S.NoticeLocationName); + + 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') { + NLN_text = position.coords.latitude + ';' + position.coords.longitude; + } + else { + NLN_text = location.name; + } + + NLN.attr('href', location.url); + NLN.text(NLN_text); + }); + }); + } + else { + NLN.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')); + NLE.change(); + } + } }, NewDirectMessage: function() { |