zoneminder/web/skins/classic/views/js/frame.js

94 lines
2.8 KiB
JavaScript
Raw Normal View History

function changeScale() {
var scale = $j('#scale').val();
var img = $j('#frameImg');
var controlsLinks = {
next: $j('#nextLink'),
prev: $j('#prevLink'),
first: $j('#firstLink'),
last: $j('#lastLink')
};
if ( img ) {
var baseWidth = $j('#base_width').val();
var baseHeight = $j('#base_height').val();
if ( ! parseInt(scale) ) {
var newSize = scaleToFit(baseWidth, baseHeight, img, $j('#controls'));
newWidth = newSize.width;
newHeight = newSize.height;
autoScale = newSize.autoScale;
} else {
$j(window).off('resize', endOfResize); //remove resize handler when Scale to Fit is not active
newWidth = baseWidth * scale / SCALE_BASE;
newHeight = baseHeight * scale / SCALE_BASE;
}
img.css('width', newWidth + 'px');
img.css('height', newHeight + 'px');
}
Cookie.write('zmWatchScale', scale, {duration: 10*365, samesite: 'strict'});
$j.each(controlsLinks, function(k, anchor) { //Make frames respect scale choices
2019-11-20 00:37:45 +08:00
if ( anchor ) {
2019-11-11 04:49:39 +08:00
anchor.prop('href', anchor.prop('href').replace(/scale=.*&/, 'scale=' + scale + '&'));
2019-11-20 00:37:45 +08:00
}
});
}
if ( !scale ) {
$j(document).ready(changeScale);
}
document.addEventListener('DOMContentLoaded', function onDCL() {
2020-09-26 02:08:55 +08:00
document.getElementById('scaleControl').addEventListener('change', changeScale);
});
2020-08-23 03:43:53 +08:00
2020-12-14 03:20:26 +08:00
function getStat(params) {
$j.getJSON(thisUrl + '?view=request&request=stats&raw=true', params)
.done(function(data) {
var stat = data.raw;
$j('#frameStatsTable').empty().append('<tbody>');
$j.each( statHeaderStrings, function( key ) {
var th = $j('<th>').addClass('text-right').text(statHeaderStrings[key]);
var tdString = ( stat ) ? stat[key] : 'n/a';
var td = $j('<td>').text(tdString);
var row = $j('<tr>').append(th, td);
$j('#frameStatsTable tbody').append(row);
});
})
.fail(logAjaxFail);
}
2020-08-23 03:43:53 +08:00
function initPage() {
2020-08-24 06:53:47 +08:00
var backBtn = $j('#backBtn');
2020-08-24 02:17:03 +08:00
if ( scale == '0' || scale == 'auto' ) changeScale();
2020-08-24 06:53:47 +08:00
// Don't enable the back button if there is no previous zm page to go back to
backBtn.prop('disabled', !document.referrer.length);
2020-08-23 03:43:53 +08:00
// Manage the BACK button
2020-08-24 06:53:47 +08:00
document.getElementById("backBtn").addEventListener("click", function onBackClick(evt) {
2020-08-23 03:43:53 +08:00
evt.preventDefault();
window.history.back();
});
2020-08-24 06:53:47 +08:00
// Manage the REFRESH Button
document.getElementById("refreshBtn").addEventListener("click", function onRefreshClick(evt) {
evt.preventDefault();
window.location.reload(true);
});
// Manage the STATS button
document.getElementById("statsBtn").addEventListener("click", function onViewClick(evt) {
evt.preventDefault();
window.location.href = thisUrl+'?view=stats&eid='+eid+'&fid='+fid;
});
2020-12-14 03:20:26 +08:00
// Load the frame stats
getStat({eid:eid, fid:fid});
2020-08-23 03:43:53 +08:00
}
$j(document).ready(function() {
initPage();
});