From 540472a093ce6835cd1f3449b27d4a81ab9f9dee Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Thu, 19 Jan 2017 13:52:38 +0000 Subject: [PATCH] Ensure all a tags have blank target in info sidebar --- editor/js/ui/tab-info.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/editor/js/ui/tab-info.js b/editor/js/ui/tab-info.js index 156e29292..f96fbdbf3 100644 --- a/editor/js/ui/tab-info.js +++ b/editor/js/ui/tab-info.js @@ -66,6 +66,15 @@ RED.sidebar.info = (function() { return value; } + function addTargetToExternalLinks(el) { + $(el).find("a").each(function(el) { + var href = $(this).attr('href'); + if (/^https?:/.test(href)) { + $(this).attr('target','_blank'); + } + }); + return el; + } function refresh(node) { tips.stop(); $(content).empty(); @@ -117,15 +126,14 @@ RED.sidebar.info = (function() { $("
").appendTo(content); if (!subflowNode && node.type != "comment") { var helpText = $("script[data-help-name$='"+node.type+"']").html()||""; - $('
'+helpText+'
').appendTo(content); + addTargetToExternalLinks($('
'+helpText+'
').appendTo(content)); } if (subflowNode) { - $('
'+marked(subflowNode.info||"")+'
').appendTo(content); + addTargetToExternalLinks($('
'+marked(subflowNode.info||"")+'
').appendTo(content)); } else if (node._def && node._def.info) { var info = node._def.info; var textInfo = (typeof info === "function" ? info.call(node) : info); - var ma = marked(textInfo).replace(/href=/g, 'target="_blank" href='); - $('
'+ma+'
').appendTo(content); + addTargetToExternalLinks($('
'+marked(textInfo)+'
').appendTo(content)); //$('
'+(typeof info === "function" ? info.call(node) : info)+'
'; }