fix: 解决forEach的兼容性问题 (#199)

This commit is contained in:
Zhicheng Wang 2017-03-03 15:59:35 +08:00
parent b735266b94
commit 4df9030215
1 changed files with 20 additions and 18 deletions

View File

@ -19,26 +19,28 @@ var sourceVisible = localStorage.getItem('source-visible') === 'true';
*/ */
function processContainer(container) { function processContainer(container) {
var nodes = container.querySelectorAll('p,h1,h2,h3,h4,h5,h6,header,a'); var nodes = container.querySelectorAll('p,h1,h2,h3,h4,h5,h6,header,a');
nodes.forEach((node)=> { for(var i in nodes) {
if (isTranslation(node.textContent)) { (function(node) {
var $translated = $(node); if (isTranslation(node.textContent)) {
var prevNode = node.previousElementSibling; var $translated = $(node);
var $english = $(prevNode); var prevNode = node.previousElementSibling;
if (isCorrespondingNode(node, prevNode) && !isTranslation(prevNode.textContent)) { var $english = $(prevNode);
$translated.after($english); if (isCorrespondingNode(node, prevNode) && !isTranslation(prevNode.textContent)) {
$translated.addClass('translated'); $translated.after($english);
$translated.addClass('translated-cn'); $translated.addClass('translated');
$english.addClass('original-english'); $translated.addClass('translated-cn');
if (!sourceVisible) { $english.addClass('original-english');
$english.addClass('hidden'); if (!sourceVisible) {
} $english.addClass('hidden');
}
$translated.on('click', function (event) { $translated.on('click', function (event) {
$english.toggleClass('hidden'); $english.toggleClass('hidden');
}); });
}
} }
} })(nodes[i]);
}); }
} }
function isTranslation(text) { function isTranslation(text) {