From 1dc3b54fe0a74f370393a22a2b6e6278afa81940 Mon Sep 17 00:00:00 2001 From: Zhicheng Wang Date: Tue, 31 May 2016 12:52:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=93=E7=82=B9=E5=87=BB=E9=93=BE=E6=8E=A5?= =?UTF-8?q?=E6=88=96=E6=8C=89=E9=92=AE=E6=97=B6=EF=BC=8C=E4=B8=8D=E5=86=8D?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E5=8E=9F=E6=96=87=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/resources/js/translate.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/public/resources/js/translate.js b/public/resources/js/translate.js index 3b60e1b54f..c82726ec1d 100644 --- a/public/resources/js/translate.js +++ b/public/resources/js/translate.js @@ -8,15 +8,23 @@ var sourceVisible = localStorage.getItem('source-visible') === 'true'; if (!prevNode) { return; } + var $prevNode = $(prevNode); + var $node = $(node); + + if (isLink(node) || isButton(node)) { + $node.on('click', function(event) { + event.stopPropagation(); + }); + } + if (isTranslationResult(node, prevNode)) { - var $prevNode = $(prevNode); - var $node = $(node); if ($prevNode.hasClass('nav-list-item')) { return; } if (isPureEnglish($node.text()) && $node.text() !== $prevNode.text()) { return; } + if (isPureEnglish($prevNode.text())) { $node.attr('id', prevNode.id); $node.addClass('translated'); @@ -26,7 +34,7 @@ var sourceVisible = localStorage.getItem('source-visible') === 'true'; if (!sourceVisible) { $prevNode.addClass('hidden'); } - if (node.tagName !== 'A' && node.tagName !== 'BUTTON') { + if (!isLink(node) && !isButton(node)) { $node.on('click', function () { $prevNode.toggleClass('hidden'); }); @@ -39,6 +47,12 @@ var sourceVisible = localStorage.getItem('source-visible') === 'true'; } }); + function isLink(node) { + return node.tagName === 'A'; + } + function isButton(node) { + return node.tagName === 'BUTTON'; + } function isPureEnglish(text) { // accept — , quotes, ® and façade too. return /^[\1-\255—’“”ç®]*$/.test(text);