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/jquery.cookie.js | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++ js/util.js | 46 ++++++++++++++++++++++--- 2 files changed, 137 insertions(+), 5 deletions(-) create mode 100644 js/jquery.cookie.js (limited to 'js') diff --git a/js/jquery.cookie.js b/js/jquery.cookie.js new file mode 100644 index 000000000..6df1faca2 --- /dev/null +++ b/js/jquery.cookie.js @@ -0,0 +1,96 @@ +/** + * Cookie plugin + * + * Copyright (c) 2006 Klaus Hartl (stilbuero.de) + * Dual licensed under the MIT and GPL licenses: + * http://www.opensource.org/licenses/mit-license.php + * http://www.gnu.org/licenses/gpl.html + * + */ + +/** + * Create a cookie with the given name and value and other optional parameters. + * + * @example $.cookie('the_cookie', 'the_value'); + * @desc Set the value of a cookie. + * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true }); + * @desc Create a cookie with all available options. + * @example $.cookie('the_cookie', 'the_value'); + * @desc Create a session cookie. + * @example $.cookie('the_cookie', null); + * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain + * used when the cookie was set. + * + * @param String name The name of the cookie. + * @param String value The value of the cookie. + * @param Object options An object literal containing key/value pairs to provide optional cookie attributes. + * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object. + * If a negative value is specified (e.g. a date in the past), the cookie will be deleted. + * If set to null or omitted, the cookie will be a session cookie and will not be retained + * when the the browser exits. + * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie). + * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie). + * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will + * require a secure protocol (like HTTPS). + * @type undefined + * + * @name $.cookie + * @cat Plugins/Cookie + * @author Klaus Hartl/klaus.hartl@stilbuero.de + */ + +/** + * Get the value of a cookie with the given name. + * + * @example $.cookie('the_cookie'); + * @desc Get the value of a cookie. + * + * @param String name The name of the cookie. + * @return The value of the cookie. + * @type String + * + * @name $.cookie + * @cat Plugins/Cookie + * @author Klaus Hartl/klaus.hartl@stilbuero.de + */ +jQuery.cookie = function(name, value, options) { + if (typeof value != 'undefined') { // name and value given, set cookie + options = options || {}; + if (value === null) { + value = ''; + options.expires = -1; + } + var expires = ''; + if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { + var date; + if (typeof options.expires == 'number') { + date = new Date(); + date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); + } else { + date = options.expires; + } + expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE + } + // CAUTION: Needed to parenthesize options.path and options.domain + // in the following expressions, otherwise they evaluate to undefined + // in the packed version for some reason... + var path = options.path ? '; path=' + (options.path) : ''; + var domain = options.domain ? '; domain=' + (options.domain) : ''; + var secure = options.secure ? '; secure' : ''; + document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); + } else { // only name given, get cookie + var cookieValue = null; + if (document.cookie && document.cookie != '') { + var cookies = document.cookie.split(';'); + for (var i = 0; i < cookies.length; i++) { + var cookie = jQuery.trim(cookies[i]); + // Does this cookie string begin with the name we want? + if (cookie.substring(0, name.length + 1) == (name + '=')) { + cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); + break; + } + } + } + return cookieValue; + } +}; \ No newline at end of file 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 From 552de999bfe660cbf88eb9b1ce19e55b2f6b3d92 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Tue, 29 Dec 2009 16:19:33 -0500 Subject: Revert "Drop the Google Client API-based AJAX geolocation lookup shim -- it fails to ask for user permission, causing us quite a bit of difficulty." This reverts commit 749b8b5b8ca4d1c39d350879aadddbdb9d8b71d5. --- js/geometa.js | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 118 insertions(+), 5 deletions(-) (limited to 'js') diff --git a/js/geometa.js b/js/geometa.js index 87e3c99a1..21deb1885 100644 --- a/js/geometa.js +++ b/js/geometa.js @@ -1,4 +1,4 @@ -// A shim to implement the W3C Geolocation API Specification using Gears +// A shim to implement the W3C Geolocation API Specification using Gears or the Ajax API if (typeof navigator.geolocation == "undefined" || navigator.geolocation.shim ) (function(){ // -- BEGIN GEARS_INIT @@ -96,9 +96,122 @@ var GearsGeoLocation = (function() { }; }); -// If you have Gears installed use that -if (window.google && google.gears) { - navigator.geolocation = GearsGeoLocation(); -} +var AjaxGeoLocation = (function() { + // -- PRIVATE + var loading = false; + var loadGoogleLoader = function() { + if (!hasGoogleLoader() && !loading) { + loading = true; + var s = document.createElement('script'); + s.src = (document.location.protocol == "https:"?"https://":"http://") + 'www.google.com/jsapi?callback=_google_loader_apiLoaded'; + s.type = "text/javascript"; + document.getElementsByTagName('body')[0].appendChild(s); + } + }; + + var queue = []; + var addLocationQueue = function(callback) { + queue.push(callback); + } + + var runLocationQueue = function() { + if (hasGoogleLoader()) { + while (queue.length > 0) { + var call = queue.pop(); + call(); + } + } + } + + window['_google_loader_apiLoaded'] = function() { + runLocationQueue(); + } + + var hasGoogleLoader = function() { + return (window['google'] && google['loader']); + } + + var checkGoogleLoader = function(callback) { + if (hasGoogleLoader()) return true; + + addLocationQueue(callback); + + loadGoogleLoader(); + + return false; + }; + + loadGoogleLoader(); // start to load as soon as possible just in case + + // -- PUBLIC + return { + shim: true, + + type: "ClientLocation", + + lastPosition: null, + + getCurrentPosition: function(successCallback, errorCallback, options) { + var self = this; + if (!checkGoogleLoader(function() { + self.getCurrentPosition(successCallback, errorCallback, options); + })) return; + + if (google.loader.ClientLocation) { + var cl = google.loader.ClientLocation; + + var position = { + coords: { + latitude: cl.latitude, + longitude: cl.longitude, + altitude: null, + accuracy: 43000, // same as Gears accuracy over wifi? + altitudeAccuracy: null, + heading: null, + speed: null, + }, + // extra info that is outside of the bounds of the core API + address: { + city: cl.address.city, + country: cl.address.country, + country_code: cl.address.country_code, + region: cl.address.region + }, + timestamp: new Date() + }; + + successCallback(position); + + this.lastPosition = position; + } else if (errorCallback === "function") { + errorCallback({ code: 3, message: "Using the Google ClientLocation API and it is not able to calculate a location."}); + } + }, + + watchPosition: function(successCallback, errorCallback, options) { + this.getCurrentPosition(successCallback, errorCallback, options); + + var self = this; + var watchId = setInterval(function() { + self.getCurrentPosition(successCallback, errorCallback, options); + }, 10000); + + return watchId; + }, + + clearWatch: function(watchId) { + clearInterval(watchId); + }, + + getPermission: function(siteName, imageUrl, extraMessage) { + // for now just say yes :) + return true; + } + + }; +}); + +// If you have Gears installed use that, else use Ajax ClientLocation +navigator.geolocation = (window.google && google.gears) ? GearsGeoLocation() : AjaxGeoLocation(); })(); -- cgit v1.2.3-54-g00ecf From 2cfa90c75203d95c859e8da2c4d9dbd6afe43500 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Tue, 29 Dec 2009 17:12:52 -0500 Subject: Revert "Revert "Drop the Google Client API-based AJAX geolocation lookup shim -- it fails to ask for user permission, causing us quite a bit of difficulty."" This reverts commit 552de999bfe660cbf88eb9b1ce19e55b2f6b3d92. Playing a bit of back-and-forth with this one :-) --- js/geometa.js | 123 +++------------------------------------------------------- 1 file changed, 5 insertions(+), 118 deletions(-) (limited to 'js') diff --git a/js/geometa.js b/js/geometa.js index 21deb1885..87e3c99a1 100644 --- a/js/geometa.js +++ b/js/geometa.js @@ -1,4 +1,4 @@ -// A shim to implement the W3C Geolocation API Specification using Gears or the Ajax API +// A shim to implement the W3C Geolocation API Specification using Gears if (typeof navigator.geolocation == "undefined" || navigator.geolocation.shim ) (function(){ // -- BEGIN GEARS_INIT @@ -96,122 +96,9 @@ var GearsGeoLocation = (function() { }; }); -var AjaxGeoLocation = (function() { - // -- PRIVATE - var loading = false; - var loadGoogleLoader = function() { - if (!hasGoogleLoader() && !loading) { - loading = true; - var s = document.createElement('script'); - s.src = (document.location.protocol == "https:"?"https://":"http://") + 'www.google.com/jsapi?callback=_google_loader_apiLoaded'; - s.type = "text/javascript"; - document.getElementsByTagName('body')[0].appendChild(s); - } - }; - - var queue = []; - var addLocationQueue = function(callback) { - queue.push(callback); - } - - var runLocationQueue = function() { - if (hasGoogleLoader()) { - while (queue.length > 0) { - var call = queue.pop(); - call(); - } - } - } - - window['_google_loader_apiLoaded'] = function() { - runLocationQueue(); - } - - var hasGoogleLoader = function() { - return (window['google'] && google['loader']); - } - - var checkGoogleLoader = function(callback) { - if (hasGoogleLoader()) return true; - - addLocationQueue(callback); - - loadGoogleLoader(); - - return false; - }; - - loadGoogleLoader(); // start to load as soon as possible just in case - - // -- PUBLIC - return { - shim: true, - - type: "ClientLocation", - - lastPosition: null, - - getCurrentPosition: function(successCallback, errorCallback, options) { - var self = this; - if (!checkGoogleLoader(function() { - self.getCurrentPosition(successCallback, errorCallback, options); - })) return; - - if (google.loader.ClientLocation) { - var cl = google.loader.ClientLocation; - - var position = { - coords: { - latitude: cl.latitude, - longitude: cl.longitude, - altitude: null, - accuracy: 43000, // same as Gears accuracy over wifi? - altitudeAccuracy: null, - heading: null, - speed: null, - }, - // extra info that is outside of the bounds of the core API - address: { - city: cl.address.city, - country: cl.address.country, - country_code: cl.address.country_code, - region: cl.address.region - }, - timestamp: new Date() - }; - - successCallback(position); - - this.lastPosition = position; - } else if (errorCallback === "function") { - errorCallback({ code: 3, message: "Using the Google ClientLocation API and it is not able to calculate a location."}); - } - }, - - watchPosition: function(successCallback, errorCallback, options) { - this.getCurrentPosition(successCallback, errorCallback, options); - - var self = this; - var watchId = setInterval(function() { - self.getCurrentPosition(successCallback, errorCallback, options); - }, 10000); - - return watchId; - }, - - clearWatch: function(watchId) { - clearInterval(watchId); - }, - - getPermission: function(siteName, imageUrl, extraMessage) { - // for now just say yes :) - return true; - } - - }; -}); - -// If you have Gears installed use that, else use Ajax ClientLocation -navigator.geolocation = (window.google && google.gears) ? GearsGeoLocation() : AjaxGeoLocation(); +// If you have Gears installed use that +if (window.google && google.gears) { + navigator.geolocation = GearsGeoLocation(); +} })(); -- cgit v1.2.3-54-g00ecf From 5103cb670a93a2f03e56230f50b8abe754b019d9 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Thu, 31 Dec 2009 16:15:24 +0000 Subject: length is faster than size() --- js/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js') diff --git a/js/util.js b/js/util.js index f52c70ba4..46efe92ff 100644 --- a/js/util.js +++ b/js/util.js @@ -438,7 +438,7 @@ var SN = { // StatusNet }, NoticeLocationAttach: function() { - if($('#notice_data-location_enabled').size()) { + if ($('#notice_data-location_enabled').length > 0) { if(navigator.geolocation) { $('#notice_data-location_enabled').change(function() { $.cookie(SN.C.S.NoticeLocationCookieName, $('#notice_data-location_enabled').attr('checked')); -- cgit v1.2.3-54-g00ecf From e06292c2a2715de5af29704eebeadc1e4b05b079 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Thu, 31 Dec 2009 16:19:49 +0000 Subject: If UA doens't support navigation.geolocation or have JavaScript enabled, the user should still be able to enable/disable their share location setting per notice. --- js/util.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'js') diff --git a/js/util.js b/js/util.js index 46efe92ff..7005d3125 100644 --- a/js/util.js +++ b/js/util.js @@ -439,7 +439,7 @@ var SN = { // StatusNet NoticeLocationAttach: function() { if ($('#notice_data-location_enabled').length > 0) { - if(navigator.geolocation) { + 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')) { @@ -472,8 +472,6 @@ var SN = { // StatusNet 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(); } } }, -- cgit v1.2.3-54-g00ecf From 58465d74bac0413b530f8a266c767da2c2f82648 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Thu, 31 Dec 2009 16:25:51 +0000 Subject: Compare by type --- js/util.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'js') diff --git a/js/util.js b/js/util.js index 7005d3125..a02a30a12 100644 --- a/js/util.js +++ b/js/util.js @@ -442,7 +442,8 @@ var SN = { // StatusNet 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')) { + + if ($('#notice_data-location_enabled').attr('checked') === true) { $('#'+SN.C.S.NoticeLocationName).show(); $('#'+SN.C.S.NoticeLocationName).addClass('processing'); navigator.geolocation.getCurrentPosition(function(position) { @@ -461,7 +462,8 @@ var SN = { // StatusNet } }); }); - } else { + } + else { $('#'+SN.C.S.NoticeLocationName).hide(); $('#'+SN.C.S.NoticeLat).val(""); $('#'+SN.C.S.NoticeLon).val(""); -- cgit v1.2.3-54-g00ecf From ccf78976a51aff886f4ab5f3dfe5a9a76cebba76 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Thu, 31 Dec 2009 16:34:07 +0000 Subject: NoticeLocationAttach() slightly more readable --- js/util.js | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'js') diff --git a/js/util.js b/js/util.js index a02a30a12..8716a3360 100644 --- a/js/util.js +++ b/js/util.js @@ -446,17 +446,32 @@ var SN = { // StatusNet if ($('#notice_data-location_enabled').attr('checked') === true) { $('#'+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()}; + + 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") { + + 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 { + } + else { $('#'+SN.C.S.NoticeLocationName).text(location.name); $('#'+SN.C.S.NoticeLocationName).attr('href',location.url); } @@ -465,12 +480,13 @@ var SN = { // StatusNet } 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(""); + $('#'+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(); -- cgit v1.2.3-54-g00ecf From 5a66d27637237359b2d81f2ac21e721703b10891 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Thu, 31 Dec 2009 16:37:46 +0000 Subject: Using semicolon to seperate lat and long; RFC2426 --- js/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js') diff --git a/js/util.js b/js/util.js index 8716a3360..f53581384 100644 --- a/js/util.js +++ b/js/util.js @@ -469,7 +469,7 @@ var SN = { // StatusNet } if (typeof(location.name) == 'undefined') { - $('#'+SN.C.S.NoticeLocationName).text(position.coords.latitude + ' ' + position.coords.longitude); + $('#'+SN.C.S.NoticeLocationName).text(position.coords.latitude + ';' + position.coords.longitude); } else { $('#'+SN.C.S.NoticeLocationName).text(location.name); -- cgit v1.2.3-54-g00ecf From e84bf0aa989ce40494f62e7355a49060e9918a63 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Thu, 31 Dec 2009 17:02:02 +0000 Subject: jQuery select SN.C.S.NoticeLocationName once. --- js/util.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'js') diff --git a/js/util.js b/js/util.js index f53581384..8ac0cbd66 100644 --- a/js/util.js +++ b/js/util.js @@ -442,10 +442,11 @@ var SN = { // StatusNet if (navigator.geolocation) { $('#notice_data-location_enabled').change(function() { $.cookie(SN.C.S.NoticeLocationCookieName, $('#notice_data-location_enabled').attr('checked')); + NLN = $('#'+SN.C.S.NoticeLocationName); if ($('#notice_data-location_enabled').attr('checked') === true) { - $('#'+SN.C.S.NoticeLocationName).show(); - $('#'+SN.C.S.NoticeLocationName).addClass('processing'); + NLN.show(); + NLN.addClass('processing'); navigator.geolocation.getCurrentPosition(function(position) { $('#'+SN.C.S.NoticeLat).val(position.coords.latitude); @@ -457,8 +458,8 @@ var SN = { // StatusNet 'token': $('#token').val() }; - $.getJSON($('#notice_data-location_enabled_container').attr('data-geocode-url'), data,function(location) { - $('#'+SN.C.S.NoticeLocationName).removeClass('processing'); + $.getJSON($('#notice_data-location_enabled_container').attr('data-geocode-url'), data, function(location) { + NLN.removeClass('processing'); if (typeof(location.location_ns) != 'undefined') { $('#'+SN.C.S.NoticeLocationNs).val(location.location_ns); @@ -469,17 +470,17 @@ var SN = { // StatusNet } if (typeof(location.name) == 'undefined') { - $('#'+SN.C.S.NoticeLocationName).text(position.coords.latitude + ';' + position.coords.longitude); + NLN.text(position.coords.latitude + ';' + position.coords.longitude); } else { - $('#'+SN.C.S.NoticeLocationName).text(location.name); - $('#'+SN.C.S.NoticeLocationName).attr('href',location.url); + NLN.text(location.name); + NLN.attr('href',location.url); } }); }); } else { - $('#'+SN.C.S.NoticeLocationName).hide(); + NLN.hide(); $('#'+SN.C.S.NoticeLat).val(''); $('#'+SN.C.S.NoticeLon).val(''); $('#'+SN.C.S.NoticeLocationNs).val(''); -- cgit v1.2.3-54-g00ecf From dde6415a6a91eb6670a80279a344ab6cc56ef17d Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Thu, 31 Dec 2009 18:08:21 +0000 Subject: Moved JavaScript dependant stuff out of noticeform. --- js/util.js | 29 ++++++++++++++++++++++------- lib/noticeform.php | 4 ++-- 2 files changed, 24 insertions(+), 9 deletions(-) (limited to 'js') diff --git a/js/util.js b/js/util.js index 8ac0cbd66..41b3fdb25 100644 --- a/js/util.js +++ b/js/util.js @@ -440,8 +440,20 @@ var SN = { // StatusNet NoticeLocationAttach: function() { if ($('#notice_data-location_enabled').length > 0) { if (navigator.geolocation) { - $('#notice_data-location_enabled').change(function() { + var NLE = $('#notice_data-location_wrap'); + var geocodeURL = NLE.attr('title'); + + 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.append('Geo'); NLN = $('#'+SN.C.S.NoticeLocationName); if ($('#notice_data-location_enabled').attr('checked') === true) { @@ -458,8 +470,9 @@ var SN = { // StatusNet 'token': $('#token').val() }; - $.getJSON($('#notice_data-location_enabled_container').attr('data-geocode-url'), data, function(location) { - NLN.removeClass('processing'); + $.getJSON(geocodeURL, data, function(location) { + NLN.replaceWith(''); + NLN = $('#'+SN.C.S.NoticeLocationName); if (typeof(location.location_ns) != 'undefined') { $('#'+SN.C.S.NoticeLocationNs).val(location.location_ns); @@ -470,12 +483,14 @@ var SN = { // StatusNet } if (typeof(location.name) == 'undefined') { - NLN.text(position.coords.latitude + ';' + position.coords.longitude); + NLN_text = position.coords.latitude + ';' + position.coords.longitude; } else { - NLN.text(location.name); - NLN.attr('href',location.url); + NLN_text = location.name; } + + NLN.attr('href', location.url); + NLN.text(NLN_text); }); }); } @@ -490,7 +505,7 @@ var SN = { // StatusNet var cookieVal = $.cookie(SN.C.S.NoticeLocationCookieName); $('#notice_data-location_enabled').attr('checked',(cookieVal == null || cookieVal == 'true')); - $('#notice_data-location_enabled').change(); + NLE.change(); } } }, diff --git a/lib/noticeform.php b/lib/noticeform.php index 98f15ca09..7ed880442 100644 --- a/lib/noticeform.php +++ b/lib/noticeform.php @@ -207,9 +207,9 @@ class NoticeForm extends Form $this->out->hidden('notice_data-location_id', empty($this->location_id) ? (empty($this->profile->location_id) ? null : $this->profile->location_id) : $this->location_id, 'location_id'); $this->out->hidden('notice_data-location_ns', empty($this->location_ns) ? (empty($this->profile->location_ns) ? null : $this->profile->location_ns) : $this->location_ns, 'location_ns'); - $this->out->elementStart('div',array('id' => 'notice_data-location_enabled_container', 'data-geocode-url' => common_local_url('geocode'))); + $this->out->elementStart('div', array('id' => 'notice_data-location_wrap', + 'title' => common_local_url('geocode'))); $this->out->checkbox('notice_data-location_enabled', _('Share your location'), true); - $this->out->element('a', array('id' => 'notice_data-location_name'), _('Finding your location...')); $this->out->elementEnd('div'); } -- cgit v1.2.3-54-g00ecf From 9496f2735e6b510f15c2c3ce627d5e6d3a94745b Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Thu, 31 Dec 2009 18:27:05 +0000 Subject: Moving notice_data-location_wrap after notice form fieldset --- js/util.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'js') diff --git a/js/util.js b/js/util.js index 41b3fdb25..0969ba5e2 100644 --- a/js/util.js +++ b/js/util.js @@ -439,10 +439,12 @@ var SN = { // StatusNet NoticeLocationAttach: function() { if ($('#notice_data-location_enabled').length > 0) { - if (navigator.geolocation) { - var NLE = $('#notice_data-location_wrap'); - var geocodeURL = NLE.attr('title'); + 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'); @@ -504,7 +506,7 @@ var SN = { // StatusNet }); var cookieVal = $.cookie(SN.C.S.NoticeLocationCookieName); - $('#notice_data-location_enabled').attr('checked',(cookieVal == null || cookieVal == 'true')); + $('#notice_data-location_enabled').attr('checked', (cookieVal == null || cookieVal == 'true')); NLE.change(); } } -- cgit v1.2.3-54-g00ecf From 01dbee2ba5280d97ddd0bb82217e8b3e7680e67b Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Thu, 31 Dec 2009 18:41:10 +0000 Subject: Initial UI for geo location share option in notice form --- js/util.js | 2 +- lib/noticeform.php | 1 + theme/base/css/display.css | 15 +++++++++++++++ theme/identica/css/display.css | 4 ++++ 4 files changed, 21 insertions(+), 1 deletion(-) (limited to 'js') diff --git a/js/util.js b/js/util.js index 0969ba5e2..dd7a74a7a 100644 --- a/js/util.js +++ b/js/util.js @@ -455,7 +455,7 @@ var SN = { // StatusNet NLN.remove(); } - NLE.append('Geo'); + NLE.prepend('Geo'); NLN = $('#'+SN.C.S.NoticeLocationName); if ($('#notice_data-location_enabled').attr('checked') === true) { diff --git a/lib/noticeform.php b/lib/noticeform.php index 7ed880442..d35655a0b 100644 --- a/lib/noticeform.php +++ b/lib/noticeform.php @@ -208,6 +208,7 @@ class NoticeForm extends Form $this->out->hidden('notice_data-location_ns', empty($this->location_ns) ? (empty($this->profile->location_ns) ? null : $this->profile->location_ns) : $this->location_ns, 'location_ns'); $this->out->elementStart('div', array('id' => 'notice_data-location_wrap', + 'class' => 'success', 'title' => common_local_url('geocode'))); $this->out->checkbox('notice_data-location_enabled', _('Share your location'), true); $this->out->elementEnd('div'); diff --git a/theme/base/css/display.css b/theme/base/css/display.css index 29c7ee963..d6a50ac60 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -566,6 +566,21 @@ overflow:auto; float:right; font-size:0.8em; } +.form_notice #notice_data-location_wrap input { +margin-right:7px; +float:left; +} +.form_notice #notice_data-location_wrap label { +font-weight:normal; +font-size:1em; +} +.form_notice #notice_data-location_name { +display:block; +line-height:1.6; +} +.form_notice span#notice_data-location_name { +padding-left:18px; +} button.close { width:16px; diff --git a/theme/identica/css/display.css b/theme/identica/css/display.css index e86ee2437..78a0707ce 100644 --- a/theme/identica/css/display.css +++ b/theme/identica/css/display.css @@ -111,6 +111,10 @@ box-shadow:3px 3px 3px rgba(194, 194, 194, 0.1); text-shadow:none; } +.form_notice #notice_data-location_name { +background-position:0 47%; +} + a, .form_settings input.form_action-primary, .notice-options input, -- cgit v1.2.3-54-g00ecf