From 2de6cebf239b200ad18ece24a214eaabc9944366 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Tue, 22 Apr 2014 16:58:06 +0300 Subject: [PATCH] show url in text fields --- frontend/client/res/templates/fields/text/detail.tpl | 2 +- frontend/client/src/view-helper.js | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/frontend/client/res/templates/fields/text/detail.tpl b/frontend/client/res/templates/fields/text/detail.tpl index f419a58bfb..3ba7ebd6a4 100644 --- a/frontend/client/res/templates/fields/text/detail.tpl +++ b/frontend/client/res/templates/fields/text/detail.tpl @@ -1 +1 @@ -{{breaklines value}} +{{complexText value}} diff --git a/frontend/client/src/view-helper.js b/frontend/client/src/view-helper.js index 6308ce13b3..4b202913fc 100644 --- a/frontend/client/src/view-helper.js +++ b/frontend/client/src/view-helper.js @@ -22,6 +22,8 @@ (function (Espo, _, Handlebars) { Espo.ViewHelper = function (options) { + this.urlRegex =/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; + this._registerHandlebarsHelpers(); } @@ -38,7 +40,6 @@ language: null, _registerHandlebarsHelpers: function () { - var self = this; Handlebars.registerHelper('img', function (img) { @@ -131,6 +132,15 @@ text = text.replace(/(\r\n|\n|\r)/gm, '
'); return new Handlebars.SafeString(text); }); + + Handlebars.registerHelper('complexText', function (text) { + text = Handlebars.Utils.escapeExpression(text || ''); + text = text.replace(/(\r\n|\n|\r)/gm, '
'); + text = text.replace(self.urlRegex, function (url) { + return '' + url + ''; + }); + return new Handlebars.SafeString(text); + }); Handlebars.registerHelper('translateOption', function (name, options) { var scope = options.hash.scope || null;