From 25f5698e714bab942fe21e758b07b952e58ac079 Mon Sep 17 00:00:00 2001 From: Zhicheng Wang Date: Tue, 31 May 2016 18:02:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E6=89=80=E6=9C=89=E5=A4=96=E7=AB=99?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=EF=BC=8C=E7=9B=B4=E6=8E=A5=E5=BC=80=E6=96=B0?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E6=89=93=E5=BC=80=EF=BC=8C=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=B0=8Fbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/resources/js/translate.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/public/resources/js/translate.js b/public/resources/js/translate.js index c82726ec1d..b200e1abdd 100644 --- a/public/resources/js/translate.js +++ b/public/resources/js/translate.js @@ -4,17 +4,23 @@ var sourceVisible = localStorage.getItem('source-visible') === 'true'; (function ($) { var nodes = document.querySelectorAll('p, li, h1, h2, h3, h4, h5, h6, header, a, button, small'); _.each(nodes, function (node) { - var prevNode = node.previousElementSibling; - if (!prevNode) { - return; - } - var $prevNode = $(prevNode); var $node = $(node); if (isLink(node) || isButton(node)) { - $node.on('click', function(event) { + $node.on('click', function (event) { event.stopPropagation(); }); + + if (/^http?s:\/\//.test($node.attr('href')) && !$node.attr('target')) { + $node.attr('target', '_blank'); + } + } + + var prevNode = node.previousElementSibling; + var $prevNode = $(prevNode); + + if (!prevNode) { + return; } if (isTranslationResult(node, prevNode)) { @@ -48,11 +54,13 @@ var sourceVisible = localStorage.getItem('source-visible') === 'true'; }); function isLink(node) { - return node.tagName === 'A'; + return node.tagName.toUpperCase() === 'A'; } + function isButton(node) { - return node.tagName === 'BUTTON'; + return node.tagName.toUpperCase() === 'BUTTON'; } + function isPureEnglish(text) { // accept — , quotes, ® and façade too. return /^[\1-\255—’“”ç®]*$/.test(text);