@@ -1275,13 +1275,11 @@ function preLoadCss(cssUrl) {
1275
1275
}
1276
1276
1277
1277
window . addEventListener ( "resize" , ( ) => {
1278
- // @ts -expect-error
1279
1278
if ( window . CURRENT_TOOLTIP_ELEMENT ) {
1280
1279
// As a workaround to the behavior of `contains: layout` used in doc togglers,
1281
1280
// tooltip popovers are positioned using javascript.
1282
1281
//
1283
1282
// This means when the window is resized, we need to redo the layout.
1284
- // @ts -expect-error
1285
1283
const base = window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE ;
1286
1284
const force_visible = base . TOOLTIP_FORCE_VISIBLE ;
1287
1285
hideTooltip ( false ) ;
@@ -1337,14 +1335,15 @@ function preLoadCss(cssUrl) {
1337
1335
}
1338
1336
// Make this function idempotent. If the tooltip is already shown, avoid doing extra work
1339
1337
// and leave it alone.
1340
- // @ts -expect-error
1341
1338
if ( window . CURRENT_TOOLTIP_ELEMENT && window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE === e ) {
1342
- // @ts -expect-error
1343
1339
clearTooltipHoverTimeout ( window . CURRENT_TOOLTIP_ELEMENT ) ;
1344
1340
return ;
1345
1341
}
1346
1342
window . hideAllModals ( false ) ;
1347
- const wrapper = document . createElement ( "div" ) ;
1343
+ // use Object.assign to make sure the object has the correct type
1344
+ // with all of the correct fields before it is assigned to a variable,
1345
+ // as typescript has no way to change the type of a variable once it is initialized.
1346
+ const wrapper = Object . assign ( document . createElement ( "div" ) , { TOOLTIP_BASE : e } ) ;
1348
1347
if ( notable_ty ) {
1349
1348
wrapper . innerHTML = "<div class=\"content\">" +
1350
1349
// @ts -expect-error
@@ -1390,11 +1389,7 @@ function preLoadCss(cssUrl) {
1390
1389
) ;
1391
1390
}
1392
1391
wrapper . style . visibility = "" ;
1393
- // @ts -expect-error
1394
1392
window . CURRENT_TOOLTIP_ELEMENT = wrapper ;
1395
- // @ts -expect-error
1396
- window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE = e ;
1397
- // @ts -expect-error
1398
1393
clearTooltipHoverTimeout ( window . CURRENT_TOOLTIP_ELEMENT ) ;
1399
1394
wrapper . onpointerenter = ev => {
1400
1395
// If this is a synthetic touch event, ignore it. A click event will be along shortly.
@@ -1429,19 +1424,15 @@ function preLoadCss(cssUrl) {
1429
1424
*/
1430
1425
function setTooltipHoverTimeout ( element , show ) {
1431
1426
clearTooltipHoverTimeout ( element ) ;
1432
- // @ts -expect-error
1433
1427
if ( ! show && ! window . CURRENT_TOOLTIP_ELEMENT ) {
1434
1428
// To "hide" an already hidden element, just cancel its timeout.
1435
1429
return ;
1436
1430
}
1437
- // @ts -expect-error
1438
1431
if ( show && window . CURRENT_TOOLTIP_ELEMENT ) {
1439
1432
// To "show" an already visible element, just cancel its timeout.
1440
1433
return ;
1441
1434
}
1442
- // @ts -expect-error
1443
1435
if ( window . CURRENT_TOOLTIP_ELEMENT &&
1444
- // @ts -expect-error
1445
1436
window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE !== element ) {
1446
1437
// Don't do anything if another tooltip is already visible.
1447
1438
return ;
@@ -1464,7 +1455,6 @@ function preLoadCss(cssUrl) {
1464
1455
*/
1465
1456
function clearTooltipHoverTimeout ( element ) {
1466
1457
if ( element . TOOLTIP_HOVER_TIMEOUT !== undefined ) {
1467
- // @ts -expect-error
1468
1458
removeClass ( window . CURRENT_TOOLTIP_ELEMENT , "fade-out" ) ;
1469
1459
clearTimeout ( element . TOOLTIP_HOVER_TIMEOUT ) ;
1470
1460
delete element . TOOLTIP_HOVER_TIMEOUT ;
@@ -1473,15 +1463,10 @@ function preLoadCss(cssUrl) {
1473
1463
1474
1464
// @ts -expect-error
1475
1465
function tooltipBlurHandler ( event ) {
1476
- // @ts -expect-error
1477
1466
if ( window . CURRENT_TOOLTIP_ELEMENT &&
1478
- // @ts -expect-error
1479
1467
! window . CURRENT_TOOLTIP_ELEMENT . contains ( document . activeElement ) &&
1480
- // @ts -expect-error
1481
1468
! window . CURRENT_TOOLTIP_ELEMENT . contains ( event . relatedTarget ) &&
1482
- // @ts -expect-error
1483
1469
! window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE . contains ( document . activeElement ) &&
1484
- // @ts -expect-error
1485
1470
! window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE . contains ( event . relatedTarget )
1486
1471
) {
1487
1472
// Work around a difference in the focus behaviour between Firefox, Chrome, and Safari.
@@ -1503,30 +1488,22 @@ function preLoadCss(cssUrl) {
1503
1488
* If set to `false`, leave keyboard focus alone.
1504
1489
*/
1505
1490
function hideTooltip ( focus ) {
1506
- // @ts -expect-error
1507
1491
if ( window . CURRENT_TOOLTIP_ELEMENT ) {
1508
- // @ts -expect-error
1509
1492
if ( window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE . TOOLTIP_FORCE_VISIBLE ) {
1510
1493
if ( focus ) {
1511
- // @ts -expect-error
1512
1494
window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE . focus ( ) ;
1513
1495
}
1514
- // @ts -expect-error
1515
1496
window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE . TOOLTIP_FORCE_VISIBLE = false ;
1516
1497
}
1517
- // @ts -expect-error
1518
1498
document . body . removeChild ( window . CURRENT_TOOLTIP_ELEMENT ) ;
1519
- // @ts -expect-error
1520
1499
clearTooltipHoverTimeout ( window . CURRENT_TOOLTIP_ELEMENT ) ;
1521
- // @ts -expect-error
1522
- window . CURRENT_TOOLTIP_ELEMENT = null ;
1500
+ window . CURRENT_TOOLTIP_ELEMENT = undefined ;
1523
1501
}
1524
1502
}
1525
1503
1526
1504
onEachLazy ( document . getElementsByClassName ( "tooltip" ) , e => {
1527
1505
e . onclick = ( ) => {
1528
1506
e . TOOLTIP_FORCE_VISIBLE = e . TOOLTIP_FORCE_VISIBLE ? false : true ;
1529
- // @ts -expect-error
1530
1507
if ( window . CURRENT_TOOLTIP_ELEMENT && ! e . TOOLTIP_FORCE_VISIBLE ) {
1531
1508
hideTooltip ( true ) ;
1532
1509
} else {
@@ -1562,9 +1539,7 @@ function preLoadCss(cssUrl) {
1562
1539
if ( ev . pointerType !== "mouse" ) {
1563
1540
return ;
1564
1541
}
1565
- // @ts -expect-error
1566
1542
if ( ! e . TOOLTIP_FORCE_VISIBLE && window . CURRENT_TOOLTIP_ELEMENT &&
1567
- // @ts -expect-error
1568
1543
! window . CURRENT_TOOLTIP_ELEMENT . contains ( ev . relatedTarget ) ) {
1569
1544
// Tooltip pointer leave gesture:
1570
1545
//
@@ -1597,7 +1572,6 @@ function preLoadCss(cssUrl) {
1597
1572
// * https://www.nngroup.com/articles/tooltip-guidelines/
1598
1573
// * https://bjk5.com/post/44698559168/breaking-down-amazons-mega-dropdown
1599
1574
setTooltipHoverTimeout ( e , false ) ;
1600
- // @ts -expect-error
1601
1575
addClass ( window . CURRENT_TOOLTIP_ELEMENT , "fade-out" ) ;
1602
1576
}
1603
1577
} ;
0 commit comments