]> git.sesse.net Git - remoteglot/blobdiff - www/js/remoteglot.js
More simplification in print_pv().
[remoteglot] / www / js / remoteglot.js
index 5d19116ee1927ebc82a989e0aab19a0dc646cf5b..5314a5681dbbbfbf7c589cd253b1179388988777 100644 (file)
@@ -733,16 +733,15 @@ function print_pv(line_num, splicepos, opt_limit, opt_showlast) {
        }
 
        let ret = document.createDocumentFragment();
-       let i = 0;
        let in_tb = false;
-       let link = document.createElement('a');
-       link.className = 'move';
        if (opt_limit && opt_showlast && pv.length > opt_limit) {
                // Truncate the PV at the beginning (instead of at the end).
                // We assume here that toplay is 'W'. We also assume that if
                // opt_showlast is set, then it is the history, and thus,
                // the UI should be to expand the history.
                ret.appendChild(document.createTextNode('('));
+               let link = document.createElement('a');
+               link.className = 'move';
                link.href = 'javascript:collapse_history(false)';
                link.textContent = '…';
                ret.appendChild(link);
@@ -754,21 +753,9 @@ function print_pv(line_num, splicepos, opt_limit, opt_showlast) {
                move_num += i / 2;
        } else if (toplay == 'B' && pv.length > 0) {
                ret.appendChild(document.createTextNode(move_num + '. … '));
-               let move = "";
-               if (splicepos === 0) {
-                       ret.appendChild(document.createTextNode('(TB: '));
-                       in_tb = true;
-               }
-               link.setAttribute('id', 'automove' + line_num + '-0');
-               link.href = 'javascript:show_line(' + line_num + ', ' + 0 + ');';
-               link.textContent = pv[0];
-               ret.appendChild(link);
-               toplay = 'W';
-               ++i;
-               ++move_num;
        }
-       for ( ; i < pv.length; ++i) {
-               link = document.createElement('a');
+       for (let i = 0; i < pv.length; ++i) {
+               let link = document.createElement('a');
                link.className = 'move';
                link.setAttribute('id', 'automove' + line_num + '-' + i);
                link.textContent = pv[i];
@@ -778,7 +765,10 @@ function print_pv(line_num, splicepos, opt_limit, opt_showlast) {
                        in_tb = true;
                }
 
-               if (toplay == 'W') {
+               if (toplay == 'B' && i == 0) {
+                       ++move_num;
+                       toplay = 'W';
+               } else if (toplay == 'W') {
                        if (i > opt_limit && !opt_showlast) {
                                if (in_tb) {
                                        ret.appendChild(document.createTextNode(')'));
@@ -786,10 +776,7 @@ function print_pv(line_num, splicepos, opt_limit, opt_showlast) {
                                ret.appendChild(document.createTextNode(' (…)'));
                                return ret;
                        }
-                       if (ret != '') {
-                               ret.appendChild(document.createTextNode(' '));
-                       }
-                       ret.appendChild(document.createTextNode(move_num + '. '));
+                       ret.appendChild(document.createTextNode(' ' + move_num + '. '));
                        ++move_num;
                        toplay = 'B';
                } else {