A little function split.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 21 Mar 2016 19:00:05 +0000 (20:00 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 21 Mar 2016 20:59:45 +0000 (21:59 +0100)
www/js/remoteglot.js

index 3dacd58..82f64d9 100644 (file)
@@ -1559,28 +1559,7 @@ var update_move_highlight = function() {
                highlighted_move.removeClass('highlight'); 
        }
        if (current_display_line) {
-               // See if the current displayed line is identical to any of the ones
-               // we have on screen. (It might not be if e.g. the analysis reloaded
-               // since we started looking.)
-               var display_line_num = null;
-               for (var i = 0; i < display_lines.length; ++i) {
-                       var line = display_lines[i];
-                       if (line.start_display_move_num > 0) continue;
-                       if (current_display_line.start_fen !== line.start_fen) continue;
-                       if (current_display_line.pretty_pv.length !== line.pretty_pv.length) continue;
-                       var ok = true;
-                       for (var j = 0; j < line.pretty_pv.length; ++j) {
-                               if (current_display_line.pretty_pv[j] !== line.pretty_pv[j]) {
-                                       ok = false;
-                                       break;
-                               }
-                       }
-                       if (ok) {
-                               display_line_num = i;
-                               break;
-                       }
-               }
-
+               var display_line_num = find_display_line_matching_num();
                if (display_line_num === null) {
                        // Replace the PV with the (complete) line.
                        $("#pvtitle").text("Exploring:");
@@ -1595,6 +1574,33 @@ var update_move_highlight = function() {
        }
 }
 
+/**
+ * See if the current displayed line is identical to any of the ones
+ * we have on screen. (It might not be if e.g. the analysis reloaded
+ * since we started looking.)
+ *
+ * @return {?number}
+ */
+var find_display_line_matching_num = function() {
+       for (var i = 0; i < display_lines.length; ++i) {
+               var line = display_lines[i];
+               if (line.start_display_move_num > 0) continue;
+               if (current_display_line.start_fen !== line.start_fen) continue;
+               if (current_display_line.pretty_pv.length !== line.pretty_pv.length) continue;
+               var ok = true;
+               for (var j = 0; j < line.pretty_pv.length; ++j) {
+                       if (current_display_line.pretty_pv[j] !== line.pretty_pv[j]) {
+                               ok = false;
+                               break;
+                       }
+               }
+               if (ok) {
+                       return i;
+               }
+       }
+       return null;
+}
+
 var update_displayed_line = function() {
        if (current_display_line === null) {
                $("#linenav").hide();