Fix attachment box bugs

This commit is contained in:
windingwind 2024-01-13 21:50:24 +08:00 committed by Dan Stillman
parent b34d0d2acc
commit 61a5704dd4
5 changed files with 47 additions and 42 deletions

View file

@ -244,7 +244,7 @@
} }
} }
render() { async render() {
Zotero.debug('Refreshing attachment box'); Zotero.debug('Refreshing attachment box');
if (this.usePreview) { if (this.usePreview) {
@ -259,53 +259,46 @@
let indexStatusRow = this._id('indexStatusRow'); let indexStatusRow = this._id('indexStatusRow');
let selectButton = this._id('select-button'); let selectButton = this._id('select-button');
let fileExists = await IOUtils.exists(this._item.getFilePath());
let isImportedURL = this.item.attachmentLinkMode == Zotero.Attachments.LINK_MODE_IMPORTED_URL; let isImportedURL = this.item.attachmentLinkMode == Zotero.Attachments.LINK_MODE_IMPORTED_URL;
let isLinkedURL = this.item.attachmentLinkMode == Zotero.Attachments.LINK_MODE_LINKED_URL; let isLinkedURL = this.item.attachmentLinkMode == Zotero.Attachments.LINK_MODE_LINKED_URL;
// Metadata for URL's // URL
if (isImportedURL || isLinkedURL) { if (this.displayURL && (isImportedURL || isLinkedURL)) {
// URL let urlSpec = this.item.getField('url');
if (this.displayURL) { urlField.setAttribute('value', urlSpec);
let urlSpec = this.item.getField('url'); urlField.setAttribute('tooltiptext', urlSpec);
urlField.setAttribute('value', urlSpec); urlField.setAttribute('hidden', false);
urlField.setAttribute('tooltiptext', urlSpec); if (this.clickableLink) {
urlField.setAttribute('hidden', false); urlField.onclick = function (event) {
if (this.clickableLink) { if (event.button == 0) {
urlField.onclick = function (event) { ZoteroPane_Local.loadURI(this.value, event);
if (event.button == 0) { }
ZoteroPane_Local.loadURI(this.value, event); };
} urlField.className = 'zotero-text-link';
};
urlField.className = 'zotero-text-link';
}
else {
urlField.className = '';
}
urlField.hidden = false;
} }
else { else {
urlField.hidden = true; urlField.className = '';
} }
urlField.hidden = false;
// Access date }
if (this.displayAccessed) { else {
let itemAccessDate = this.item.getField('accessDate'); urlField.hidden = true;
if (itemAccessDate) { }
itemAccessDate = Zotero.Date.sqlToDate(itemAccessDate, true);
this._id("accessed").value = itemAccessDate.toLocaleString(); // Access date
accessed.hidden = false; if (this.displayAccessed && isImportedURL) {
} let itemAccessDate = this.item.getField('accessDate');
else { if (itemAccessDate) {
accessed.hidden = true; itemAccessDate = Zotero.Date.sqlToDate(itemAccessDate, true);
} this._id("accessed").value = itemAccessDate.toLocaleString();
accessed.hidden = false;
} }
else { else {
accessed.hidden = true; accessed.hidden = true;
} }
} }
// Metadata for files
else { else {
urlField.hidden = true;
accessed.hidden = true; accessed.hidden = true;
} }
@ -345,7 +338,7 @@
pagesRow.hidden = true; pagesRow.hidden = true;
} }
if (this.displayDateModified && !this._item.isWebAttachment()) { if (this.displayDateModified && fileExists && !this._item.isWebAttachment()) {
// Conflict resolution uses a modal window, so promises won't work, but // Conflict resolution uses a modal window, so promises won't work, but
// the sync process passes in the file mod time as dateModified // the sync process passes in the file mod time as dateModified
if (this.synchronous) { if (this.synchronous) {
@ -371,7 +364,7 @@
} }
// Full-text index information // Full-text index information
if (this.displayIndexed) { if (this.displayIndexed && fileExists && await Zotero.FullText.canIndex(this.item)) {
this.updateItemIndexedState() this.updateItemIndexedState()
.then(function () { .then(function () {
if (!this.item) return; if (!this.item) return;
@ -429,7 +422,7 @@
str = 'general.yes'; str = 'general.yes';
break; break;
} }
indexStatus.value = Zotero.getString(str); indexStatus.textContent = Zotero.getString(str);
// Reindex button tooltip (string stored in zotero.properties) // Reindex button tooltip (string stored in zotero.properties)
str = Zotero.getString('pane.items.menu.reindexItem'); str = Zotero.getString('pane.items.menu.reindexItem');

View file

@ -70,7 +70,7 @@
transparent="transparent" transparent="transparent"
src="resource://zotero/reader/reader.html" src="resource://zotero/reader/reader.html"
flex="1"/> flex="1"/>
<html:img id="image-preview"></html:img> <html:img id="image-preview" class="media-preview"></html:img>
<html:span class="icon"></html:span> <html:span class="icon"></html:span>
<html:div class="btn-container"> <html:div class="btn-container">
<toolbarbutton id="prev" class="btn-prev" ondblclick="event.stopPropagation()" <toolbarbutton id="prev" class="btn-prev" ondblclick="event.stopPropagation()"
@ -324,6 +324,7 @@
media = document.createElement("audio"); media = document.createElement("audio");
} }
media.id = mediaID; media.id = mediaID;
media.classList.add("media-preview");
this._id("next-preview").after(media); this._id("next-preview").after(media);
} }
media.onload = () => { media.onload = () => {

View file

@ -130,6 +130,10 @@
grid-template-columns: subgrid; grid-template-columns: subgrid;
grid-column: span 2; grid-column: span 2;
&[hidden] {
display: none;
}
// On hover of the meta-row, reveal all hidden icons // On hover of the meta-row, reveal all hidden icons
// unless there's .noHover class which keeps everything hidden // unless there's .noHover class which keeps everything hidden
&:not(.noHover):hover .show-on-hover, &:not(.noHover):hover .show-on-hover,

View file

@ -25,8 +25,10 @@ attachment-box {
#index-status { #index-status {
margin-inline: 0; margin-inline: 0;
margin-block: 0; margin-block: 0;
height: 22px; margin-top: 2px;
padding: 2px 4px; @include comfortable {
margin-top: 3px;
}
} }
#reindex #reindex

View file

@ -49,6 +49,7 @@ attachment-preview {
pdf: "attachment-pdf", pdf: "attachment-pdf",
snapshot: "attachment-snapshot", snapshot: "attachment-snapshot",
epub: "attachment-epub", epub: "attachment-epub",
image: "document",
); );
@each $cls, $icon in $preview-icons { @each $cls, $icon in $preview-icons {
@ -176,6 +177,10 @@ attachment-preview {
display: none; display: none;
} }
.media-preview {
display: none !important;
}
.icon { .icon {
display: inline-block; display: inline-block;
opacity: 1; opacity: 1;