add config file comments, minor JS refactoring
[ppt-control.git] / ppt_control / static / ppt-control.js
index c00ca682e503558d6812f9d039ea32df5938436a..39714f6c910c88d7c2d923e2425924889b779a55 100644 (file)
@@ -1,4 +1,9 @@
-var DEFAULT_TITLE = "ppt-control"
+const DEFAULT_TITLE = "ppt-control";
+const LABEL_STOPPED = "Slideshow stopped";
+const LABEL_RUNNING = "Slideshow running";
+const LABEL_DISCONNECTED = "Disconnected";
+const LABEL_FINAL_PREFIX = "Final slide ‐ ";
+const LABEL_END_PREFIX = "End of slideshow ‐ ";
 var preloaded = false;
 var preload = [];
 
@@ -126,6 +131,8 @@ next_img.onclick = function (event) {
        next.click()
 }
 
+window.addEventListener('resize', function(event) {set_control_width()}, true);
+
 
 function sync_current() {
     if (show_current.checked) {
@@ -211,9 +218,8 @@ function refreshInterface() {
     var d = new Date;
     if (Object.keys(presentationData).length > 0) {
         currentPresentationData = presentationData[getPresentationName()];
-        console.log("Current presentation is " + getPresentationName());
         presentation_text.style.display = "block";
-        status_text.textContent = "Slideshow running";
+        status_text.innerHTML = LABEL_RUNNING;
         startBtn.style.display = "none";
         stopBtn.style.display = "block";
         if (show_current.checked) {
@@ -230,10 +236,10 @@ function refreshInterface() {
             }
         }
         if (currentPresentationData.slide_current == currentPresentationData.slide_total) {
-            status_text.textContent = "Slideshow running (last slide)";
+            status_text.innerHTML = LABEL_FINAL_PREFIX + LABEL_RUNNING;
         }
         if (currentPresentationData.slide_current == currentPresentationData.slide_total + 1) { 
-            status_text.textContent = "End of slideshow";
+            status_text.innerHTML = LABEL_END_PREFIX + LABEL_RUNNING;
             next_img.src = "/black.jpg";
         } else {
             next_img.src = "/cache/" + currentPresentationData.name + "/" + (currentPresentationData.slide_current + 1) + ".jpg?t=" + d.getTime();
@@ -241,7 +247,7 @@ function refreshInterface() {
         if (currentPresentationData.slide_current == 0) {
             current_img.src = "/black.jpg";
             next_img.src = "/black.jpg";
-            status_text.textContent = "Slideshow not running";
+            status_text.innerHTML = LABEL_STOPPED;
             startBtn.style.display = "block";
             stopBtn.style.display = "none";
         }
@@ -261,7 +267,7 @@ function disconnect() {
     document.title = DEFAULT_TITLE;
     current_img.src = "/black.jpg";
     next_img.src = "/black.jpg";
-    status_text.textContent = "Disconnected";
+    status_text.innerHTML = LABEL_DISCONNECTED;
     total.textContent = "?";
     current.value = "";
     presentation_text.style.display = "none";
@@ -271,7 +277,6 @@ function disconnect() {
 
 function receive_message(event) {
     data = JSON.parse(event.data);
-    console.log("Received data: " + data);
     if (Object.keys(presentationData).includes(data.name)) {
         // Existing presentation
         presentationData[data.name] = {"name": data.name, "pres_open": data.pres_open, "slideshow": data.slideshow, "visible": data.visible, "slide_current": data.slide_current, "slide_total": data.slide_total, "option": presentationData[data.name].option};