Skip to content

Commit 5fc4451

Browse files
committed
Display /Subj field in annotation popup header
1 parent 30d060c commit 5fc4451

3 files changed

Lines changed: 49 additions & 2 deletions

File tree

src/core/annotation.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,16 @@ class Annotation {
922922
this._title = this._parseStringHelper(title);
923923
}
924924

925+
/**
926+
* Set the subject.
927+
*
928+
* @param {string} subject - The subject of the annotation (PDF /Subj entry),
929+
* displayed alongside the title in annotation popups.
930+
*/
931+
setSubject(subject) {
932+
this._subject = this._parseStringHelper(subject);
933+
}
934+
925935
/**
926936
* Set the contents.
927937
*
@@ -1657,6 +1667,9 @@ class MarkupAnnotation extends Annotation {
16571667
this.setTitle(parent.get("T"));
16581668
this.data.titleObj = this._title;
16591669

1670+
this.setSubject(parent.get("Subj"));
1671+
this.data.subjectObj = this._subject;
1672+
16601673
this.setContents(parent.get("Contents"));
16611674
this.data.contentsObj = this._contents;
16621675

@@ -1686,6 +1699,9 @@ class MarkupAnnotation extends Annotation {
16861699
} else {
16871700
this.data.titleObj = this._title;
16881701

1702+
this.setSubject(dict.get("Subj"));
1703+
this.data.subjectObj = this._subject;
1704+
16891705
this.setCreationDate(dict.get("CreationDate"));
16901706
this.data.creationDate = this.creationDate;
16911707

@@ -3985,6 +4001,9 @@ class PopupAnnotation extends Annotation {
39854001
this.setTitle(parentItem.get("T"));
39864002
this.data.titleObj = this._title;
39874003

4004+
this.setSubject(parentItem.get("Subj"));
4005+
this.data.subjectObj = this._subject;
4006+
39884007
this.setContents(parentItem.get("Contents"));
39894008
this.data.contentsObj = this._contents;
39904009

src/display/annotation_layer.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,7 @@ class AnnotationElement {
750750
data: {
751751
color: data.color,
752752
titleObj: data.titleObj,
753+
subjectObj: data.subjectObj,
753754
modificationDate,
754755
contentsObj,
755756
richText: data.richText,
@@ -2374,6 +2375,7 @@ class PopupAnnotationElement extends AnnotationElement {
23742375
container: this.container,
23752376
color: this.data.color,
23762377
titleObj: this.data.titleObj,
2378+
subjectObj: this.data.subjectObj,
23772379
modificationDate: this.data.modificationDate || this.data.creationDate,
23782380
contentsObj: this.data.contentsObj,
23792381
richText: this.data.richText,
@@ -2455,6 +2457,8 @@ class PopupElement {
24552457

24562458
#titleObj = null;
24572459

2460+
#subjectObj = null;
2461+
24582462
#updates = null;
24592463

24602464
#wasVisible = false;
@@ -2468,6 +2472,7 @@ class PopupElement {
24682472
color,
24692473
elements,
24702474
titleObj,
2475+
subjectObj,
24712476
modificationDate,
24722477
contentsObj,
24732478
richText,
@@ -2479,6 +2484,7 @@ class PopupElement {
24792484
}) {
24802485
this.#container = container;
24812486
this.#titleObj = titleObj;
2487+
this.#subjectObj = subjectObj;
24822488
this.#contentsObj = contentsObj;
24832489
this.#richText = richText;
24842490
this.#parent = parent;
@@ -2671,6 +2677,8 @@ class PopupElement {
26712677
opacity,
26722678
creationDate,
26732679
modificationDate,
2680+
titleObj: this.#titleObj,
2681+
subjectObj: this.#subjectObj,
26742682
};
26752683
}
26762684

@@ -2783,7 +2791,12 @@ class PopupElement {
27832791
const title = document.createElement("span");
27842792
title.className = "title";
27852793
header.append(title);
2786-
({ dir: title.dir, str: title.textContent } = this.#titleObj);
2794+
if (this.#subjectObj?.str) {
2795+
title.textContent = `${this.#subjectObj.str} \u2014 ${this.#titleObj.str}`;
2796+
title.dir = this.#subjectObj.dir;
2797+
} else {
2798+
({ dir: title.dir, str: title.textContent } = this.#titleObj);
2799+
}
27872800
}
27882801
popup.append(header);
27892802

web/comment_manager.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,8 @@ class CommentPopup {
876876

877877
#text = null;
878878

879+
#title = null;
880+
879881
#time = null;
880882

881883
#prevDragX = 0;
@@ -939,6 +941,9 @@ class CommentPopup {
939941
const time = (this.#time = document.createElement("time"));
940942
time.className = "commentPopupTime";
941943

944+
const title = (this.#title = document.createElement("span"));
945+
title.className = "commentPopupTitle";
946+
942947
const buttons = (this.#buttonsContainer = document.createElement("div"));
943948
buttons.className = "commentPopupButtons";
944949
const edit = document.createElement("button");
@@ -999,7 +1004,7 @@ class CommentPopup {
9991004
del.addEventListener("contextmenu", noContextMenu);
10001005
buttons.append(edit, del);
10011006

1002-
top.append(time, buttons);
1007+
top.append(title, time, buttons);
10031008

10041009
const separator = document.createElement("hr");
10051010

@@ -1137,9 +1142,19 @@ class CommentPopup {
11371142
modificationDate,
11381143
color,
11391144
opacity,
1145+
titleObj,
1146+
subjectObj,
11401147
} = editor.getData();
11411148
container.style.backgroundColor =
11421149
(color && CommentManager._makeCommentColor(color, opacity)) || "";
1150+
if (titleObj?.str) {
1151+
this.#title.textContent = subjectObj?.str
1152+
? `${subjectObj.str} \u2014 ${titleObj.str}`
1153+
: titleObj.str;
1154+
this.#title.hidden = false;
1155+
} else {
1156+
this.#title.hidden = true;
1157+
}
11431158
this.#text.replaceChildren();
11441159
const html =
11451160
richText?.str && (!contentsObj?.str || richText.str === contentsObj.str)

0 commit comments

Comments
 (0)