Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added copy to clipboard functionality for TextRightPanel. #22

Merged
merged 1 commit into from
Jul 10, 2024
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import '../../../modules/uv-dialogues-module/css/styles.less';
@import '../../../modules/uv-moreinforightpanel-module/css/styles.less';
@import '../../../modules/uv-textrightpanel-module/css/styles.less';
@import '../../../modules/uv-pagingheaderpanel-module/css/styles.less';
@import '../../../modules/uv-openseadragoncenterpanel-module/css/styles.less';
@import '../../../modules/uv-contentleftpanel-module/css/styles.less';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ import { TextRightPanel as TextRightPanelConfig } from "../../BaseConfig";
import { Events } from "../../../../Events";
import OpenSeadragonExtension from "../../extensions/uv-openseadragon-extension/Extension";
import OpenSeadragon from "openseadragon";
import { Clipboard } from "@edsilv/utils";

export class TextRightPanel extends RightPanel<TextRightPanelConfig> {
$transcribedText: JQuery;
$existingAnnotation: JQuery = $();
$copyButton: JQuery;
$copiedText: JQuery;
currentCanvasIndex: number = 0;
clipboardText: string = '';

constructor($element: JQuery) {
super($element);
Expand All @@ -19,6 +23,44 @@ export class TextRightPanel extends RightPanel<TextRightPanelConfig> {

super.create();

if (this.config.options.copyToClipboardEnabled && Clipboard.supportsCopy()) {
this.$copyButton = $(
'<div class="copyText" alt="' +
this.config.content.copyToClipboard +
'" title="' +
this.config.content.copyToClipboard +
'"></div>'
);

this.$copiedText = $(
'<div class="copiedText">' +
this.config.content.copiedToClipboard +
' </div>'
);
this.$copiedText.hide();
this.$copyButton.hide();

this.$copyButton.append(this.$copiedText);

const that = this;
this.$top.on('mouseenter', () => {
that.$copyButton.show();
});
this.$top.on('mouseleave', () => {
that.$copyButton.hide();
});
this.$copyButton.on('mouseleave', () => {
that.$copiedText.hide();
});

this.$copyButton.on('click', () => {
let text = that.$transcribedText.attr('data-text');
this.copyText(text);
});

this.$top.append(this.$copyButton);
}

this.extensionHost.on(Events.LOAD, async (e) => {
if (this.currentCanvasIndex == this.extension.helper.canvasIndex) {
this.$existingAnnotation = $('.lineAnnotation.current');
Expand All @@ -28,6 +70,7 @@ export class TextRightPanel extends RightPanel<TextRightPanelConfig> {
this.currentCanvasIndex = this.extension.helper.canvasIndex;

this.$main.html('');
this.clipboardText = '';
this.removeLineAnnotationRects();
let canvases = this.extension.getCurrentCanvases();
canvases.sort((a, b) => (a.index as number - b.index as number));
Expand Down Expand Up @@ -56,6 +99,7 @@ export class TextRightPanel extends RightPanel<TextRightPanelConfig> {
});

this.setTitle(this.config.content.title);
this.$top.parent().addClass('rightTextPanel');
}

toggleFinish(): void {
Expand Down Expand Up @@ -95,6 +139,7 @@ export class TextRightPanel extends RightPanel<TextRightPanelConfig> {
const width = Number(e.getAttribute('WIDTH'));
const height = Number(e.getAttribute('HEIGHT'));
let text = t.join(' ');
this.clipboardText += text;

let line = $('<p id="line-annotation-' + i + '" class="lineAnnotation" tabindex="0">' + text + '</p>');

Expand Down Expand Up @@ -137,6 +182,7 @@ export class TextRightPanel extends RightPanel<TextRightPanelConfig> {
}
if (lines.length > 0) {
this.$transcribedText.append(lines);
this.$transcribedText.attr('data-text', this.clipboardText);
} else {
this.$transcribedText.append($('<div>' + this.content.textNotFound + '</div>'));
}
Expand All @@ -155,6 +201,16 @@ export class TextRightPanel extends RightPanel<TextRightPanelConfig> {
}
}

copyText(text: string): void {
Clipboard.copy(text);

this.$copiedText.show();

setTimeout(() => {
this.$copiedText.hide();
}, 2000);
}

setCurrentLineAnnotationRect(e: any): void {
$('div.lineAnnotationRect').each((i: Number, lineAnnotationRect: any) => {
if ($(lineAnnotationRect).hasClass('current')) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
@import "@iiif/iiif-metadata-component/dist-css/styles.less";

.uv {
.rightPanel {
.rightTextPanel {
.top {
display: flex;

.copyText {
position: absolute;
background-image: data-uri('../img/copy_overlay.png') !important;
width: 15px;
height: 15px;
right: 40px;
top: 10px;
cursor: pointer;
}

.copiedText {
color: @text-color !important;
position: absolute;
top: 18px;
right: -10px;
white-space: nowrap;
padding: 4px;
text-transform: none;
background-color: #343434;
z-index: 1;
border: 1px solid #9a9a9a;
border-radius: 2px;
}

.title {
text-transform: uppercase;
position: relative;
}
}

Expand All @@ -21,13 +48,11 @@
}

.noData {
padding: 0 @padding-medium-horizontal (@padding-medium-vertical * 2)
@padding-medium-horizontal;
padding: 0 @padding-medium-horizontal (@padding-medium-vertical * 2) @padding-medium-horizontal;
}

.groups {
padding: @padding-medium-vertical @padding-medium-horizontal
(@padding-medium-vertical * 2) @padding-medium-horizontal;
padding: @padding-medium-vertical @padding-medium-horizontal (@padding-medium-vertical * 2) @padding-medium-horizontal;

.group {
.header {
Expand Down Expand Up @@ -65,4 +90,4 @@
}
}
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/uv-iiif-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
},
"textRightPanel": {
"options": {
"panelExpandedWidth": 270
"panelExpandedWidth": 270,
"copyToClipboardEnabled": true
}
},
"moreInfoRightPanel": {
Expand Down