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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

161 lines
4.9 KiB
JavaScript
Raw Normal View History

2021-01-08 21:32:52 +08:00
var intervalId;
2021-01-03 06:57:23 +08:00
var pauseBtn = $j('#pauseBtn');
var playBtn = $j('#playBtn');
2017-05-19 01:50:56 +08:00
function nextCycleView() {
2018-07-10 00:33:21 +08:00
window.location.replace('?view=cycle&mid='+nextMid+'&mode='+mode, cycleRefreshTimeout);
}
function cyclePause() {
2021-01-08 21:32:52 +08:00
clearInterval(intervalId);
2021-01-03 06:57:23 +08:00
pauseBtn.prop('disabled', true);
playBtn.prop('disabled', false);
}
2020-07-04 07:18:05 +08:00
function cycleStart() {
2021-01-08 21:32:52 +08:00
intervalId = setInterval(nextCycleView, cycleRefreshTimeout);
2021-01-03 06:57:23 +08:00
pauseBtn.prop('disabled', false);
playBtn.prop('disabled', true);
}
2020-07-04 07:18:05 +08:00
function cycleNext() {
monIdx ++;
2019-03-06 00:01:58 +08:00
if ( monIdx >= monitorData.length ) {
monIdx = 0;
2019-03-06 00:01:58 +08:00
}
if ( !monitorData[monIdx] ) {
2020-07-04 07:18:05 +08:00
console.log('No monitorData for ' + monIdx);
2019-03-06 00:01:58 +08:00
}
window.location.replace('?view=cycle&mid='+monitorData[monIdx].id+'&mode='+mode, cycleRefreshTimeout);
}
2020-07-04 07:18:05 +08:00
function cyclePrev() {
2021-01-09 03:16:16 +08:00
monIdx --;
if ( monIdx < 0 ) {
2019-03-11 11:56:08 +08:00
monIdx = monitorData.length - 1;
}
2021-01-09 03:16:16 +08:00
if ( !monitorData[monIdx] ) {
console.log('No monitorData for ' + monIdx);
}
window.location.replace('?view=cycle&mid='+monitorData[monIdx].id+'&mode='+mode, cycleRefreshTimeout);
}
2017-05-19 01:50:56 +08:00
function initCycle() {
2021-01-08 21:32:52 +08:00
intervalId = setInterval(nextCycleView, cycleRefreshTimeout);
2020-10-20 02:28:02 +08:00
var scale = $j('#scale').val();
if ( scale == '0' || scale == 'auto' ) changeScale();
}
function changeSize() {
2021-01-03 06:57:23 +08:00
var width = $j('#width').val();
var height = $j('#height').val();
// Scale the frame
monitor_frame = $j('#imageFeed');
if ( !monitor_frame ) {
2020-02-26 00:18:02 +08:00
console.log('Error finding frame');
return;
}
if ( width ) {
monitor_frame.css('width', width);
}
if ( height ) {
monitor_frame.css('height', height);
}
/* Stream could be an applet so can't use moo tools */
2021-01-03 06:57:23 +08:00
var streamImg = document.getElementById('liveStream'+monitorData[monIdx].id);
if ( streamImg ) {
if ( streamImg.nodeName == 'IMG' ) {
var src = streamImg.src;
streamImg.src = '';
console.log(parseInt(width));
src = src.replace(/width=[\.\d]+/i, 'width='+parseInt(width));
src = src.replace(/height=[\.\d]+/i, 'height='+parseInt(height));
src = src.replace(/rand=\d+/i, 'rand='+Math.floor((Math.random() * 1000000) ));
streamImg.src = src;
}
streamImg.style.width = width ? width : null;
streamImg.style.height = height ? height : null;
} else {
2020-07-04 07:18:05 +08:00
console.log('Did not find liveStream'+monitorData[monIdx].id);
}
2021-01-03 06:57:23 +08:00
$j('#scale').val('');
setCookie('zmCycleScale', '', 3600);
setCookie('zmCycleWidth', width, 3600);
setCookie('zmCycleHeight', height, 3600);
} // end function changeSize()
function changeScale() {
2021-01-03 06:57:23 +08:00
var scale = $j('#scale').val();
$j('#width').val('auto');
$j('#height').val('auto');
setCookie('zmCycleScale', scale, 3600);
setCookie('zmCycleWidth', 'auto', 3600);
setCookie('zmCycleHeight', 'auto', 3600);
var newWidth = ( monitorData[monIdx].width * scale ) / SCALE_BASE;
var newHeight = ( monitorData[monIdx].height * scale ) / SCALE_BASE;
// Scale the frame
monitor_frame = $j('#imageFeed');
if ( !monitor_frame ) {
2020-02-26 00:18:02 +08:00
console.log('Error finding frame');
return;
}
2020-02-26 00:18:02 +08:00
2020-07-04 07:18:05 +08:00
if ( scale != '0' && scale != '' && scale != 'auto' ) {
2020-10-20 02:28:02 +08:00
var newWidth = ( monitorData[monIdx].width * scale ) / SCALE_BASE;
var newHeight = ( monitorData[monIdx].height * scale ) / SCALE_BASE;
2020-02-26 00:18:02 +08:00
if ( newWidth ) {
monitor_frame.css('width', newWidth+'px');
}
if ( newHeight ) {
monitor_frame.css('height', newHeight+'px');
}
} else {
2020-10-20 02:28:02 +08:00
//var bottomEl = streamMode == 'stills' ? $j('#eventImageNav') : $j('#replayStatus');
var newSize = scaleToFit(monitorData[monIdx].width, monitorData[monIdx].height, monitor_frame, $j('#buttons'));
newWidth = newSize.width;
newHeight = newSize.height;
autoScale = newSize.autoScale;
monitor_frame.width(newWidth);
monitor_frame.height(newHeight);
}
2020-07-04 07:18:05 +08:00
/*Stream could be an applet so can't use moo tools*/
var streamImg = $j('#liveStream'+monitorData[monIdx].id)[0];
2020-07-04 07:18:05 +08:00
if ( !streamImg ) {
console.log("Did not find liveStream"+monitorData[monIdx].id);
return;
}
2020-07-04 07:18:05 +08:00
if ( streamImg.nodeName == 'IMG' ) {
var src = streamImg.src;
streamImg.src = '';
//src = src.replace(/rand=\d+/i,'rand='+Math.floor((Math.random() * 1000000) ));
src = src.replace(/scale=[\.\d]+/i, 'scale='+scale);
2020-10-20 02:28:02 +08:00
// zms doesn't actually use width&height
2020-07-04 07:18:05 +08:00
if ( scale != '0' && scale != '' && scale != 'auto' ) {
src = src.replace(/width=[\.\d]+/i, 'width='+newWidth);
src = src.replace(/height=[\.\d]+/i, 'height='+newHeight);
2020-02-26 00:18:02 +08:00
} else {
2020-07-04 07:18:05 +08:00
src = src.replace(/width=[\.\d]+/i, 'width='+monitorData[monIdx].width);
src = src.replace(/height=[\.\d]+/i, 'height='+monitorData[monIdx].height);
2020-02-26 00:18:02 +08:00
}
2020-07-04 07:18:05 +08:00
streamImg.src = src;
}
if ( scale != '0' && scale != '' && scale != 'auto' ) {
streamImg.style.width = newWidth+'px';
streamImg.style.height = newHeight+'px';
} else {
2020-07-04 07:18:05 +08:00
streamImg.style.width = '100%';
streamImg.style.height = 'auto';
}
} // end function changeScale()
2021-01-03 06:57:23 +08:00
$j(document).ready(initCycle);