summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/js/utils.js
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2016-11-15 13:58:55 +0100
committerChristophe Simonis <chs@odoo.com>2016-11-15 13:58:55 +0100
commitdece72d010e23c88bdf5b2a1ace6ff0df2b2732f (patch)
treef9fc12d1f2f5f51acca168854702f75e316e1f0b /addons/mail/static/src/js/utils.js
parent22d7be5b7397f9d9a811e071601a9ad07762dc55 (diff)
parentca2003839a9abc3f76f48d2382d512a4546aeab1 (diff)
[MERGE] forward port branch saas-12 up to ca20038
Diffstat (limited to 'addons/mail/static/src/js/utils.js')
-rw-r--r--addons/mail/static/src/js/utils.js20
1 files changed, 16 insertions, 4 deletions
diff --git a/addons/mail/static/src/js/utils.js b/addons/mail/static/src/js/utils.js
index 7c64ba48df0..db82b976945 100644
--- a/addons/mail/static/src/js/utils.js
+++ b/addons/mail/static/src/js/utils.js
@@ -61,12 +61,23 @@ function _parse_and_transform(nodes, transform_function) {
// suggested regexp (gruber url matching regexp, adapted to js, see https://gist.github.com/gruber/8891611)
var url_regexp = /\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/gi;
+function linkify(text, attrs) {
+ attrs = attrs || {};
+ if (attrs.target === undefined) {
+ attrs.target = '_blank';
+ }
+ attrs = _.map(attrs, function (value, key) {
+ return key + '="' + _.escape(value) + '"';
+ }).join(' ');
+ return text.replace(url_regexp, function (url) {
+ var href = (!/^(f|ht)tps?:\/\//i.test(url)) ? "http://" + url : url;
+ return '<a ' + attrs + ' href="' + href + '">' + url + '</a>';
+ });
+}
+
function add_link (node, transform_children) {
if (node.nodeType === 3) { // text node
- return node.data.replace(url_regexp, function (url) {
- var href = (!/^(f|ht)tps?:\/\//i.test(url)) ? "http://" + url : url;
- return '<a target="_blank" href="' + href + '">' + url + '</a>';
- });
+ return linkify(node.data);
}
if (node.tagName === "A") return node.outerHTML;
node.innerHTML = transform_children();
@@ -132,6 +143,7 @@ return {
send_notification: send_notification,
parse_and_transform: parse_and_transform,
add_link: add_link,
+ linkify: linkify,
strip_html: strip_html,
inline: inline,
parse_email: parse_email,