@@ -112,7 +112,6 @@ export abstract class AbstractRegion<T> implements Region<T> {
112
112
constructor ( public document : A11yDocument ) {
113
113
this . CLASS = this . constructor as typeof AbstractRegion ;
114
114
this . AddStyles ( ) ;
115
- this . AddElement ( ) ;
116
115
}
117
116
118
117
@@ -136,9 +135,9 @@ export abstract class AbstractRegion<T> implements Region<T> {
136
135
* @override
137
136
*/
138
137
public AddElement ( ) {
138
+ if ( this . div ) return ;
139
139
let element = this . document . adaptor . node ( 'div' ) ;
140
140
element . classList . add ( this . CLASS . className ) ;
141
- element . style . backgroundColor = 'white' ;
142
141
this . div = element ;
143
142
this . inner = this . document . adaptor . node ( 'div' ) ;
144
143
this . div . appendChild ( this . inner ) ;
@@ -153,6 +152,7 @@ export abstract class AbstractRegion<T> implements Region<T> {
153
152
* @override
154
153
*/
155
154
public Show ( node : HTMLElement , highlighter : Sre . highlighter ) {
155
+ this . AddElement ( ) ;
156
156
this . position ( node ) ;
157
157
this . highlight ( highlighter ) ;
158
158
this . div . classList . add ( this . CLASS . className + '_Show' ) ;
@@ -177,7 +177,10 @@ export abstract class AbstractRegion<T> implements Region<T> {
177
177
* @override
178
178
*/
179
179
public Hide ( ) {
180
- this . div . classList . remove ( this . CLASS . className + '_Show' ) ;
180
+ if ( ! this . div ) return ;
181
+ this . div . parentNode . removeChild ( this . div ) ;
182
+ this . div = null ;
183
+ this . inner = null ;
181
184
}
182
185
183
186
@@ -198,6 +201,7 @@ export abstract class AbstractRegion<T> implements Region<T> {
198
201
* @param {HTMLElement } node The reference node.
199
202
*/
200
203
protected stackRegions ( node : HTMLElement ) {
204
+ this . AddElement ( ) ;
201
205
// TODO: This could be made more efficient by caching regions of a class.
202
206
const rect = node . getBoundingClientRect ( ) ;
203
207
let baseBottom = 0 ;
@@ -270,6 +274,7 @@ export class StringRegion extends AbstractRegion<string> {
270
274
* @override
271
275
*/
272
276
public Clear ( ) : void {
277
+ if ( ! this . div ) return ;
273
278
this . Update ( '' ) ;
274
279
this . inner . style . top = '' ;
275
280
this . inner . style . backgroundColor = '' ;
@@ -280,8 +285,13 @@ export class StringRegion extends AbstractRegion<string> {
280
285
* @override
281
286
*/
282
287
public Update ( speech : string ) {
283
- this . inner . textContent = '' ;
284
- this . inner . textContent = speech ;
288
+ if ( speech ) {
289
+ this . AddElement ( ) ;
290
+ }
291
+ if ( this . inner ) {
292
+ this . inner . textContent = '' ;
293
+ this . inner . textContent = speech ;
294
+ }
285
295
}
286
296
287
297
/**
@@ -296,6 +306,7 @@ export class StringRegion extends AbstractRegion<string> {
296
306
* @override
297
307
*/
298
308
protected highlight ( highlighter : Sre . highlighter ) {
309
+ if ( ! this . div ) return ;
299
310
const color = highlighter . colorString ( ) ;
300
311
this . inner . style . backgroundColor = color . background ;
301
312
this . inner . style . color = color . foreground ;
@@ -317,13 +328,11 @@ export class ToolTip extends StringRegion {
317
328
protected static style : CssStyles =
318
329
new CssStyles ( {
319
330
[ '.' + ToolTip . className ] : {
320
- display : 'none' ,
321
- } ,
322
- [ '.' + ToolTip . className + '_Show' ] : {
323
331
width : 'auto' , height : 'auto' , opacity : 1 , 'text-align' : 'center' ,
324
332
'border-radius' : '6px' , padding : 0 ,
325
333
'border-bottom' : '1px dotted black' ,
326
334
position : 'absolute' , display : 'inline-block' ,
335
+ 'background-color' : 'white' ,
327
336
'z-index' : 202
328
337
}
329
338
} ) ;
@@ -344,14 +353,12 @@ export class LiveRegion extends StringRegion {
344
353
protected static style : CssStyles =
345
354
new CssStyles ( {
346
355
[ '.' + LiveRegion . className ] : {
347
- display : 'none'
348
- } ,
349
- [ '.' + LiveRegion . className + '_Show' ] : {
350
356
position : 'absolute' , top : 0 ,
351
357
display : 'block' , width : 'auto' , height : 'auto' ,
352
358
padding : 0 , opacity : 1 , 'z-index' : '202' ,
353
359
left : 0 , right : 0 , 'margin' : '0 auto' ,
354
- 'background-color' : 'rgba(0, 0, 255, 0.2)' , 'box-shadow' : '0px 5px 20px #888' ,
360
+ 'background-color' : 'white' ,
361
+ 'box-shadow' : '0px 5px 20px #888' ,
355
362
border : '2px solid #CCCCCC'
356
363
}
357
364
} ) ;
@@ -531,27 +538,17 @@ export class HoverRegion extends AbstractRegion<HTMLElement> {
531
538
protected static style : CssStyles =
532
539
new CssStyles ( {
533
540
[ '.' + HoverRegion . className ] : {
534
- display : 'none'
535
- } ,
536
- [ '.' + HoverRegion . className + '_Show' ] : {
537
541
display : 'block' , position : 'absolute' ,
538
542
width : 'max-content' , height : 'auto' ,
539
543
padding : 0 , opacity : 1 , 'z-index' : '202' , 'margin' : '0 auto' ,
540
- 'background-color' : 'rgba(0, 0, 255, 0.2)' ,
544
+ 'background-color' : 'white' , 'line-height' : 0 ,
541
545
'box-shadow' : '0px 10px 20px #888' , border : '2px solid #CCCCCC'
546
+ } ,
547
+ [ '.' + HoverRegion . className + ' > div' ] : {
548
+ overflow : 'hidden'
542
549
}
543
550
} ) ;
544
551
545
-
546
- /**
547
- * @constructor
548
- * @param {A11yDocument } document The document the live region is added to.
549
- */
550
- constructor ( public document : A11yDocument ) {
551
- super ( document ) ;
552
- this . inner . style . lineHeight = '0' ;
553
- }
554
-
555
552
/**
556
553
* Sets the position of the region with respect to align parameter. There are
557
554
* three options: top, bottom and center. Center is the default.
@@ -568,7 +565,7 @@ export class HoverRegion extends AbstractRegion<HTMLElement> {
568
565
let top ;
569
566
switch ( this . document . options . a11y . align ) {
570
567
case 'top' :
571
- top = nodeRect . top - divRect . height - 10 ;
568
+ top = nodeRect . top - divRect . height - 10 ;
572
569
break ;
573
570
case 'bottom' :
574
571
top = nodeRect . bottom + 10 ;
@@ -588,6 +585,7 @@ export class HoverRegion extends AbstractRegion<HTMLElement> {
588
585
* @override
589
586
*/
590
587
protected highlight ( highlighter : Sre . highlighter ) {
588
+ if ( ! this . div ) return ;
591
589
// TODO Do this with styles to avoid the interaction of SVG/CHTML.
592
590
if ( this . inner . firstChild &&
593
591
! ( this . inner . firstChild as HTMLElement ) . hasAttribute ( 'sre-highlight' ) ) {
@@ -602,6 +600,7 @@ export class HoverRegion extends AbstractRegion<HTMLElement> {
602
600
* @override
603
601
*/
604
602
public Show ( node : HTMLElement , highlighter : Sre . highlighter ) {
603
+ this . AddElement ( ) ;
605
604
this . div . style . fontSize = this . document . options . a11y . magnify ;
606
605
this . Update ( node ) ;
607
606
super . Show ( node , highlighter ) ;
@@ -611,6 +610,7 @@ export class HoverRegion extends AbstractRegion<HTMLElement> {
611
610
* @override
612
611
*/
613
612
public Clear ( ) {
613
+ if ( ! this . div ) return ;
614
614
this . inner . textContent = '' ;
615
615
this . inner . style . top = '' ;
616
616
this . inner . style . backgroundColor = '' ;
@@ -620,9 +620,11 @@ export class HoverRegion extends AbstractRegion<HTMLElement> {
620
620
* @override
621
621
*/
622
622
public Update ( node : HTMLElement ) {
623
+ if ( ! this . div ) return ;
623
624
this . Clear ( ) ;
624
625
let mjx = this . cloneNode ( node ) ;
625
626
this . inner . appendChild ( mjx ) ;
627
+ this . position ( node ) ;
626
628
}
627
629
628
630
/**
0 commit comments