From f29c3f151415d2820b0cad93d43dce8614c27add Mon Sep 17 00:00:00 2001 From: Summer Smith Date: Tue, 20 Oct 2015 18:53:19 -0400 Subject: [PATCH 1/2] Split long strings into single or multiple phone numbers --- src/infotemplates.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/infotemplates.js b/src/infotemplates.js index da8cbce..60a6228 100644 --- a/src/infotemplates.js +++ b/src/infotemplates.js @@ -10,7 +10,11 @@ define(function(require, exports) { list: Handlebars.compile(''), directions: Handlebars.compile('{{title}}'), simple: Handlebars.compile('{{text}}'), - phone_numbers: Handlebars.compile('{{text}}'), + phone_numbers: Handlebars.compile( + '{{#if secondValue}}{{text}}
' + + '{{secondValue}}' + + '{{else}}{{text}}{{/if}}' + ), popup: Handlebars.compile('
{{#popup}}
{{{rendered}}}
{{/popup}}
') }; var formatters = { @@ -41,6 +45,17 @@ define(function(require, exports) { }, phone_numbers: function(value) { + if(value.length > 12) { + var regex = new RegExp("\\+?\\(?\\d*\\)? ?\\(?\\d+\\)?\\d*([\\s./-]?\\"+ + "d{2,}), g"); + var firstValue = regex.exec(value); + var secondValue = regex.exec(value); + value = firstValue[0]; + if(secondValue[0].length >= 12) { + return templates.phone_numbers({text: value, + secondValue: secondValue[0]}); + } + } return templates.phone_numbers({text: value}); }, From 4f846f52169f13139f45a56ee0d9ca1043b63ea6 Mon Sep 17 00:00:00 2001 From: Summer Smith Date: Tue, 20 Oct 2015 19:02:10 -0400 Subject: [PATCH 2/2] Fix regex --- src/infotemplates.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/infotemplates.js b/src/infotemplates.js index 60a6228..6d8c12b 100644 --- a/src/infotemplates.js +++ b/src/infotemplates.js @@ -46,8 +46,8 @@ define(function(require, exports) { phone_numbers: function(value) { if(value.length > 12) { - var regex = new RegExp("\\+?\\(?\\d*\\)? ?\\(?\\d+\\)?\\d*([\\s./-]?\\"+ - "d{2,}), g"); + var regex = new RegExp("\\+?\\(?\\d*\\)? ?\\(?\\d+\\)?\\d*([\\s./-]?\\d{2,})+", + "g"); var firstValue = regex.exec(value); var secondValue = regex.exec(value); value = firstValue[0];