Browse Source

Fixed issue #438 - Introduced App.Utils.phoneify() for phone numbers.

Martin Edenhofer 8 years ago
parent
commit
cb4c4c85e4

+ 5 - 4
app/assets/javascripts/app/index.coffee

@@ -111,12 +111,13 @@ class App extends Spine.Controller
 
     # transform input tel|url to make it clickable
     if attribute_config.tag is 'input'
-      isHtmlEscape = true
-      result       = App.Utils.htmlEscape(result)
       if attribute_config.type is 'tel'
-        result = "<a href=\"tel://#{result}\">#{result}</a>"
-      if attribute_config.type is 'url'
+        result = "<a href=\"#{App.Utils.phoneify(result)}\">#{App.Utils.htmlEscape(result)}</a>"
+      else if attribute_config.type is 'url'
         result = App.Utils.linkify(result)
+      else
+        result = App.Utils.htmlEscape(result)
+      isHtmlEscape = true
 
     # use pretty time for datetime
     else if attribute_config.tag is 'datetime'

+ 7 - 2
app/assets/javascripts/app/lib/app_post/utils.coffee

@@ -46,8 +46,13 @@ class App.Utils
       .replace(/\n{3,20}/g, "\n\n")   # remove multiple empty lines
 
   # htmlEscapedAndLinkified = App.Utils.linkify(rawText)
-  @linkify: (ascii) ->
-    window.linkify(ascii)
+  @linkify: (string) ->
+    window.linkify(string)
+
+  # htmlEscapedAndLinkified = App.Utils.linkify(rawText)
+  @phoneify: (string) ->
+    string = string.replace(/\s+/g, '')
+    "tel://#{encodeURIComponent(string)}"
 
   # wrappedText = App.Utils.wrap(rawText, maxLineLength)
   @wrap: (ascii, max = 82) ->

+ 14 - 0
public/assets/tests/html_utils.js

@@ -197,6 +197,20 @@ test("html2text", function() {
 
 });
 
+// phoneify
+test("phoneify", function() {
+
+  var source = "+1 123 123 123-123"
+  var should = 'tel://%2B1123123123-123'
+  var result = App.Utils.phoneify(source)
+  equal(result, should, source)
+
+  source = "+1 123 123 A 123-123<>"
+  should = 'tel://%2B1123123A123-123%3C%3E'
+  result = App.Utils.phoneify(source)
+  equal(result, should, source)
+})
+
 // linkify
 test("linkify", function() {