From 212dd7f8198ec6219c565fa74f6c3440b4a6cfec Mon Sep 17 00:00:00 2001 From: Lapo Luchini Date: Sat, 22 Nov 2014 22:15:33 +0100 Subject: [PATCH] Make links clickable and only show the domain in the text. --- pinry/static/js/helpers.js | 12 ++++++++++++ pinry/templates/includes/lightbox.html | 2 +- pinry/templates/includes/pins.html | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pinry/static/js/helpers.js b/pinry/static/js/helpers.js index 33e95e8..9f22a4e 100644 --- a/pinry/static/js/helpers.js +++ b/pinry/static/js/helpers.js @@ -58,3 +58,15 @@ function postPinData(data) { function getUrlParameter(name) { return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null; } + +Handlebars.registerHelper('niceLinks', (function () { + var reNL = /\r?\n/g, + reURL = /https?:[/][/](?:www[.])?([^/]+)(?:[/]([.]?[^\s,.])+)?/g; + return function (text) { + var t = Handlebars.Utils.escapeExpression(text); + t = t.replace(reURL, '$1'); + t = t.replace(reNL, '
'); + return new Handlebars.SafeString(t); + }; +})()); + diff --git a/pinry/templates/includes/lightbox.html b/pinry/templates/includes/lightbox.html index 1c558c7..d903575 100644 --- a/pinry/templates/includes/lightbox.html +++ b/pinry/templates/includes/lightbox.html @@ -8,7 +8,7 @@