Skip to content

Commit

Permalink
Open original media in new tab instead of canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuuuube committed Dec 27, 2024
1 parent 7c1a454 commit 2fed539
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
14 changes: 14 additions & 0 deletions ext/js/display/display-content-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

import {EventListenerCollection} from '../core/event-listener-collection.js';
import {base64ToArrayBuffer} from '../data/array-buffer-util.js';

/**
* The content manager which is used when generating HTML display content.
Expand Down Expand Up @@ -86,6 +87,19 @@ export class DisplayContentManager {
this._loadMediaRequests = [];
}

/**
* @param {string} path
* @param {string} dictionary
* @param {Window} window
*/
async openMediaInTab(path, dictionary, window) {
const data = await this._display.application.api.getMedia([{path, dictionary}]);
const buffer = base64ToArrayBuffer(data[0].content);
const blob = new Blob([buffer], {type: data[0].mediaType});
const blobUrl = URL.createObjectURL(blob);
window.open(blobUrl, '_blank')?.focus();
}

/**
* @param {MouseEvent} e
*/
Expand Down
11 changes: 2 additions & 9 deletions ext/js/display/structured-content-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,8 @@ export class StructuredContentGenerator {

if (this._contentManager instanceof DisplayContentManager) {
node.addEventListener('click', () => {
/** @type {HTMLCanvasElement | null} */
const canvasElement = imageContainer.querySelector('.gloss-image');
if (canvasElement) {
canvasElement.toBlob((blob) => {
if (blob) {
const blobUrl = URL.createObjectURL(blob);
window.open(blobUrl, '_blank')?.focus();
}
});
if (this._contentManager instanceof DisplayContentManager) {
void this._contentManager.openMediaInTab(path, dictionary, window);
}
});
}
Expand Down

0 comments on commit 2fed539

Please sign in to comment.