From e6f1983073a3712e55779b3b1b43f99e915f89e3 Mon Sep 17 00:00:00 2001 From: Abe Jellinek Date: Fri, 4 Apr 2025 12:27:02 -0400 Subject: [PATCH] Make item pane attachments/notes/related item rows draggable (#5184) --- chrome/content/zotero/elements/attachmentRow.js | 5 +++++ chrome/content/zotero/elements/notesBox.js | 4 ++++ chrome/content/zotero/elements/relatedBox.js | 4 ++++ chrome/content/zotero/xpcom/utilities_internal.js | 7 ++++++- 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/elements/attachmentRow.js b/chrome/content/zotero/elements/attachmentRow.js index 204b247dd4..f7e11abb90 100644 --- a/chrome/content/zotero/elements/attachmentRow.js +++ b/chrome/content/zotero/elements/attachmentRow.js @@ -82,6 +82,7 @@ import { getCSSItemTypeIcon } from 'components/icons'; this._removeButton = this.querySelector('.zotero-clicky-minus'); this._attachmentButton.addEventListener('click', this._handleAttachmentClick); + this._attachmentButton.addEventListener('dragstart', this._handleAttachmentDragStart); this._annotationButton.addEventListener('click', this._handleAnnotationClick); if (this.editable) { @@ -100,6 +101,10 @@ import { getCSSItemTypeIcon } from 'components/icons'; ZoteroPane.viewAttachment(this._attachment.id, event); }; + _handleAttachmentDragStart = (event) => { + Zotero.Utilities.Internal.onDragItems(event, [this._attachment.id]); + }; + _handleAnnotationClick = () => { // TODO: jump to annotations pane let pane; diff --git a/chrome/content/zotero/elements/notesBox.js b/chrome/content/zotero/elements/notesBox.js index 9dc1139977..a3ab5bee4f 100644 --- a/chrome/content/zotero/elements/notesBox.js +++ b/chrome/content/zotero/elements/notesBox.js @@ -118,6 +118,10 @@ import { getCSSItemTypeIcon } from 'components/icons'; row.append(remove); } + row.addEventListener('dragstart', (event) => { + Zotero.Utilities.Internal.onDragItems(event, [id]); + }); + body.append(row); } diff --git a/chrome/content/zotero/elements/relatedBox.js b/chrome/content/zotero/elements/relatedBox.js index ab97717fc8..4ef7a4ff5d 100644 --- a/chrome/content/zotero/elements/relatedBox.js +++ b/chrome/content/zotero/elements/relatedBox.js @@ -144,6 +144,10 @@ import { getCSSItemTypeIcon } from 'components/icons'; row.append(remove); } + row.addEventListener('dragstart', (event) => { + Zotero.Utilities.Internal.onDragItems(event, [id]); + }); + body.append(row); } this._updateCount(); diff --git a/chrome/content/zotero/xpcom/utilities_internal.js b/chrome/content/zotero/xpcom/utilities_internal.js index 730e7c09e1..3694213cb7 100644 --- a/chrome/content/zotero/xpcom/utilities_internal.js +++ b/chrome/content/zotero/xpcom/utilities_internal.js @@ -3289,7 +3289,12 @@ Zotero.Utilities.Internal.OpenURL = { }, }; -Zotero.Utilities.Internal.onDragItems = function (event, itemIDs, dragImage) { +/** + * @param {DragEvent} event + * @param {number[]} itemIDs + * @param {Element} [dragImage] + */ +Zotero.Utilities.Internal.onDragItems = function (event, itemIDs, dragImage = event.currentTarget) { // See note in LibraryTreeView::setDropEffect() if (Zotero.isWin || Zotero.isLinux) { event.dataTransfer.effectAllowed = 'copyMove';