From 954ffcd91c32bc300f70c0f05416945673f8ca5f Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Thu, 17 Oct 2013 17:53:14 +0200 Subject: [PATCH] Truncate link texts to a sensible length (#2376) --- plugins/libcalendaring/libcalendaring.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/libcalendaring/libcalendaring.js b/plugins/libcalendaring/libcalendaring.js index 5dcc3d46..ff111b36 100644 --- a/plugins/libcalendaring/libcalendaring.js +++ b/plugins/libcalendaring/libcalendaring.js @@ -283,9 +283,17 @@ function rcube_libcalendaring(settings) var url1 = '.:;,', url2 = 'a-z0-9%=#@+?&/_~\\[\\]-'; var link_pattern = new RegExp('([hf]t+ps?://)('+utf_domain+'(['+url1+']?['+url2+']+)*)?', 'ig'); var mailto_pattern = new RegExp('([^\\s\\n\\(\\);]+@'+utf_domain+')', 'ig'); + var link_replace = function(matches, p1, p2) { + var title = '', text = p2; + if (p2.length > 55) { + text = p2.substr(0, 45) + '...' + p2.substr(-8) : p2; + title = p1 + p2; + } + return ''+p1+text+'' + }; return html - .replace(link_pattern, '$1$2') + .replace(link_pattern, link_replace) .replace(mailto_pattern, '$1') .replace(/(mailto:)([^"]+)"/g, '$1$2" onclick="rcmail.command(\'compose\', \'$2\');return false"') .replace(/\n/g, "
");