Refactored NoticeLocationAttach(). It works better in UAs that don't

support Geolocation API.
This commit is contained in:
Sarven Capadisli 2010-01-04 23:36:22 +00:00
parent a0f7896f22
commit d59ffeaab5

View File

@ -442,6 +442,9 @@ var SN = { // StatusNet
},
NoticeLocationAttach: function() {
var NLat = $('#'+SN.C.S.NoticeLat).val();
var NLon = $('#'+SN.C.S.NoticeLon).val();
function removeNoticeDataGeo() {
$('label[for='+SN.C.S.NoticeDataGeo+']').removeClass('checked');
$('#'+SN.C.S.NoticeDataGeoSelected).hide();
@ -451,67 +454,7 @@ var SN = { // StatusNet
$('#'+SN.C.S.NoticeLocationId).val('');
}
var NDG = $('#'+SN.C.S.NoticeDataGeo);
if (NDG.length > 0) {
var NLE = $('#notice_data-location_wrap');
var geocodeURL = NLE.attr('title');
NLE.removeAttr('title');
$('label[for='+SN.C.S.NoticeDataGeo+']').attr('title', jQuery.trim($('label[for='+SN.C.S.NoticeDataGeo+']').text()));
if (navigator.geolocation) {
NDG.change(function() {
$.cookie(SN.C.S.NoticeLocationCookieName, $('#'+SN.C.S.NoticeDataGeo).attr('checked'));
var NLN = $('#'+SN.C.S.NoticeLocationName);
if (NLN.length > 0) {
NLN.remove();
}
var S = '<div id="'+SN.C.S.NoticeDataGeoSelected+'" class="'+SN.C.S.Success+'"/>';
var NDGS = $('#'+SN.C.S.NoticeDataGeoSelected);
if (NDGS.length > 0) {
NDGS.replaceWith(S);
}
else {
$('#'+SN.C.S.FormNotice).append(S);
}
NDGS = $('#'+SN.C.S.NoticeDataGeoSelected);
NDGS.prepend('<span id="'+SN.C.S.NoticeLocationName+'">Geo</span>');
var NLN = $('#'+SN.C.S.NoticeLocationName);
if ($('#'+SN.C.S.NoticeDataGeo).attr('checked') === true) {
NLN.addClass('processing');
$('label[for='+SN.C.S.NoticeDataGeo+']').addClass('checked');
NDGS.append('<button class="minimize">&#95;</button> <button class="close">&#215;</button>');
$('#'+SN.C.S.NoticeDataGeoSelected+' button.close').click(function(){
$('#'+SN.C.S.NoticeDataGeoSelected).remove();
$('#'+SN.C.S.NoticeDataGeo).attr('checked', false);
$('label[for='+SN.C.S.NoticeDataGeo+']').removeClass('checked');
return false;
});
$('#'+SN.C.S.NoticeDataGeoSelected+' button.minimize').click(function(){
$('#'+SN.C.S.NoticeDataGeoSelected).hide();
return false;
});
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()
};
function getJSONgeocodeURL(geocodeURL, data) {
$.getJSON(geocodeURL, data, function(location) {
NLN = $('#'+SN.C.S.NoticeLocationName);
NLN.replaceWith('<a id="notice_data-location_name"/>');
@ -540,6 +483,69 @@ var SN = { // StatusNet
return false;
});
});
}
var NDG = $('#'+SN.C.S.NoticeDataGeo);
if (NDG.length > 0) {
var NLE = $('#notice_data-location_wrap');
var geocodeURL = NLE.attr('title');
NLE.removeAttr('title');
$('label[for='+SN.C.S.NoticeDataGeo+']').attr('title', jQuery.trim($('label[for='+SN.C.S.NoticeDataGeo+']').text()));
NDG.change(function() {
$.cookie(SN.C.S.NoticeLocationCookieName, $('#'+SN.C.S.NoticeDataGeo).attr('checked'));
var NLN = $('#'+SN.C.S.NoticeLocationName);
if (NLN.length > 0) {
NLN.remove();
}
if ($('#'+SN.C.S.NoticeDataGeo).attr('checked') === true) {
$('label[for='+SN.C.S.NoticeDataGeo+']').addClass('checked');
var S = '<div id="'+SN.C.S.NoticeDataGeoSelected+'" class="'+SN.C.S.Success+'"/>';
var NDGS = $('#'+SN.C.S.NoticeDataGeoSelected);
if (NDGS.length > 0) {
NDGS.replaceWith(S);
}
else {
$('#'+SN.C.S.FormNotice).append(S);
}
NDGS = $('#'+SN.C.S.NoticeDataGeoSelected);
NDGS.prepend('<span id="'+SN.C.S.NoticeLocationName+'">Geo</span> <button class="minimize">&#95;</button> <button class="close">&#215;</button>');
var NLN = $('#'+SN.C.S.NoticeLocationName);
NLN.addClass('processing');
$('#'+SN.C.S.NoticeDataGeoSelected+' button.close').click(function(){
$('#'+SN.C.S.NoticeDataGeoSelected).remove();
$('#'+SN.C.S.NoticeDataGeo).attr('checked', false);
$('label[for='+SN.C.S.NoticeDataGeo+']').removeClass('checked');
return false;
});
$('#'+SN.C.S.NoticeDataGeoSelected+' button.minimize').click(function(){
$('#'+SN.C.S.NoticeDataGeoSelected).hide();
return false;
});
if (navigator.geolocation) {
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()
};
getJSONgeocodeURL(geocodeURL, data);
},
function(error) {
@ -550,6 +556,20 @@ var SN = { // StatusNet
);
}
else {
if (NLat.length > 0 && NLon.length > 0) {
var data = {
'lat': NLat,
'lon': NLon,
'token': $('#token').val()
};
getJSONgeocodeURL(geocodeURL, data);
}
}
}
else {
$('label[for='+SN.C.S.NoticeDataGeo+']').removeClass('checked');
removeNoticeDataGeo();
}
}).change();
@ -557,7 +577,6 @@ var SN = { // StatusNet
var cookieVal = $.cookie(SN.C.S.NoticeLocationCookieName);
NDG.attr('checked', (cookieVal === null || cookieVal == 'true'));
}
}
},
NewDirectMessage: function() {