@@ -41,6 +41,7 @@ var icons = {
41
41
var panZoomEnabled = true ; //Add it to settings in the future
42
42
var expiredTap ; //Time between touch screen clicks. Used to analyze double clicks
43
43
var shifted = ctrled = alted = false ;
44
+ var mainContent = document . getElementById ( 'content' ) ;
44
45
45
46
function checkSize ( ) {
46
47
if ( 0 ) {
@@ -1527,6 +1528,13 @@ function initPageGeneral() {
1527
1528
alted = e . altKey ;
1528
1529
} ) ;
1529
1530
1531
+ if ( [ 'montage' , 'watch' , 'devices' , 'reports' , 'monitorpreset' , 'monitorprobe' , 'onvifprobe' , 'timeline' ] . includes ( currentView ) ) {
1532
+ mainContent = document . getElementById ( 'page' ) ;
1533
+ } else if ( currentView == 'options' ) {
1534
+ mainContent = document . getElementById ( 'optionsContainer' ) ;
1535
+ }
1536
+ var mainContentJ = $j ( mainContent ) ;
1537
+
1530
1538
/* Assigning global handlers!
1531
1539
** IMPORTANT! It will not be possible to remove assigned handlers using the removeEventListener method, since the functions are anonymous
1532
1540
*/
@@ -1556,30 +1564,35 @@ function initPageGeneral() {
1556
1564
} ) ;
1557
1565
} , 200 ) ;
1558
1566
1559
- window . addEventListener ( 'beforeunload' , function ( event ) {
1567
+ // https://web.dev/articles/bfcache Firefox has a peculiar behavior of caching the previous page.
1568
+ window . addEventListener ( 'pageshow' , ( event ) => {
1569
+ if ( event . persisted ) {
1570
+ // Do any checks and updates to the page
1571
+ if ( mainContentJ [ 0 ] . clientHeight < 1 ) {
1572
+ window . location . reload ( true ) ;
1573
+ }
1574
+ }
1575
+ } ) ;
1576
+
1577
+ window . addEventListener ( 'beforeunload' , function addListenerGlobalBeforeunload ( event ) {
1560
1578
//event.preventDefault();
1561
- let target ;
1562
1579
/*
1563
1580
if (!useOldMenuView) {
1564
1581
closeMbExtruder(updateCookie = true);
1565
1582
}
1566
1583
*/
1567
- if ( [ 'montage' , 'watch' , 'devices' , 'reports' , 'monitorpreset' , 'monitorprobe' , 'onvifprobe' ] . includes ( currentView ) ) {
1568
- target = $j ( '#page' ) ;
1569
- } else if ( currentView == 'options' ) {
1570
- target = $j ( '#optionsContainer' ) ;
1571
- } else {
1572
- target = $j ( '#content' ) ;
1573
- }
1574
- if ( target . css ( 'display' ) == 'flex' ) {
1575
- // If flex-grow is set to a value > 0 then "height" will be ignored!
1576
- target . css ( { flex : "0 1 auto" } ) ;
1577
- }
1584
+ if ( mainContentJ ) {
1585
+ if ( mainContentJ . css ( 'display' ) == 'flex' ) {
1586
+ // If flex-grow is set to a value > 0 then "height" will be ignored!
1587
+ mainContentJ . css ( { flex : "0 1 auto" } ) ;
1588
+ }
1578
1589
1579
- target . animate ( { height : 0 } , 300 , function ( ) {
1580
- $j ( 'body' ) . find ( '#btn-collapse' ) . css ( { display : "none" } ) ;
1581
- target . css ( { display : "none" } ) ;
1582
- } ) ;
1590
+ mainContentJ . animate ( { height : 0 } , 300 , function rollupBeforeunloadPage ( ) {
1591
+ const btnCollapse = $j ( 'body' ) . find ( '#btn-collapse' ) ;
1592
+ if ( btnCollapse ) btnCollapse . css ( { display : "none" } ) ;
1593
+ mainContentJ . css ( { display : "none" } ) ;
1594
+ } ) ;
1595
+ }
1583
1596
//event.returnValue = '';
1584
1597
} ) ;
1585
1598
}
0 commit comments