当点击链接或按钮时,不再切换原文显示

This commit is contained in:
Zhicheng Wang 2016-05-31 12:52:39 +08:00
parent 20bf6c0085
commit 1dc3b54fe0
1 changed files with 17 additions and 3 deletions

View File

@ -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);