@@ -306,6 +306,7 @@ export default class Guest extends Delegator {
306
306
} ) ;
307
307
308
308
this . subscribe ( 'annotationsLoaded' , annotations => {
309
+ this . loadDoodles ( annotations . filter ( this . isDoodleAnnotation ) ) ;
309
310
annotations . map ( annotation => this . anchor ( annotation ) ) ;
310
311
} ) ;
311
312
}
@@ -364,6 +365,10 @@ export default class Guest extends Delegator {
364
365
crossframe . on ( 'saveCurrentDoodle' , ( ) => {
365
366
this . saveCurrentDoodle ( ) ;
366
367
} ) ;
368
+
369
+ crossframe . on ( 'clearDoodleCanvas' , ( ) => {
370
+ this . clearDoodleCanvas ( ) ;
371
+ } ) ;
367
372
}
368
373
369
374
destroy ( ) {
@@ -773,9 +778,64 @@ export default class Guest extends Delegator {
773
778
if ( this . doodleCanvasController ) {
774
779
this . createAnnotation ( {
775
780
$doodle : true ,
776
- doodleLines : this . doodleCanvasController . lines ,
781
+ doodleLines : this . doodleCanvasController . newLines ,
777
782
} ) ;
778
- this . doodleCanvasController . lines = [ ] ;
783
+ // removed clearing lines from here because of bug when you try to save unsuccessfully (b/c not logged in) clearing your doodle
784
+ }
785
+ }
786
+
787
+ /**
788
+ * Clear the doodle canvas
789
+ */
790
+ clearDoodleCanvas ( ) {
791
+ if ( this . doodleCanvasController ) {
792
+ this . doodleCanvasController . saveLines ( ) ;
793
+ }
794
+ }
795
+
796
+ /**
797
+ *
798
+ * @param {* } annotation
799
+ * @returns true if the annotation is a doodleAnnotation
800
+ */
801
+
802
+ isDoodleAnnotation ( annotation ) {
803
+ // If any of the targets have a DoodleSelector, this is a doodle annotation. Otherwise, it is not.
804
+ if ( annotation . target ) {
805
+ for ( let targ of annotation . target ) {
806
+ // not all targets have selectors at this point
807
+ if ( targ . selector ) {
808
+ for ( let selector of targ . selector ) {
809
+ if ( selector . type === 'DoodleSelector' ) {
810
+ return true ;
811
+ }
812
+ }
813
+ }
814
+ }
815
+ }
816
+ return false ;
817
+ }
818
+
819
+ loadDoodles ( doodleAnnotations ) {
820
+ // First, make sure there are doodleAnnotations and a Controller
821
+ if ( ! doodleAnnotations . length || ! this . doodleCanvasController ) {
822
+ return ;
823
+ }
824
+
825
+ // Then, load the lines into our doodleCanvasController.
826
+ let newLines = [ ] ;
827
+ for ( let doodle of doodleAnnotations ) {
828
+ for ( let targ of doodle . target ) {
829
+ for ( let sel of targ . selector ) {
830
+ if ( sel . type === 'DoodleSelector' ) {
831
+ newLines = [ ...newLines , sel . line ] ;
832
+ }
833
+ }
834
+ }
779
835
}
836
+ this . doodleCanvasController . savedLines = [
837
+ ...this . doodleCanvasController . savedLines ,
838
+ ...newLines ,
839
+ ] ;
780
840
}
781
841
}
0 commit comments