From 724d266f9a69a6bfb602a4f7462f78b3602cc03b Mon Sep 17 00:00:00 2001 From: Andrew Van Tassel Date: Tue, 28 Jun 2011 10:09:30 -0600 Subject: [PATCH] Fixed styles and reload of datapane --- chrome/content/images/loader.gif | Bin 723 -> 1644 bytes chrome/content/mailhops.js | 251 +++++++++++++++++---------- chrome/content/msgHdrViewOverlay.xul | 16 +- chrome/content/preferences.js | 22 ++- chrome/content/preferences.xul | 6 + chrome/skin/classic/mailhops.css | 46 +++++ install.rdf | 2 +- 7 files changed, 244 insertions(+), 99 deletions(-) diff --git a/chrome/content/images/loader.gif b/chrome/content/images/loader.gif index c8fc154b66ee413b0904d72cac13d3886c92e7b7..49b6d85326305cebc519dd8eb1a8fbe108b6f282 100644 GIT binary patch literal 1644 zcmbW%ZA?>V6bJCf+xxWl#rF2T7Vd3(OIL0SDyd2qmMx^-i?iiL%f_59xXDBWW3W@F z9U-%7VN5EhC@1<6Kf|A^YItz~<*mOJ)U?WuH>Z7&P&*jZMdRaITF6Qs?cIFWp{c<#%& zApreXzKGeo*+)cHV@r1k;t|ZZyu({}=)lMVm=~wIyMn=3cSF1)$I*fxyS0^h3Kpu! zq^~vGYsXMg7CzFU1Y}bQ-X$MHYpV$^dQ47ds!2TsdC9?(sH%rJf@!&+CJzvZ5S6#Ms(okvlxx11a=I+S=`_*P&o!FiMvw!w~IWEDra zKBHZ3>PQhzSQUjq0ys42FoBdZWLXi`>;aS@=p>6X9uM$>6*wh^bDh`F%e&o@w1s(J zMXr~el```mBbJkad7-VoNU+jlj_Q64Wq3FfIJn!(c^2Sj!BSfmf&Z~D6kgj|2fIB> zJmig4lN-Yvck5tJvAEa#VVI$fb!LhY4huZT*45F_+Q?v%n3`h2G#EoE(IFFdmZe2o zF+iLWFY_3Ej&*C9l0?cb)Fz(mR0l-8EQ=oxtKub)epg>mpwDMy;qkoGWCnum>#%yi zt2^iedN^D>_9;fy!J#47!bPojbsK=^vcGZSpr1nv7d>e>8v6P7bTyRgFpyS`Ah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/content/mailhops.js b/chrome/content/mailhops.js index 26a9eda..2589bbf 100644 --- a/chrome/content/mailhops.js +++ b/chrome/content/mailhops.js @@ -1,8 +1,7 @@ /* * @author: Andrew Van Tassel * @email: andrew@andrewvantassel.com -* @website: http://mailhops.com -* @TODO: cache result and display country flag in column +* @website: http://mailhops.com* */ var mailHops = @@ -10,31 +9,61 @@ var mailHops = resultTextDataPane: null, resultTextDataPane2: null, resultContainerDataPane: null, + resultDetailsLink: null, + resultContainerDetails: null, + resultDetails: null, + resultMapLink: null, isLoaded: false, + showDetails: false, map: 'goog', unit: 'mi', - appVersion: 'MailHops Postbox 0.4.7' + appVersion: 'MailHops Postbox 0.4.8' } -mailHops.startLoading = function() +mailHops.init = function() { + //load preferences + mailHops.loadPref(); + mailHops.isLoaded = true; mailHops.resultContainerDataPane = document.getElementById ( "mailhopsDataPane"); mailHops.resultTextDataPane = document.getElementById ( "mailhopsDataPaneText"); mailHops.resultTextDataPane2 = document.getElementById ( "mailhopsDataPaneText2"); - - //get preferences - mailHops.map = mailHops.getCharPref('mail.mailHops.map','goog'); - mailHops.unit = mailHops.getCharPref('mail.mailHops.unit','mi'); + + mailHops.resultDetailsLink = document.getElementById ( "mailhopsDataPaneDetailsLink"); + mailHops.resultContainerDetails = document.getElementById ( "mailhopsDetailsContainer"); + mailHops.resultDetails = document.getElementById ( "mailhopsDataPaneDetails"); + + mailHops.resultMapLink = document.getElementById ( "mailhopsDataPaneMapLink"); + //event listner for route click to launch map - mailHops.resultContainerDataPane.addEventListener("click", function () { + mailHops.resultMapLink.addEventListener("click", function () { var route = this.getAttribute("route"); if(route) mailHops.launchMap(String(route)); } , false); -} ; + mailHops.resultDetailsLink.addEventListener("click", function () { + if(mailHops.resultContainerDetails.style.display=='none'){ + mailHops.resultContainerDetails.style.display = 'block'; + mailHops.resultDetailsLink.setAttribute('class','text-link dataPaneMoreLink active'); + } + else{ + mailHops.resultContainerDetails.style.display = 'none'; + mailHops.resultDetailsLink.setAttribute('class','text-link dataPaneMoreLink'); + } + } + , false); +}; + +mailHops.loadPref = function() +{ + //get preferences + mailHops.map = mailHops.getCharPref('mail.mailHops.map','goog'); + mailHops.unit = mailHops.getCharPref('mail.mailHops.unit','mi'); + mailHops.showDetails = mailHops.getCharPref('mail.mailHops.show_details','false')=='true'?true:false; +}; mailHops.StreamListener = { @@ -72,9 +101,9 @@ mailHops.StreamListener = { mailHops.headers = Components.classes["@mozilla.org/messenger/mimeheaders;1"].createInstance ( Components.interfaces.nsIMimeHeaders ) ; mailHops.headers.initialize ( this.content , this.content.length ) ; - mailHops.dispRoute() ; + mailHops.getRoute() ; } -} ; +}; /** * loop through the header, find out if we have received-from headers @@ -96,11 +125,9 @@ mailHops.loadHeaderData = function() var messenger = Components.classes["@mozilla.org/messenger;1"].createInstance ( Components.interfaces.nsIMessenger ) ; var msgService = messenger.messageServiceFromURI ( msgURI ) ; msgService.CopyMessage ( msgURI , mailHops.StreamListener , false , null , msgWindow , {} ) ; -} ; - -mailHops.dispRoute = function() -{ +}; +mailHops.getRoute = function(){ //IP regex var regexIp=/(1\d{0,2}|2(?:[0-4]\d{0,1}|[6789]|5[0-5]?)?|[3-9]\d?|0)\.(1\d{0,2}|2(?:[0-4]\d{0,1}|[6789]|5[0-5]?)?|[3-9]\d?|0)\.(1\d{0,2}|2(?:[0-4]\d{0,1}|[6789]|5[0-5]?)?|[3-9]\d?|0)\.(1\d{0,2}|2(?:[0-4]\d{0,1}|[6789]|5[0-5]?)?|[3-9]\d?|0)(\/(?:[012]\d?|3[012]?|[456789])){0,1}$/; var regexAllIp = /(1\d{0,2}|2(?:[0-4]\d{0,1}|[6789]|5[0-5]?)?|[3-9]\d?|0)\.(1\d{0,2}|2(?:[0-4]\d{0,1}|[6789]|5[0-5]?)?|[3-9]\d?|0)\.(1\d{0,2}|2(?:[0-4]\d{0,1}|[6789]|5[0-5]?)?|[3-9]\d?|0)\.(1\d{0,2}|2(?:[0-4]\d{0,1}|[6789]|5[0-5]?)?|[3-9]\d?|0)(\/(?:[012]\d?|3[012]?|[456789])){0,1}/g; @@ -149,7 +176,6 @@ var regexAllIp = /(1\d{0,2}|2(?:[0-4]\d{0,1}|[6789]|5[0-5]?)?|[3-9]\d?|0)\.(1\d{ }; //another ip check, dates will throw off the regex mailHops.testIP = function(ip,header){ - var retval; try { @@ -173,19 +199,61 @@ mailHops.testIP = function(ip,header){ catch(ex) { retval = true; } - return retval; - + return retval; }; -mailHops.displayResult = function ( image, distance, city, state, countryName, route ) -{ +mailHops.displayResult = function ( header_route, response ){ var displayText=''; var distanceText=''; - - if(image.indexOf('error')!=-1) { - displayText = ' There was a problem connecting to MailHops.'; - } - else if(image.indexOf('local')!=-1) { + var image= 'chrome://mailhops/content/images/local.png'; + var city; + var state; + var countryName; + var gotFirst=false; + + //remove child details + while(mailHops.resultDetails.firstChild) { + mailHops.resultDetails.removeChild(mailHops.resultDetails.firstChild); + } + + for(var i=0; i 0){ + if(response.distance && response.distance.miles > 0){ if(mailHops.unit=='mi') - distanceText =' ( '+mailHops.addCommas(Math.round(distance.miles))+' mi traveled )'; + distanceText =' ( '+mailHops.addCommas(Math.round(response.distance.miles))+' mi traveled )'; else - distanceText =' ( '+mailHops.addCommas(Math.round(distance.kilometers))+' km traveled )'; + distanceText =' ( '+mailHops.addCommas(Math.round(response.distance.kilometers))+' km traveled )'; } else if(displayText=='') displayText = ' Local message.'; } + //add event for route api map - if(mailHops.resultContainerDataPane){ - mailHops.resultContainerDataPane.setAttribute("route", route); - mailHops.resultTextDataPane.style.backgroundImage = 'url('+image+')'; - mailHops.resultTextDataPane.value = displayText; - mailHops.resultTextDataPane.setAttribute('tooltiptext',displayText+' '+distanceText); + mailHops.resultMapLink.setAttribute("route", header_route); + mailHops.resultTextDataPane.style.backgroundImage = 'url('+image+')'; + mailHops.resultTextDataPane.value = displayText; + mailHops.resultTextDataPane.setAttribute('tooltiptext',displayText+' '+distanceText); + + mailHops.resultTextDataPane2.value = distanceText; + mailHops.resultTextDataPane2.setAttribute('tooltiptext',displayText+' '+distanceText); + //show the detail link + mailHops.resultDetailsLink.style.display = 'block'; + mailHops.resultMapLink.style.display = 'block'; + //show details by default + if(mailHops.showDetails){ + mailHops.resultContainerDetails.style.display = 'block'; + mailHops.resultDetailsLink.setAttribute('class','text-link dataPaneMoreLink active'); + } + else{ + mailHops.resultContainerDetails.style.display = 'none'; + mailHops.resultDetailsLink.setAttribute('class','text-link dataPaneMoreLink'); + } +}; + +//display the connection error message +mailHops.displayError = function(){ + mailHops.resultMapLink.removeAttribute("route"); + mailHops.resultTextDataPane.style.backgroundImage = 'url(chrome://mailhops/content/images/error.png)'; + mailHops.resultTextDataPane.value = ' MailHops Failed.'; + mailHops.resultTextDataPane.setAttribute('tooltiptext',' Could not connect to MailHops.'); mailHops.resultTextDataPane2.value = distanceText; - mailHops.resultTextDataPane2.setAttribute('tooltiptext',displayText+' '+distanceText); - } -} ; + mailHops.resultTextDataPane2.setAttribute('tooltiptext',' Could not connect to MailHops.'); +}; mailHops.clearRoute = function(){ - if(mailHops.resultContainerDataPane){ - mailHops.resultTextDataPane.style.backgroundImage = 'url(chrome://mailhops/content/images/loader.gif)'; - mailHops.resultTextDataPane.value = ' Looking Up Route'; - mailHops.resultTextDataPane.setAttribute('tooltiptext','Looking Up Route'); - - mailHops.resultTextDataPane2.value = ''; - mailHops.resultTextDataPane2.setAttribute('tooltiptext',''); - } -} ; + mailHops.resultContainerDetails.style.display = 'none'; + mailHops.resultDetailsLink.style.display = 'none'; + mailHops.resultMapLink.style.display = 'none'; + + mailHops.resultTextDataPane.style.backgroundImage = 'url(chrome://mailhops/content/images/loader.gif)'; + mailHops.resultTextDataPane.value = ' Looking Up Route'; + mailHops.resultTextDataPane.setAttribute('tooltiptext','Looking Up Route'); + + mailHops.resultTextDataPane2.value = ''; + mailHops.resultTextDataPane2.setAttribute('tooltiptext',''); + + //remove child details + while(mailHops.resultDetails.firstChild) { + mailHops.resultDetails.removeChild(mailHops.resultDetails.firstChild); + } +}; -mailHops.setupEventListener = function() -{ +mailHops.setupEventListener = function(){ if ( mailHops.isLoaded ){ return ; } - mailHops.startLoading() ; + mailHops.init() ; mailHops.registerObserver() ; var listener = {} ; listener.onStartHeaders = function() { mailHops.clearRoute() ; } ; listener.onEndHeaders = mailHops.loadHeaderData ; gMessageListeners.push ( listener ) ; -} ; +}; //preferences observers -mailHops.registerObserver = function() -{ +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() -{ +mailHops.unregisterObserver = function(){ if ( !mailHops._branch ){ return ; } mailHops._branch.removeObserver ( "" , mailHops ) ; -} ; +}; mailHops.observe = function ( aSubject , aTopic , aData ) { @@ -265,11 +359,11 @@ mailHops.observe = function ( aSubject , aTopic , aData ) return ; } - mailHops.startLoading(); -} ; + //load preferences + mailHops.loadPref(); +}; -mailHops.getCharPref = function ( strName , strDefault ) -{ +mailHops.getCharPref = function ( strName , strDefault ){ var value; try @@ -282,10 +376,10 @@ mailHops.getCharPref = function ( strName , strDefault ) } return ( value ) ; -} ; +}; //mailhops lookup -mailHops.lookup = function(route){ +mailHops.lookup = function(header_route){ //setup loading mailHops.clearRoute(); @@ -295,45 +389,29 @@ mailHops.lookup = function(route){ //call mailhops api for lookup var xmlhttp = new XMLHttpRequest(); - var flag= 'chrome://mailhops/content/images/local.png'; - var city; - var state; - var countryName; - xmlhttp.open("GET", 'http://api.mailhops.com/v1/lookup/?tb&app='+mailHops.appVersion+'&r='+route.toString(),true); + xmlhttp.open("GET", 'http://api.mailhops.com/v1/lookup/?tb&app='+mailHops.appVersion+'&r='+String(header_route),true); xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4) { try{ var data = nativeJSON.decode(xmlhttp.responseText); if(data && data.meta.code==200){ - for(var i=0; i + - - + + + + + + + + + + + + + diff --git a/chrome/content/preferences.js b/chrome/content/preferences.js index c82284c..4692791 100644 --- a/chrome/content/preferences.js +++ b/chrome/content/preferences.js @@ -7,22 +7,26 @@ var mailHopPreferences = { loadPreferences: function() { - if(mailHops.getCharPref("mail.mailHops.map",'goog')=='goog') + if(pref.getCharPref("mail.mailHops.map",'goog')=='goog') document.getElementById("mailhop.map").selectedIndex = 0; else document.getElementById("mailhop.map").selectedIndex = 1; - if(mailHops.getCharPref("mail.mailHops.unit",'mi')=='mi') + + if(pref.getCharPref("mail.mailHops.unit",'mi')=='mi') document.getElementById("mailhop.unit").selectedIndex = 0; else document.getElementById("mailhop.unit").selectedIndex = 1; + + if(pref.getCharPref("mail.mailHops.show_details",'false')=='true') + document.getElementById("mailhop.show_details").checked = true; + else + document.getElementById("mailhop.show_details").checked = false; + } , savePreferences: function() { - mailHopPreferences.setCharPref("mail.mailHops.map", document.getElementById("mailhop.map").selectedItem.value) ; - mailHopPreferences.setCharPref("mail.mailHops.unit", document.getElementById("mailhop.unit").selectedItem.value) ; - } , - setCharPref: function( strName , strValue ) - { - pref.setCharPref ( strName , strValue ) ; - } + pref.setCharPref("mail.mailHops.map", document.getElementById("mailhop.map").selectedItem.value) ; + pref.setCharPref("mail.mailHops.unit", document.getElementById("mailhop.unit").selectedItem.value) ; + pref.setCharPref("mail.mailHops.show_details", String(document.getElementById("mailhop.show_details").checked)) ; + } } diff --git a/chrome/content/preferences.xul b/chrome/content/preferences.xul index 5985b16..cdd0712 100644 --- a/chrome/content/preferences.xul +++ b/chrome/content/preferences.xul @@ -21,6 +21,7 @@ + @@ -28,6 +29,11 @@ + + + + + diff --git a/chrome/skin/classic/mailhops.css b/chrome/skin/classic/mailhops.css index c7c821d..454873c 100644 --- a/chrome/skin/classic/mailhops.css +++ b/chrome/skin/classic/mailhops.css @@ -5,3 +5,49 @@ #mailhopsResultText {padding-left:4px;} #mailHopsResultImage {padding-left:4px;display: none;} + +#mailhopsDataPaneDetailsLink{ + margin-left: 10px; + text-align: center; + padding-right: 14px; +} + +#mailhopsDataPaneDetailsLink.active{ + color: #FFF; + margin-left: 10px; + background-color: #98a5b3; + -moz-border-radius: 20px; + -webkit-border-radius: 20px; + -khtml-border-radius: 20px; + border-radius: 20px; + text-align: center; + padding-right: 14px; +} + +.mailhopsDetail{ + padding-bottom: 2px; +} + +.mailHopsLinkContainer{ + padding-bottom: 4px; +} + +#mailhopsDetailsContainer{ + margin-left: 10px; + margin-right: 10px; + display: none; + border: 1px solid #e1e2e5; + background-color: #f7f8f9; + -moz-border-radius: 5px; + -webkit-border-radius: 5px; + -khtml-border-radius: 5px; + border-radius: 5px; +} + +#mailhopsDataPaneDetails{ + padding: 4px; +} + +#mailhopsDataPane{ + padding-bottom: 4px; +} \ No newline at end of file diff --git a/install.rdf b/install.rdf index b4a0c0c..72af158 100644 --- a/install.rdf +++ b/install.rdf @@ -7,7 +7,7 @@ postbox@mailhops.com 2 MailHops - 0.4.7 + 0.4.8 MailHops maps the route an email traveled to get to you. Using GeoIP it also displays distance traveled along with the location (city, state and country) of the sender. chrome://mailhops/content/images/mailhops32.png http://mailhops.com