Skip to content

Commit

Permalink
WIP: overlay toggle improvements and enabling drawing #8
Browse files Browse the repository at this point in the history
  • Loading branch information
WUOTE committed May 16, 2024
1 parent d622253 commit 3291196
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 11 deletions.
4 changes: 2 additions & 2 deletions public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ html {
margin-left: auto;
margin-right: 2vw;
}
#overlayVisibilityToggleButton {
#overlayVisibilityToggle {
margin-left: auto;
margin-right: 2vw;
}
Expand Down Expand Up @@ -157,7 +157,7 @@ html {
transform: rotate(360deg);
}
}
body.toggle-hidden a#overlayVisibilityToggleButton {
body.toggle-hidden div:has(> #overlayVisibilityToggle) {
visibility: hidden;
}
body.toggle-hidden div.osOverlayHighlight {
Expand Down
18 changes: 16 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,22 @@
<a id="goToMainWebsiteButton" tabindex="0" href="https://runfast.stream" target="\_blank"
class="btn btn-outline-warning text-nowrap" data-bs-trigger="focus" role="button"><i
class="icon-runfast"></i></a>
<a id="overlayVisibilityToggleButton" tabindex="0" class="btn btn-outline-info text-nowrap"
data-bs-trigger="focus" role="button"><i class="bi bi-layers"></i> Toggle overlays</a>
<span id="overlaySpan" class="d-inline-block" tabindex="0" data-bs-toggle="tooltip" data-bs-title="">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="overlayVisibilityToggle">
<label class="form-check-label" for="overlayVisibilityToggle"><i class="bi bi-layers"></i> Show
overlays</label>
</div>
</span>

<!-- TODO: add drawing -->
<!-- <div class="form-check form-switch"> -->
<!-- <input class="form-check-input" type="checkbox" role="switch" id="drawingToggleSwitch"> -->
<!-- <label class="form-check-label" for="drawingToggleSwitch"><i class="bi bi-brush"></i> Draw</label> -->
<!-- </div> -->
<!-- <a id="eraseAnnotationDrawingsButton" tabindex="0" class="btn btn-outline-info text-nowrap"
data-bs-trigger="focus" role="button" onclick="eraseDrawings()"><i class="bi bi-eraser"></i></a> -->

<a id="shareButton" tabindex="0" class="btn btn-outline-success text-nowrap" data-bs-trigger="focus"
data-bs-container="body" data-bs-toggle="popover" data-bs-placement="bottom" data-bs-content="Copied!"
role="button" onclick="getShareUrl();"><i class="bi bi-copy"></i> Copy to clipboard</a>
Expand Down
40 changes: 33 additions & 7 deletions public/js/script.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// TODO: Add annotations
// annotations plugin
// const annotations = new OpenSeadragon.Annotations({ viewer });

// os.initializeAnnotations();

"use strict";

Expand Down Expand Up @@ -351,15 +348,27 @@ const changeMap = (() => {
// modify the DOM to show the current map name based on the contents of the link
// to activate that map
document.getElementById("currentMapName").innerHTML = currentMapLink.innerHTML;

const mytooltip = bootstrap.Tooltip.getInstance("#overlaySpan");
// Quick hack to fix toggle overlays button
const overlaySpan = document.querySelector("#overlaySpan");
switch (mapName) {
case "regular-main-branch":
case "regular-beta":
document.body.classList.remove("toggle-hidden");
// document.body.classList.remove("toggle-hidden");
document.querySelector("#overlayVisibilityToggle").disabled = false;
// overlaySpan.dataset["bsToggle"] = "tooltip";
// overlaySpan.dataset["bsPlacement"] = "bottom";
// overlaySpan.innerText = "";
mytooltip.disable();
break;
default:
document.body.classList.add("toggle-hidden");
// document.body.classList.add("toggle-hidden");

document.querySelector("#overlayVisibilityToggle").disabled = true;
mytooltip.enable();
overlaySpan.dataset["bsToggle"] = "tooltip";
overlaySpan.dataset["bsPlacement"] = "bottom";
overlaySpan.dataset["bsTitle"] = "Overlays are not available for this map";
}

// update url to refer to the map we just selected
Expand Down Expand Up @@ -502,7 +511,7 @@ const popoverTriggerList = document.querySelectorAll('[data-bs-toggle="popover"]
const popoverList = [...popoverTriggerList].map((popoverTriggerEl) => new bootstrap.Popover(popoverTriggerEl));

let allOverlays = document.getElementsByClassName("osOverlayHighlight");
document.querySelector("#overlayVisibilityToggleButton").addEventListener("click", function () {
document.querySelector("#overlayVisibilityToggle").addEventListener("click", function () {
const updatedUrlParamsFromOverlaysToggle = new URLSearchParams(window.location.search);
const currentMapURLFromOverlaysToggle = String(updatedUrlParamsFromOverlaysToggle.get("map"));
if (overlaysState) {
Expand Down Expand Up @@ -605,3 +614,20 @@ function addTooltips() {
const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]');
const tooltipList = [...tooltipTriggerList].map((tooltipTriggerEl) => new bootstrap.Tooltip(tooltipTriggerEl));
}

const drawingToggleSwitch = document.getElementById("drawingToggleSwitch");

function eraseDrawings() {
os.annotations.clean();
console.log("cleared");
}

drawingToggleSwitch.addEventListener("change", (event) => {
if (event.currentTarget.checked && os.areAnnotationsActive() == false) {
os.initializeAnnotations();
console.log("checked");
} else {
os.shutdownAnnotations();
console.log("not checked");
}
});

0 comments on commit 3291196

Please sign in to comment.