From 35b5bb7b85a008fc50fdebce7d2f25b038bc4ccd Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 11 Jan 2021 13:38:04 -0500 Subject: [PATCH] Fix changeScale not updating zms url when the page initially loads as not scale to fit --- web/skins/classic/views/js/watch.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/web/skins/classic/views/js/watch.js b/web/skins/classic/views/js/watch.js index 5ac6f49d0..d3df80b50 100644 --- a/web/skins/classic/views/js/watch.js +++ b/web/skins/classic/views/js/watch.js @@ -95,13 +95,17 @@ function changeScale() { var scale = $j('#scale').val(); var newWidth; var newHeight; + + // Always turn it off, we will re-add it below. I don't know if you can add a callback multiple + // times and what the consequences would be + $j(window).off('resize', endOfResize); //remove resize handler when Scale to Fit is not active if ( scale == '0' || scale == 'auto' ) { var newSize = scaleToFit(monitorWidth, monitorHeight, $j('#liveStream'+monitorId), $j('#replayStatus')); newWidth = newSize.width; newHeight = newSize.height; autoScale = newSize.autoScale; + $j(window).on('resize', endOfResize); //remove resize handler when Scale to Fit is not active } else { - $j(window).off('resize', endOfResize); //remove resize handler when Scale to Fit is not active newWidth = monitorWidth * scale / SCALE_BASE; newHeight = monitorHeight * scale / SCALE_BASE; } @@ -111,15 +115,16 @@ function changeScale() { var streamImg = $j('#liveStream'+monitorId); if ( streamImg ) { var oldSrc = streamImg.attr('src'); - var newSrc = oldSrc.replace(/scale=\d+/i, 'scale='+(scale== 'auto' ? autoScale : scale)); + var newSrc = oldSrc.replace(/scale=\d+/i, 'scale='+(scale == 'auto' ? autoScale : scale)); - streamImg.width( newWidth ); - streamImg.height( newHeight ); + streamImg.width(newWidth); + streamImg.height(newHeight); + streamImg.src = ''; // Some browsers need it to be cleared first streamImg.src = newSrc; } else { console.error('No element found for liveStream'+monitorId); } -} +} // end function changeScale function setAlarmState( currentAlarmState ) { alarmState = currentAlarmState; @@ -175,7 +180,8 @@ function setAlarmState( currentAlarmState ) { function getStreamCmdError(text, error) { console.log(error); // Error are normally due to failed auth. reload the page. - window.location.reload(); + + //window.location.reload(); } function getStreamCmdResponse(respObj, respText) { @@ -285,7 +291,8 @@ function getStreamCmdResponse(respObj, respText) { checkStreamForErrors('getStreamCmdResponse', respObj);//log them // Try to reload the image stream. // If it's an auth error, we should reload the whole page. - window.location.reload(); + console.log("have error"); + //window.location.reload(); if ( 0 ) { var streamImg = $j('#liveStream'+monitorId); if ( streamImg ) { @@ -854,13 +861,13 @@ function initPage() { if ( refreshApplet && appletRefreshTime ) { appletRefresh.delay(appletRefreshTime*1000); } - if ( scale == '0' || scale == 'auto' ) changeScale(); if ( window.history.length == 1 ) { $j('#closeControl').html(''); } document.querySelectorAll('select[name="scale"]').forEach(function(el) { el.onchange = window['changeScale']; }); + changeScale(); } else if ( monitorRefresh > 0 ) { setInterval(reloadWebSite, monitorRefresh*1000); }