File tree Expand file tree Collapse file tree 4 files changed +10
-7
lines changed Expand file tree Collapse file tree 4 files changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ type LiveTranslatorPluginOptions = {
10
10
persist ?: boolean ;
11
11
root ?: HTMLElement ;
12
12
refreshRate ?: number ;
13
+ checkVisibility ?: boolean ;
13
14
} ;
14
15
export declare function encodeMessages ( messagesObject : any ) : any ;
15
16
export declare const LiveTranslatorPlugin : {
Original file line number Diff line number Diff line change @@ -259,18 +259,18 @@ class LiveTranslatorManager {
259
259
if ( badges . length ) {
260
260
let position = { top : 0 , left : 0 } ;
261
261
try {
262
- let isVisible ;
262
+ let isVisible = ! this . _options . checkVisibility ;
263
263
if ( node instanceof Text ) {
264
264
const clientRect = getBoundingClientRect ( node ) ;
265
265
position . top = clientRect . top + window . scrollY ;
266
266
position . left = clientRect . left + window . screenX ;
267
- isVisible = node . parentElement . contains ( document . elementFromPoint ( clientRect . left + clientRect . width / 2 , clientRect . top + clientRect . height / 2 ) ) ;
267
+ isVisible = isVisible || node . parentElement . contains ( document . elementFromPoint ( clientRect . left + clientRect . width / 2 , clientRect . top + clientRect . height / 2 ) ) ;
268
268
}
269
269
else {
270
270
const clientRect = node . getClientRects ( ) [ 0 ] ;
271
271
position . top = clientRect . top + clientRect . height - 10 + window . scrollY ;
272
272
position . left = clientRect . left + window . screenX ;
273
- isVisible = node . contains ( document . elementFromPoint ( clientRect . left + clientRect . width / 2 , clientRect . top + clientRect . height / 2 ) ) ;
273
+ isVisible = isVisible || node . contains ( document . elementFromPoint ( clientRect . left + clientRect . width / 2 , clientRect . top + clientRect . height / 2 ) ) ;
274
274
}
275
275
if ( ! isVisible ) {
276
276
continue ;
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ app.use(LiveTranslatorPlugin, {
14
14
persist : true ,
15
15
root : document . getElementById ( 'app' ) ,
16
16
refreshRate : 50 ,
17
+ checkVisibility : true ,
17
18
} )
18
19
19
20
app . mount ( '#app' )
Original file line number Diff line number Diff line change @@ -84,7 +84,8 @@ type LiveTranslatorPluginOptions = {
84
84
translationLink : ( meta : TranslationMeta ) => string
85
85
persist ?: boolean
86
86
root ?: HTMLElement
87
- refreshRate ?: number
87
+ refreshRate ?: number ,
88
+ checkVisibility ?: boolean ,
88
89
}
89
90
90
91
function deepForIn ( object : Object , fn : ( value : string , key : string ) => void ) {
@@ -305,19 +306,19 @@ class LiveTranslatorManager {
305
306
if ( badges . length ) {
306
307
let position = { top : 0 , left : 0 }
307
308
try {
308
- let isVisible
309
+ let isVisible = ! this . _options . checkVisibility
309
310
if ( node instanceof Text ) {
310
311
const clientRect = getBoundingClientRect ( node )
311
312
position . top = clientRect . top + window . scrollY
312
313
position . left = clientRect . left + window . screenX
313
- isVisible = node . parentElement . contains (
314
+ isVisible = isVisible || node . parentElement . contains (
314
315
document . elementFromPoint ( clientRect . left + clientRect . width / 2 , clientRect . top + clientRect . height / 2 )
315
316
)
316
317
} else {
317
318
const clientRect = node . getClientRects ( ) [ 0 ]
318
319
position . top = clientRect . top + clientRect . height - 10 + window . scrollY
319
320
position . left = clientRect . left + window . screenX
320
- isVisible = node . contains (
321
+ isVisible = isVisible || node . contains (
321
322
document . elementFromPoint ( clientRect . left + clientRect . width / 2 , clientRect . top + clientRect . height / 2 )
322
323
)
323
324
}
You can’t perform that action at this time.
0 commit comments