Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion __tests__/image_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ describe("Universal Viewer", () => {
await page.waitForSelector(overlay, { visible: true });

const text = await page.$eval(heading, (el) => el.textContent.trim());
expect(text).toBe("Adjust image");
expect(text).toBe("Adjust Image");

await page.$eval(closeBtn, (el) => el.click());

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import React from "react";
import Button from "../uv-shared-module/Button";
import { IIIFEvents } from "../../IIIFEvents";
import { IIIFExtensionHost } from "../../IIIFExtensionHost";
import { OpenSeadragonExtensionEvents } from "../../extensions/uv-openseadragon-extension/Events";
import { Config } from "../../extensions/uv-openseadragon-extension/config/Config";
import {
AdjustImage,
FitImage,
Layers,
Rotate,
ZoomIn,
ZoomOut,
} from "../uv-shared-module/Icons";

type CenterPanelConfig = Config["modules"]["openSeadragonCenterPanel"];

interface Props {
extensionHost: IIIFExtensionHost;
content: CenterPanelConfig["content"];
showHomeButton: boolean;
showAdjustImageButton: boolean;
hasChoices: boolean;
}

const ImageControls: React.FC<Props> = ({
extensionHost,
content,
showHomeButton,
showAdjustImageButton,
hasChoices,
}) => {
return (
<>
<Button
className="zoomIn imageControlButton viewportNavButton"
label={content.zoomIn}
tooltipPlacement="right"
onClick={() =>
extensionHost.publish(OpenSeadragonExtensionEvents.ZOOM_IN)
}
>
<ZoomIn />
</Button>

<Button
className="zoomOut imageControlButton viewportNavButton"
label={content.zoomOut}
tooltipPlacement="right"
onClick={() =>
extensionHost.publish(OpenSeadragonExtensionEvents.ZOOM_OUT)
}
>
<ZoomOut />
</Button>

{showHomeButton && (
<Button
className="goHome imageControlButton viewportNavButton"
label={content.goHome}
tooltipPlacement="right"
onClick={() =>
extensionHost.publish(OpenSeadragonExtensionEvents.GO_HOME)
}
>
<FitImage />
</Button>
)}

<Button
className="rotate imageControlButton viewportNavButton"
label={content.rotateRight}
tooltipPlacement="right"
onClick={() =>
extensionHost.publish(OpenSeadragonExtensionEvents.ROTATE)
}
>
<Rotate />
</Button>

{showAdjustImageButton && (
<Button
className="adjustImage imageControlButton viewportNavButton"
label={content.adjustImage}
tooltipPlacement="right"
onClick={() =>
extensionHost.publish(IIIFEvents.SHOW_ADJUSTIMAGE_DIALOGUE)
}
>
<AdjustImage />
</Button>
)}

{hasChoices && (
<Button
className="choiceSwitch imageControlButton viewportNavButton"
label={content.layers}
tooltipPlacement="right"
onClick={() =>
extensionHost.publish(IIIFEvents.SHOW_CHOICE_SWITCH_DIALOGUE)
}
>
<Layers />
</Button>
)}
</>
);
};

export default ImageControls;
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import { CenterPanel } from "../uv-shared-module/CenterPanel";
import { OpenSeadragonExtensionEvents } from "../../extensions/uv-openseadragon-extension/Events";
import { Config } from "../../extensions/uv-openseadragon-extension/config/Config";

import { createElement } from "react";
import { createRoot, Root } from "react-dom/client";
import ImageControls from "./ImageControls";

export class OpenSeadragonCenterPanel extends CenterPanel<
Config["modules"]["openSeadragonCenterPanel"]
> {
Expand All @@ -18,18 +22,26 @@ export class OpenSeadragonCenterPanel extends CenterPanel<
showAdjustImageButton: boolean;
showHomeButton: boolean;

$goHomeButton: JQuery;
$nextButton: JQuery;
$prevButton: JQuery;
$rotateButton: JQuery;
$zoomInButton: JQuery;
$zoomOutButton: JQuery;
$adjustImageButton: JQuery;
$choiceSwitchButton: JQuery;

$navigator: JQuery;
$imageControlsContainer: JQuery;

imageControlsRoot: Root;
hasChoices: boolean = false;

// The AdjustImageDialogue and ChoiceSwitchDialogue return focus to the old jquery buttons,
// so these getters allow them access - but ultimately the dialogues should be redesigned and become part of the ImageControls react component,
// then we can remove this workaround.
get $adjustImageButton(): JQuery {
return this.$imageControlsContainer.find(".adjustImage");
}

get $choiceSwitchButton(): JQuery {
return this.$imageControlsContainer.find(".choiceSwitch");
}

constructor($element: JQuery) {
super($element);
}
Expand Down Expand Up @@ -103,151 +115,22 @@ export class OpenSeadragonCenterPanel extends CenterPanel<
'<div class="imageControlsContainer"></div>'
);
this.$content.prepend(this.$imageControlsContainer);

this.$zoomInButton = $("<button />");
this.$imageControlsContainer.append(this.$zoomInButton);
this.$zoomInButton.attr("tabindex", 0);
this.$zoomInButton.attr("title", this.content.zoomIn);
this.$zoomInButton.attr("aria-label", this.content.zoomIn);
this.$zoomInButton.addClass("zoomIn imageControlButton viewportNavButton");
this.$zoomInButton.html(` <svg
width=30
height=30
viewBox="0 0 30 30"
xmlns="http://www.w3.org/2000/svg"
fill="currentColor"
>
<polygon points="22,14 16,14 16,8 14,8 14,14 8,14 8,16 14,16 14,22 16,22 16,16 22,16 " />
</svg>`);
this.onAccessibleClick(this.$zoomInButton, () => {
this.extensionHost.publish(OpenSeadragonExtensionEvents.ZOOM_IN);
});

this.$zoomOutButton = $("<button />");
this.$imageControlsContainer.append(this.$zoomOutButton);
this.$zoomOutButton.attr("tabindex", 0);
this.$zoomOutButton.attr("title", this.content.zoomOut);
this.$zoomOutButton.attr("aria-label", this.content.zoomOut);
this.$zoomOutButton.addClass(
"zoomOut imageControlButton viewportNavButton"
);
this.$zoomOutButton.html(`<svg
width=30
height=30
viewBox="0 0 30 30"
xmlns="http://www.w3.org/2000/svg"
fill="currentColor"
>
<rect x="8" y="14" width="14" height="2" />
</svg>
`);
this.onAccessibleClick(this.$zoomOutButton, () => {
this.extensionHost.publish(OpenSeadragonExtensionEvents.ZOOM_OUT);
});

if (this.showHomeButton) {
this.$goHomeButton = $("<button />");
this.$imageControlsContainer.append(this.$goHomeButton);
this.$goHomeButton.attr("tabindex", 0);
this.$goHomeButton.attr("title", this.content.goHome);
this.$goHomeButton.attr("aria-label", this.content.goHome);
this.$goHomeButton.addClass(
"goHome imageControlButton viewportNavButton"
);
this.onAccessibleClick(this.$goHomeButton, () => {
this.extensionHost.publish(OpenSeadragonExtensionEvents.GO_HOME);
});
// todo: add goHome SVG and remove icon as background image from styles.less
}

this.$rotateButton = $("<button />");
this.$imageControlsContainer.append(this.$rotateButton);
this.$rotateButton.attr("tabindex", 0);
this.$rotateButton.attr("title", this.content.rotateRight);
this.$rotateButton.attr("aria-label", this.content.rotateRight);
this.$rotateButton.addClass("rotate imageControlButton viewportNavButton");
this.$rotateButton.html(`<svg
width=30
height=30
viewBox="0 0 30 30"
xmlns="http://www.w3.org/2000/svg"
fill="currentColor"
>
<g>
<path
d="M15,22.5c-2.1,0-3.9-0.7-5.3-2.2S7.5,17.1,7.5,15s0.7-3.9,2.2-5.3s3.2-2.2,5.3-2.2
c1.1,0,2.1,0.2,3.1,0.7s1.8,1.1,2.5,1.9V7.5h1.9v6.6h-6.6v-1.9h3.9c-0.5-0.9-1.2-1.6-2.1-2.1C17,9.6,16,9.4,15,9.4
c-1.6,0-2.9,0.5-4,1.6s-1.6,2.4-1.6,4s0.5,2.9,1.6,4s2.4,1.6,4,1.6c1.2,0,2.3-0.3,3.3-1s1.6-1.6,2-2.7h2c-0.4,1.7-1.3,3-2.7,4.1
S16.7,22.5,15,22.5z"
/>
</g>
</svg>`);

this.onAccessibleClick(this.$rotateButton, () => {
this.extensionHost.publish(OpenSeadragonExtensionEvents.ROTATE);
});

if (this.showAdjustImageButton) {
this.$adjustImageButton = $("<button />");
this.$imageControlsContainer.append(this.$adjustImageButton);
this.$adjustImageButton.attr("title", this.content.adjustImage);
this.$adjustImageButton.attr("aria-label", this.content.adjustImage);
this.$adjustImageButton.addClass(
"adjustImage imageControlButton viewportNavButton"
);
this.$adjustImageButton.attr("tabindex", 0);
this.$adjustImageButton.onPressed(() => {
this.extensionHost.publish(IIIFEvents.SHOW_ADJUSTIMAGE_DIALOGUE);
});
this.$adjustImageButton.html(` <svg
width="30"
height="30"
viewBox="0 0 30 30"
xmlns="http://www.w3.org/2000/svg"
fill="currentColor"
>
<g>
<path
d="M15,22.5c-1,0-2-0.2-2.9-0.6c-0.9-0.4-1.7-0.9-2.4-1.6c-0.7-0.7-1.2-1.5-1.6-2.4
C7.7,17,7.5,16,7.5,15s0.2-2,0.6-2.9S9,10.4,9.7,9.7c0.7-0.7,1.5-1.2,2.4-1.6C13,7.7,14,7.5,15,7.5s2,0.2,2.9,0.6s1.7,0.9,2.4,1.6
c0.7,0.7,1.2,1.5,1.6,2.4c0.4,0.9,0.6,1.9,0.6,2.9s-0.2,2-0.6,2.9c-0.4,0.9-0.9,1.7-1.6,2.4c-0.7,0.7-1.5,1.2-2.4,1.6
C17,22.3,16,22.5,15,22.5z M15.8,20.9c1.5-0.2,2.7-0.8,3.7-2s1.5-2.4,1.5-4s-0.5-2.9-1.5-4s-2.3-1.8-3.7-2V20.9z"
/>
</g>
</svg>`);
this.onAccessibleClick(this.$adjustImageButton, () => {
this.extensionHost.publish(IIIFEvents.SHOW_ADJUSTIMAGE_DIALOGUE);
});
}

this.createChoiceSwitch();
this.imageControlsRoot = createRoot(this.$imageControlsContainer[0]);
this.renderImageControls();
}

createChoiceSwitch(): void {
this.$choiceSwitchButton = this.$rotateButton.clone();
this.$choiceSwitchButton.attr("aria-label", this.content.layers);
this.$choiceSwitchButton.attr("title", this.content.layers);
this.$choiceSwitchButton.switchClass("rotate", "choiceSwitch");
this.$choiceSwitchButton.attr("tabindex", 0);
this.$choiceSwitchButton.css("visibility", "hidden");
// this svg is a hacky transformation of the google icons svg - will need to make a proper one when we add the svg icon library
this.$choiceSwitchButton.html(
`<svg xmlns="http://www.w3.org/2000/svg" width="30" height="30"
viewBox="0 0 30 30" fill="currentColor">
<g transform="translate(15 15) scale(0.0185) translate(-480 480)">
<path d="M480-118 120-398l66-50 294 228 294-228 66 50-360 280Zm0-202L120-600l360-280 360 280-360 280Zm0-280Zm0 178 230-178-230-178-230 178 230 178Z"/>
</g>
</svg>`
renderImageControls(): void {
if (!this.imageControlsRoot) return;

this.imageControlsRoot.render(
createElement(ImageControls, {
extensionHost: this.extensionHost,
content: this.content,
showHomeButton: this.showHomeButton,
showAdjustImageButton: this.showAdjustImageButton,
hasChoices: this.hasChoices,
})
);

if (this.showAdjustImageButton && this.$adjustImageButton) {
this.$choiceSwitchButton.insertAfter(this.$adjustImageButton);
} else {
this.$choiceSwitchButton.insertAfter(this.$rotateButton);
}
this.onAccessibleClick(this.$choiceSwitchButton, () => {
this.extensionHost.publish(IIIFEvents.SHOW_CHOICE_SWITCH_DIALOGUE);
});
}

indicesIncludeChoices(indices: number[]): boolean {
Expand All @@ -258,15 +141,9 @@ export class OpenSeadragonCenterPanel extends CenterPanel<
}

updateChoiceSwitchVisibility(): void {
if (!this.$choiceSwitchButton) return;

const indices = this.extension.getPagedIndices();
const hasChoices = this.indicesIncludeChoices(indices);

this.$choiceSwitchButton.css(
"visibility",
hasChoices ? "visible" : "hidden"
);
this.hasChoices = this.indicesIncludeChoices(indices);
this.renderImageControls();
}

createNavigationButtons(): void {
Expand Down
Loading