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

This commit is contained in:
Martin Edenhofer 2017-03-14 20:10:52 +01:00
parent 4b4e157806
commit cb4c4c85e4
3 changed files with 26 additions and 6 deletions

View file

@ -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'

View file

@ -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) ->

View file

@ -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() {