From 35b108e645c3e3dd7ece038c04b72a2819aa4b8a Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Thu, 13 Feb 2014 12:11:25 -0500 Subject: [PATCH] Contact: fix display of links --- UI/Contacts/UIxContactView.m | 71 +++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/UI/Contacts/UIxContactView.m b/UI/Contacts/UIxContactView.m index 486fff107..093091248 100644 --- a/UI/Contacts/UIxContactView.m +++ b/UI/Contacts/UIxContactView.m @@ -67,7 +67,8 @@ - (NSString *) _cardStringWithLabel: (NSString *) label value: (NSString *) value - url: (NSString *) url + asLinkScheme: (NSString *) scheme + withLinkAttributes: (NSString *) attrs { NSMutableString *cardString; @@ -75,8 +76,8 @@ value = [[value stringByReplacingString: @"\r" withString: @""] stringByEscapingHTMLString]; if ([value length] > 0) { - if ([url length] > 0) - value = [NSString stringWithFormat: @"%@", url, value, value]; + if ([scheme length] > 0) + value = [NSString stringWithFormat: @"%@", scheme, value, attrs, value]; if (label) [cardString appendFormat: @"
%@
%@
\n", @@ -93,7 +94,18 @@ { return [self _cardStringWithLabel: label value: value - url: nil]; + asLinkScheme: nil + withLinkAttributes: nil]; +} + +- (NSString *) _cardStringWithLabel: (NSString *) label + value: (NSString *) value + asLinkScheme: (NSString *) scheme +{ + return [self _cardStringWithLabel: label + value: value + asLinkScheme: scheme + withLinkAttributes: nil]; } - (NSString *) displayName @@ -115,7 +127,7 @@ - (NSString *) primaryEmail { - NSString *email, *fn, *mailTo; + NSString *email, *fn, *attrs; email = [card preferredEMail]; if ([email length] > 0) @@ -123,26 +135,28 @@ fn = [card fn]; fn = [fn stringByReplacingString: @"\"" withString: @""]; fn = [fn stringByReplacingString: @"'" withString: @"\\\'"]; - mailTo = [NSString stringWithFormat: @"');\">" - @"%@", email, fn, email, email]; + attrs = [NSString stringWithFormat: @"onclick=\"return openMailTo('%@ <%@>');\"", fn, email]; } else - mailTo = nil; + { + attrs = nil; + } return [self _cardStringWithLabel: @"Email:" - value: mailTo]; + value: email + asLinkScheme: @"mailto:" + withLinkAttributes: attrs]; } - (NSArray *) secondaryEmails { NSMutableArray *secondaryEmails; - NSString *email, *fn, *mailTo; + NSString *email, *fn, *attrs; NSArray *emails; emails = [card secondaryEmails]; secondaryEmails = [NSMutableArray array]; - mailTo = nil; + attrs = nil; // We might not have a preferred item but rather something like this: // EMAIL;TYPE=work:dd@ee.com @@ -164,18 +178,18 @@ fn = [card fn]; fn = [fn stringByReplacingString: @"\"" withString: @""]; fn = [fn stringByReplacingString: @"'" withString: @"\\\'"]; - mailTo = [NSString stringWithFormat: @"');\">" - @"%@", email, fn, email, email]; + attrs = [NSString stringWithFormat: @"onclick=\"return openMailTo('%@ <%@>');\"", fn, email]; [secondaryEmails addObject: [self _cardStringWithLabel: nil - value: mailTo]]; + value: email + asLinkScheme: @"mailto:" + withLinkAttributes: attrs]]; } } else { [secondaryEmails addObject: [self _cardStringWithLabel: nil - value: mailTo]]; + value: nil]]; } @@ -184,22 +198,19 @@ - (NSString *) screenName { - NSString *screenName, *goim; + NSString *screenName; screenName = [[card uniqueChildWithTag: @"x-aim"] flattenedValuesForKey: @""]; - if ([screenName length] > 0) - goim = [NSString stringWithFormat: @"%@", screenName, screenName]; - else - goim = nil; - return [self _cardStringWithLabel: @"Screen Name:" value: goim]; + return [self _cardStringWithLabel: @"Screen Name:" + value: screenName + asLinkScheme: @"aim:goim?screenname="]; } - (NSString *) preferredTel { return [self _cardStringWithLabel: @"Phone Number:" - value: [card preferredTel] url: @"tel"]; + value: [card preferredTel] asLinkScheme: @"tel:"]; } - (NSString *) preferredAddress @@ -228,27 +239,27 @@ { // We do this (exclude FAX) in order to avoid setting the WORK number as the FAX // one if we do see the FAX field BEFORE the WORK number. - return [self _cardStringWithLabel: @"Work:" value: [card workPhone] url: @"tel"]; + return [self _cardStringWithLabel: @"Work:" value: [card workPhone] asLinkScheme: @"tel:"]; } - (NSString *) homePhone { - return [self _cardStringWithLabel: @"Home:" value: [card homePhone] url: @"tel"]; + return [self _cardStringWithLabel: @"Home:" value: [card homePhone] asLinkScheme: @"tel:"]; } - (NSString *) fax { - return [self _cardStringWithLabel: @"Fax:" value: [card fax] url: @"tel"]; + return [self _cardStringWithLabel: @"Fax:" value: [card fax] asLinkScheme: @"tel:"]; } - (NSString *) mobile { - return [self _cardStringWithLabel: @"Mobile:" value: [card mobile] url: @"tel"]; + return [self _cardStringWithLabel: @"Mobile:" value: [card mobile] asLinkScheme: @"tel:"]; } - (NSString *) pager { - return [self _cardStringWithLabel: @"Pager:" value: [card pager] url: @"tel"]; + return [self _cardStringWithLabel: @"Pager:" value: [card pager] asLinkScheme: @"tel:"]; } - (BOOL) hasHomeInfos