From 3706bfa59b5f5b19c92f9b0cfa7b4497dd43bef7 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Thu, 29 Dec 2022 14:49:23 +0100 Subject: [PATCH] Slightly fewer DOM calls in print_pv(). --- www/js/remoteglot.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/www/js/remoteglot.js b/www/js/remoteglot.js index de1bb16..42990ad 100644 --- a/www/js/remoteglot.js +++ b/www/js/remoteglot.js @@ -755,13 +755,9 @@ function print_pv(line_num, splicepos, opt_limit, opt_showlast) { ret.appendChild(document.createTextNode(move_num + '. … ')); } for (; i < pv.length; ++i) { - let link = document.createElement('a'); - link.className = 'move'; - link.setAttribute('id', 'automove' + line_num + '-' + i); - link.textContent = pv[i]; - link.href = 'javascript:show_line(' + line_num + ', ' + i + ');'; + let prefix = ''; if (splicepos === i) { - ret.appendChild(document.createTextNode('(TB: ')); + prefix = '(TB: '; in_tb = true; } @@ -771,18 +767,25 @@ function print_pv(line_num, splicepos, opt_limit, opt_showlast) { } else if (toplay == 'W') { if (i > opt_limit && !opt_showlast) { if (in_tb) { - ret.appendChild(document.createTextNode(')')); + prefix += ')'; } - ret.appendChild(document.createTextNode(' (…)')); + ret.appendChild(document.createTextNode(prefix + ' (…)')); return ret; } - ret.appendChild(document.createTextNode(' ' + move_num + '. ')); + prefix += ' ' + move_num + '. '; ++move_num; toplay = 'B'; } else { - ret.appendChild(document.createTextNode(' ')); + prefix += ' '; toplay = 'W'; } + ret.appendChild(document.createTextNode(prefix)); + + let link = document.createElement('a'); + link.className = 'move'; + link.setAttribute('id', 'automove' + line_num + '-' + i); + link.textContent = pv[i]; + link.href = 'javascript:show_line(' + line_num + ', ' + i + ');'; ret.appendChild(link); } if (in_tb) { -- 2.39.2