diff --git a/app/assets/javascripts/app/index.coffee b/app/assets/javascripts/app/index.coffee index c357871c1..9ee17d832 100644 --- a/app/assets/javascripts/app/index.coffee +++ b/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 = "#{result}" - if attribute_config.type is 'url' + result = "#{App.Utils.htmlEscape(result)}" + 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' diff --git a/app/assets/javascripts/app/lib/app_post/utils.coffee b/app/assets/javascripts/app/lib/app_post/utils.coffee index 2539ff434..7aac88ebb 100644 --- a/app/assets/javascripts/app/lib/app_post/utils.coffee +++ b/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) -> diff --git a/public/assets/tests/html_utils.js b/public/assets/tests/html_utils.js index 820aa3cf9..9569c8a8c 100644 --- a/public/assets/tests/html_utils.js +++ b/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() {