浏览代码

fix(demo): fix optional zoom controls not shown, improve hiding/unhiding of control elements (#661)

control elements now have opacity=0 before being enabled by controls, so they're invisible during page load.
sschmid 5 年之前
父节点
当前提交
97832042f4
共有 2 个文件被更改,包括 76 次插入36 次删除
  1. 19 9
      demo/index.html
  2. 57 27
      demo/index.js

+ 19 - 9
demo/index.html

@@ -14,11 +14,11 @@
     <link rel="icon" href="./favicon.ico?" type="image/x-icon"/>
 </head>
 <body>
-<h1 class="ui centered header" id="header">
+<h1 class="ui centered header" id="header" style="opacity: 0.0">
     <img src="./favicon.ico?" class="ui image">
     <%= htmlWebpackPlugin.options.title %>
 </h1>
-<div class="ui four column grid container" id="divControls" style="visibility: hidden">
+<div class="ui four column grid container" id="divControls" style="visibility: hidden; opacity: 0.0">
     <div class="column">
         <h3 class="ui header">Select a sample:</h3>
         <select class="ui selection dropdown" id="selectSample" style="width:320px; height:38%; visibility: hidden"></select>
@@ -142,12 +142,22 @@
         <div class="ui button" id="print-pdf-btn">Print to Pdf</div>
     </div>
 </div>
-<div id="optionalControls"></div>
-<table cellspacing="0" style="max-width:700px;">
-    <tr id="error-tr">
-        <td></td>
-        <td id="error-td"></td>
-    </tr>
-</table>
+<div id="optionalControls" style="opacity: 0.0">
+    <table cellspacing="0" style="max-width:700px;">
+        <tr id="error-tr">
+            <td></td>
+            <td id="error-td"></td>
+        </tr>
+    </table>
+    <div class="ui buttons" id="zoomControlsButtons-optional">
+        <div class="ui button" id="zoom-in-btn-optional">
+            <i class="search plus icon"></i>
+        </div>
+        <div class="ui button" id="zoom-out-btn-optional">
+            <i class="search minus icon"></i>
+        </div>
+    </div>
+    <h4 class="ui header" id="zoom-str-optional"></h4>
+</div>
 </body>
 </html>

+ 57 - 27
demo/index.js

@@ -59,9 +59,9 @@ import { OpenSheetMusicDisplay } from '../src/OpenSheetMusicDisplay/OpenSheetMus
         selectBounding,
         skylineDebug,
         bottomlineDebug,
-        zoomIn,
-        zoomOut,
-        zoomDiv,
+        zoomIns,
+        zoomOuts,
+        zoomDivs,
         custom,
         nextCursorBtn,
         resetCursorBtn,
@@ -121,8 +121,10 @@ import { OpenSheetMusicDisplay } from '../src/OpenSheetMusicDisplay/OpenSheetMus
         var paramPageHeight = findGetParameter('pageHeight');
 
         showHeader = (paramShowHeader !== '0');
+        showControls = false;
         if (paramEmbedded !== undefined) {
             showControls = (paramShowControls !== '0');
+            console.log('show controls: ' + showControls);
             showZoomControl = (paramShowZoomControl !== '0');
         }
 
@@ -171,14 +173,20 @@ import { OpenSheetMusicDisplay } from '../src/OpenSheetMusicDisplay/OpenSheetMus
         header = document.getElementById('header');
         err = document.getElementById("error-td");
         error_tr = document.getElementById("error-tr");
-        zoomDiv = document.getElementById("zoom-str");
+        zoomDivs = [];
+        zoomDivs.push(document.getElementById("zoom-str"));
+        zoomDivs.push(document.getElementById("zoom-str-optional"));
         custom = document.createElement("option");
         selectSample = document.getElementById("selectSample");
         selectBounding = document.getElementById("selectBounding");
         skylineDebug = document.getElementById("skylineDebug");
         bottomlineDebug = document.getElementById("bottomlineDebug");
-        zoomIn = document.getElementById("zoom-in-btn");
-        zoomOut = document.getElementById("zoom-out-btn");
+        zoomIns = [];
+        zoomIns.push(document.getElementById("zoom-in-btn"));
+        zoomIns.push(document.getElementById("zoom-in-btn-optional"));
+        zoomOuts = [];
+        zoomOuts.push(document.getElementById("zoom-out-btn"));
+        zoomOuts.push(document.getElementById("zoom-out-btn-optional"));
         canvas = document.createElement("div");
         //canvas.id = 'osmdCanvasDiv';
         //canvas.style.overflowX = 'auto'; // enable horizontal scrolling
@@ -206,6 +214,7 @@ import { OpenSheetMusicDisplay } from '../src/OpenSheetMusicDisplay/OpenSheetMus
                 if (elementsToEnable[i]) { // make sure this element is not null/exists in the index.html, e.g. github.io demo has different index.html
                     if (elementsToEnable[i].style) {
                         elementsToEnable[i].style.visibility = defaultVisibilityValue;
+                        elementsToEnable[i].style.opacity = 1.0;
                     }
                 }
             }
@@ -215,22 +224,31 @@ import { OpenSheetMusicDisplay } from '../src/OpenSheetMusicDisplay/OpenSheetMus
             }
         }
 
-        if (!showControls) {
-            if (divControls) {
-                divControls.style.display = 'none';
+        const optionalControls = document.getElementById('optionalControls');
+        if (optionalControls) {
+            if (showControls) {
+                optionalControls.style.visibility = defaultVisibilityValue;
+                optionalControls.style.opacity = 0.8;
+            } else {
+                optionalControls.style.display = 'none';
             }
         }
+
         if (!showHeader) {
             if (header) {
                 header.style.display = 'none';
             }
+        } else {
+            if (header) {
+                header.style.opacity = 1.0;
+            }
         }
         // Hide error
         error();
 
-        if (!showControls && showZoomControl) {
-            const zoomControlsButtons = document.getElementById('zoomControlsButtons');
-            const zoomControlsString = document.getElementById('zoom-str');
+        if (showControls && showZoomControl) {
+            const zoomControlsButtons = document.getElementById('zoomControlsButtons-optional');
+            const zoomControlsString = document.getElementById('zoom-str-optional'); // actually === zoomDiv above
             const optionalControls = document.getElementById('optionalControls');
             if (optionalControls) {
                 optionalControls.appendChild(zoomControlsButtons);
@@ -284,17 +302,21 @@ import { OpenSheetMusicDisplay } from '../src/OpenSheetMusicDisplay/OpenSheetMus
         custom.appendChild(document.createTextNode("Custom"));
 
         // Create zoom controls
-        if (zoomIn) {
-            zoomIn.onclick = function () {
-                zoom *= 1.2;
-                scale();
-            };
+        for (const zoomIn of zoomIns) {
+            if (zoomIn) {
+                zoomIn.onclick = function () {
+                    zoom *= 1.2;
+                    scale();
+                };
+            }
         }
-        if (zoomOut) {
-            zoomOut.onclick = function () {
-                zoom /= 1.2;
-                scale();
-            };
+        for (const zoomOut of zoomOuts) {
+            if (zoomOut) {
+                zoomOut.onclick = function () {
+                    zoom /= 1.2;
+                    scale();
+                };
+            }
         }
 
         if (skylineDebug) {
@@ -605,7 +627,11 @@ import { OpenSheetMusicDisplay } from '../src/OpenSheetMusicDisplay/OpenSheetMus
     }
 
     function logCanvasSize() {
-        zoomDiv.innerHTML = Math.floor(zoom * 100.0) + "%";
+        for (const zoomDiv of zoomDivs) {
+            if (zoomDiv) {
+                zoomDiv.innerHTML = Math.floor(zoom * 100.0) + "%";
+            }
+        }
     }
 
     function scale() {
@@ -658,11 +684,15 @@ import { OpenSheetMusicDisplay } from '../src/OpenSheetMusicDisplay/OpenSheetMus
         if (selectSample) {
             selectSample.disabled = disabledValue;
         }
-        if (zoomIn) {
-            zoomIn.disabled = disabledValue;
+        for (const zoomIn of zoomIns) {
+            if (zoomIn) {
+                zoomIn.disabled = disabledValue;
+            }
         }
-        if (zoomOut) {
-            zoomOut.disabled = disabledValue;
+        for (const zoomOut of zoomOuts) {
+            if (zoomOut) {
+                zoomOut.disabled = disabledValue;
+            }
         }
     }