@@ -47,6 +47,70 @@ function render() {
4747}
4848render ( ) ;
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