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

Fix uncollapse link and clicking on images #1705

Merged
merged 6 commits into from
Dec 27, 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
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@
"ext/js/core/extension-error.js",
"ext/js/core/json.js",
"ext/js/data/anki-note-data-creator.js",
"ext/js/data/array-buffer-util.js",
"ext/js/dictionary/dictionary-data-util.js",
"ext/js/display/display-content-manager.js",
"ext/js/display/pronunciation-generator.js",
Expand Down
1 change: 0 additions & 1 deletion ext/css/display.css
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,6 @@ button.action-button:active {
.entry {
padding: var(--entry-vertical-padding) var(--entry-horizontal-padding);
position: relative;
content-visibility: auto;
contain-intrinsic-height: auto 500px;
}
.entry+.entry {
Expand Down
2 changes: 0 additions & 2 deletions ext/css/structured-content.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
}
.gloss-image-link:hover {
color: var(--accent-color-dark);
}
.gloss-image-link[href]:hover {
cursor: pointer;
}
.gloss-image-container-overlay {
Expand Down
6 changes: 0 additions & 6 deletions ext/data/structured-content-style.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@
["color", "inherit"]
]
},
{
"selectors": [".gloss-image-link[href]:hover"],
"styles": [
["cursor", "pointer"]
]
},
{
"selectors": [".gloss-image-container-overlay"],
"styles": [
Expand Down
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
12 changes: 12 additions & 0 deletions ext/js/display/structured-content-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ export class StructuredContentGenerator {
const overlay = this._createElement('span', 'gloss-image-container-overlay');
imageContainer.appendChild(overlay);

const linkText = this._createElement('span', 'gloss-image-link-text');
linkText.textContent = 'Image';
node.appendChild(linkText);

if (this._contentManager instanceof DisplayContentManager) {
node.addEventListener('click', () => {
if (this._contentManager instanceof DisplayContentManager) {
void this._contentManager.openMediaInTab(path, dictionary, window);
}
});
}

node.dataset.path = path;
node.dataset.dictionary = dictionary;
node.dataset.imageLoadState = 'not-loaded';
Expand Down
24 changes: 12 additions & 12 deletions test/data/anki-note-builder-test-results.json

Large diffs are not rendered by default.

Loading