diff --git a/chrome/content/images/mailhops32.png b/chrome/content/images/mailhops32.png index d92b95f..9572c42 100644 Binary files a/chrome/content/images/mailhops32.png and b/chrome/content/images/mailhops32.png differ diff --git a/chrome/content/mailWindowOverlay.xul b/chrome/content/mailWindowOverlay.xul index 18e5328..4867441 100644 --- a/chrome/content/mailWindowOverlay.xul +++ b/chrome/content/mailWindowOverlay.xul @@ -12,7 +12,7 @@ diff --git a/chrome/content/mailhops.js b/chrome/content/mailhops.js index dc66747..71c3b6c 100644 --- a/chrome/content/mailhops.js +++ b/chrome/content/mailhops.js @@ -16,7 +16,9 @@ var mailHops = resultImage: null, resultText: null, container: null, - isLoaded: false + isLoaded: false, + map: 'goog', + unit: 'mi' } mailHops.startLoading = function() @@ -26,6 +28,10 @@ mailHops.startLoading = function() mailHops.resultBox = document.getElementById ( "mailhopsResult" ) ; mailHops.resultImage = document.getElementById ( "mailhopsResultImage" ) ; mailHops.resultText = document.getElementById ( "mailhopsResultText" ) ; + //get preferences + mailHops.map = mailHops.getCharPref('mail.mailHops.map','goog'); + mailHops.unit = mailHops.getCharPref('mail.mailHops.unit','mi'); + } ; mailHops.StreamListener = @@ -155,13 +161,20 @@ mailHops.testIP = function(ip,header){ mailHops.displayResult = function ( distance, image, city, state, route ) { if(distance){ - if(distance.miles > 0) - mailHops.resultText.textContent = city+', '+state+' ( '+Math.round(distance.miles)+' miles to you )'; - else + if(distance.miles > 0){ + if(mailHops.unit=='mi') + mailHops.resultText.textContent = city+', '+state+' ( '+addCommas(Math.round(distance.miles))+' mi traveled )'; + else + mailHops.resultText.textContent = city+', '+state+' ( '+addCommas(Math.round(distance.kilometers))+' km traveled )'; + } + else if(city && state) mailHops.resultText.textContent = city+', '+state; + else + mailHops.resultText.textContent = ' Local message.'; mailHops.container.setAttribute("onclick","launchMap('"+route.toString()+"');"); } else { mailHops.resultText.textContent = ' There was a problem.'; + mailHops.container.removeAttribute("onclick"); } mailHops.resultImage.src=image; } ; @@ -178,6 +191,7 @@ mailHops.setupEventListener = function() } mailHops.startLoading() ; + mailHops.registerObserver() ; var listener = {} ; listener.onStartHeaders = function() { mailHops.clearRoute() ; } ; @@ -185,6 +199,50 @@ mailHops.setupEventListener = function() gMessageListeners.push ( listener ) ; } ; +//preferences observers +mailHops.registerObserver = function() +{ + var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService ( Components.interfaces.nsIPrefService ) ; + mailHops._branch = prefService.getBranch ( "mail.mailHops." ) ; + mailHops._branch.QueryInterface ( Components.interfaces.nsIPrefBranchInternal ) ; + mailHops._branch.addObserver ( "" , mailHops , false ) ; +} ; + +mailHops.unregisterObserver = function() +{ + if ( !mailHops._branch ){ + return ; + } + + mailHops._branch.removeObserver ( "" , mailHops ) ; +} ; + +mailHops.observe = function ( aSubject , aTopic , aData ) +{ + if ( aTopic != "nsPref:changed" ){ + return ; + } + + mailHops.startLoading(); +} ; + +mailHops.getCharPref = function ( strName , strDefault ) +{ + var value; + + try + { + value = pref.getCharPref ( strName ) ; + } + catch ( exception ) + { + value = strDefault ; + } + + return ( value ) ; +} ; + +//mailhops lookup mailHops.lookup = function(route){ //setup loading @@ -202,7 +260,7 @@ mailHops.lookup = function(route){ var data = nativeJSON.decode(xmlhttp.responseText); if(data && data.meta.code==200){ for(var i=0; i 1 ? '.' + x[1] : ''; + var rgx = /(\d+)(\d{3})/; + while (rgx.test(x1)) { + x1 = x1.replace(rgx, '$1' + ',' + '$2'); + } + return x1 + x2; +} + function launchMap(route) { //launch mailhops api map - var openwin = window.openDialog('http://api.mailhops.com/v1/map/?tb&route='+route,"MailHops",'toolbar=no,location=no,directories=no,menubar=yes,scrollbars=yes,close=yes,width=730,height=330'); + var openwin = window.openDialog('http://api.mailhops.com/v1/map/?tb&m='+mailHops.map+'&u='+mailHops.unit+'&r='+route,"MailHops",'toolbar=no,location=no,directories=no,menubar=yes,scrollbars=yes,close=yes,width=730,height=330'); openwin.focus(); } diff --git a/install.rdf b/install.rdf index 8f1df9d..1747d39 100644 --- a/install.rdf +++ b/install.rdf @@ -8,7 +8,7 @@ 2 MailHops - 0.1 + 0.2 MailHops maps the route an email took to get to you. chrome://mailhops/content/images/mailhops32.png @@ -17,6 +17,8 @@ Andrew Van Tassel Andrew Van Tassel + chrome://mailhops/content/preferences.xul +