Skip to content

Commit f2df4bf

Browse files
authored
Merge pull request #5 from DynamicEnvironmentSystems/ina/color-coding-hotpots
Support for hotspot color coding.
2 parents d275842 + ef68c8d commit f2df4bf

File tree

5 files changed

+71
-3
lines changed

5 files changed

+71
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ coverage/
33
sandbox/shared
44
web/shared
55
web-dist
6+
npm-debug.log

shared/initColorPicker.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Color picker component
22
const COLORS = [
3+
{hex: 'darkgoldenrod', name: 'Delete Color'},
34
{hex: '#000000', name: 'Black'},
45
{hex: '#EF4437', name: 'Red'},
56
{hex: '#E71F63', name: 'Pink'},

shared/toolbar.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,6 @@ body {
128128
margin-left: -2px;
129129
margin-right: -2px;
130130
}
131-
.text-color, .pen-color {
131+
.text-color, .pen-color, .hotspot-color {
132132
display: inline-block;
133133
}

web/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@
9393
<button class="circle" type="button" title="fillCircle" data-tooltype="fillcircle"></button>
9494
<button class="circle" type="button" title="emptyCircle" data-tooltype="emptycircle">⦿</button>
9595
<button class="arrow" type="arrow" title="Arrow" data-tooltype="arrow"></button>
96+
<div class="hotspot-color"></div>
97+
9698
<button class="highlight" type="button" title="Highlight" data-tooltype="highlight">&nbsp;</button>
9799
<button class="strikeout" type="button" title="Strikeout" data-tooltype="strikeout">&nbsp;</button>
98100

web/index.js

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,70 @@ function render() {
4747
}
4848
render();
4949

50+
// Hotspot color stuff
51+
(function () {
52+
let hotspotColor = localStorage.getItem(`${RENDER_OPTIONS.documentId}/hotspot/color`) || 'darkgoldenrod';
53+
let currentTarget = undefined;
54+
55+
function handleAnnotationClick(target) {
56+
let type = target.getAttribute('data-pdf-annotate-type');
57+
if (['fillcircle', 'arrow'].indexOf(type) === -1) {
58+
return; // nothing to do
59+
}
60+
currentTarget = target;
61+
hotspotColor = currentTarget.getAttribute('stroke');
62+
63+
UI.setArrow(10, hotspotColor);
64+
UI.setCircle(10, hotspotColor);
65+
66+
let a = document.querySelector('.hotspot-color .color');
67+
if (a) {
68+
a.setAttribute('data-color', hotspotColor);
69+
a.style.background = hotspotColor;
70+
}
71+
}
72+
73+
function handleAnnotationBlur(target) {
74+
if (currentTarget === target) {
75+
currentTarget = undefined;
76+
}
77+
}
78+
79+
initColorPicker(document.querySelector('.hotspot-color'), hotspotColor, function (value) {
80+
if (value === hotspotColor) {
81+
return; // nothing to do
82+
}
83+
localStorage.setItem(`${RENDER_OPTIONS.documentId}/hotspot/color`, value);
84+
hotspotColor = value;
85+
86+
UI.setArrow(10, hotspotColor);
87+
UI.setCircle(10, hotspotColor);
88+
89+
if (!currentTarget) {
90+
return; // nothing to do
91+
}
92+
93+
let type = currentTarget.getAttribute('data-pdf-annotate-type');
94+
let annotationId = currentTarget.getAttribute('data-pdf-annotate-id');
95+
if (['fillcircle', 'arrow'].indexOf(type) === -1) {
96+
return; // nothing to do
97+
}
98+
99+
// update target
100+
currentTarget.setAttribute('stroke', hotspotColor);
101+
currentTarget.setAttribute('fill', hotspotColor);
102+
103+
// update annotation
104+
PDFJSAnnotate.getStoreAdapter().getAnnotation(documentId, annotationId).then((annotation) => {
105+
annotation.color = hotspotColor;
106+
PDFJSAnnotate.getStoreAdapter().editAnnotation(documentId, annotationId, annotation);
107+
});
108+
});
109+
110+
UI.addEventListener('annotation:click', handleAnnotationClick);
111+
UI.addEventListener('annotation:blur', handleAnnotationBlur);
112+
})();
113+
50114
// Text stuff
51115
(function () {
52116
let textSize;
@@ -368,7 +432,7 @@ render();
368432
UI.addEventListener('annotation:click', handleAnnotationClick);
369433
UI.addEventListener('annotation:blur', handleAnnotationBlur);
370434

371-
UI.setArrow(10, '#0000FF');
372-
UI.setCircle(10, '#0000FF')
435+
UI.setArrow(10, 'darkgoldenrod');
436+
UI.setCircle(10, 'darkgoldenrod')
373437

374438
})(window, document);

0 commit comments

Comments
 (0)