]> git.sesse.net Git - remoteglot/commitdiff
Slightly fewer DOM calls in print_pv().
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 29 Dec 2022 13:49:23 +0000 (14:49 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 29 Dec 2022 13:49:23 +0000 (14:49 +0100)
www/js/remoteglot.js

index de1bb1652c3960bde41bcac5ffea08a8476817f3..42990ad0001ee6e716bba308ce4c901cdfe3f1cd 100644 (file)
@@ -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) {