1
0
mirror of https://github.com/MailHops/mailhops-plugin.git synced 2025-05-17 23:00:10 -07:00

Refactored the display of first hop

This commit is contained in:
Andrew Van Tassel 2015-09-18 11:42:44 -06:00
parent f0f165527a
commit a317fc87a8
2 changed files with 24 additions and 38 deletions

View File

@ -271,12 +271,9 @@ var mailHopsDisplay =
var displayText='' var displayText=''
, distanceText='' , distanceText=''
, image='chrome://mailhops/content/images/local.png' , image='chrome://mailhops/content/images/local.png'
, city=null
, state=null
, countryName=null
, gotFirst=false
, secureToolTipText=false , secureToolTipText=false
, weather=null; , weather=null
, first=null;
//remove child details //remove child details
while(this.resultDetails.firstChild) { while(this.resultDetails.firstChild) {
@ -310,16 +307,10 @@ var mailHopsDisplay =
for(var i=0; i<response.route.length;i++){ for(var i=0; i<response.route.length;i++){
//get the first hop location //get the first hop location
if(!gotFirst && !response.route[i].private && !response.route[i].client){ if(!first && !response.route[i].private && !response.route[i].client){
first = response.route[i];
if(!!response.route[i].countryCode) if(!!response.route[i].countryCode)
image='chrome://mailhops/content/images/flags/'+response.route[i].countryCode.toLowerCase()+'.png'; image='chrome://mailhops/content/images/flags/'+response.route[i].countryCode.toLowerCase()+'.png';
if(!!response.route[i].city)
city=response.route[i].city;
if(!!response.route[i].state)
state=response.route[i].state;
if(!!response.route[i].countryName)
countryName=response.route[i].countryName;
gotFirst=true;
} }
var label = document.createElement('label'); var label = document.createElement('label');
@ -422,12 +413,14 @@ var mailHopsDisplay =
displayText = ' Local message.'; displayText = ' Local message.';
} else { } else {
if(!!city && !!state) if(!!first){
displayText = city+', '+state; if(!!first.city && !!first.state)
else if(!!city) displayText = first.city+', '+first.state;
displayText = city+', '+countryCode; else if(!!first.city)
else if(!!countryName) displayText = first.city+', '+first.countryCode;
displayText = countryName; else if(!!first.countryName)
displayText = first.countryName;
}
if(response.distance && response.distance.miles > 0){ if(response.distance && response.distance.miles > 0){
if(this.options.unit=='mi') if(this.options.unit=='mi')

View File

@ -173,11 +173,8 @@ var mailHopsDisplay =
var displayText='' var displayText=''
, distanceText='' , distanceText=''
, image='chrome://mailhops/content/images/local.png' , image='chrome://mailhops/content/images/local.png'
, city=null , weather=null
, state=null , first=null;
, countryName=null
, gotFirst=false
, weather=null;
//remove child details //remove child details
while(this.resultDetails.firstChild) { while(this.resultDetails.firstChild) {
@ -192,16 +189,10 @@ var mailHopsDisplay =
} }
for(var i=0; i<response.route.length;i++){ for(var i=0; i<response.route.length;i++){
//get the first hop location //get the first hop location
if(!gotFirst && !response.route[i].private && !response.route[i].client){ if(!first && !response.route[i].private && !response.route[i].client){
first = response.route[i];
if(!!response.route[i].countryCode) if(!!response.route[i].countryCode)
image='chrome://mailhops/content/images/flags/'+response.route[i].countryCode.toLowerCase()+'.png'; image='chrome://mailhops/content/images/flags/'+response.route[i].countryCode.toLowerCase()+'.png';
if(!!response.route[i].city)
city=response.route[i].city;
if(!!response.route[i].state)
state=response.route[i].state;
if(!!response.route[i].countryName)
countryName=response.route[i].countryName;
gotFirst=true;
} }
var menuitem = document.createElement('menuitem'); var menuitem = document.createElement('menuitem');
@ -283,12 +274,14 @@ var mailHopsDisplay =
displayText = ' Local message.'; displayText = ' Local message.';
} else { } else {
if(!!city && !!state) if(!!first){
displayText = city+', '+state; if(!!first.city && !!first.state)
else if(!!city) displayText = first.city+', '+first.state;
displayText = city+', '+countryCode; else if(!!first.city)
else if(!!countryName) displayText = first.city+', '+first.countryCode;
displayText = countryName; else if(!!first.countryName)
displayText = first.countryName;
}
if(response.distance && response.distance.miles > 0){ if(response.distance && response.distance.miles > 0){
if(this.options.unit=='mi') if(this.options.unit=='mi')