Some refactorings out of update_board().
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 20 Nov 2014 21:10:13 +0000 (22:10 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 20 Nov 2014 21:22:22 +0000 (22:22 +0100)
www/js/remoteglot.js

index 8161236..52e4c4a 100644 (file)
@@ -101,7 +101,11 @@ var request_update = function() {
        }).done(function(data, textstatus, xhr) {
                ims = xhr.getResponseHeader('X-Remoteglot-Last-Modified');
                var num_viewers = xhr.getResponseHeader('X-Remoteglot-Num-Viewers');
-               update_board(data, num_viewers);
+               update_board(data);
+               update_num_viewers(num_viewers);
+
+               // Next update.
+               setTimeout(function() { request_update(); }, 100);
        }).fail(function() {
                // Wait ten seconds, then try again.
                setTimeout(function() { request_update(); }, 10000);
@@ -561,9 +565,8 @@ var update_refutation_lines = function() {
 
 /**
  * @param {Object} data
- * @param {number} num_viewers
  */
-var update_board = function(data, num_viewers) {
+var update_board = function(data) {
        display_lines = [];
 
        // The headline.
@@ -590,14 +593,6 @@ var update_board = function(data, num_viewers) {
 
        $("#headline").text(headline);
 
-       if (num_viewers === null) {
-               $("#numviewers").text("");
-       } else if (num_viewers == 1) {
-               $("#numviewers").text("You are the only current viewer");
-       } else {
-               $("#numviewers").text(num_viewers + " current viewers");
-       }
-
        // The engine id.
        if (data['id'] && data['id']['name'] !== null) {
                $("#engineid").text(data['id']['name']);
@@ -724,9 +719,19 @@ var update_board = function(data, num_viewers) {
        toplay = data['position']['toplay'];
        refutation_lines = data['refutation_lines'];
        update_refutation_lines();
+}
 
-       // Next update.
-       setTimeout(function() { request_update(); }, 100);
+/**
+ * @param {number} num_viewers
+ */
+var update_num_viewers = function(num_viewers) {
+       if (num_viewers === null) {
+               $("#numviewers").text("");
+       } else if (num_viewers == 1) {
+               $("#numviewers").text("You are the only current viewer");
+       } else {
+               $("#numviewers").text(num_viewers + " current viewers");
+       }
 }
 
 /**