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

155 lines
4.7 KiB
JavaScript
Raw Normal View History

var periodical_id;
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() {
$clear(periodical_id);
$('pauseBtn').disabled = true;
$('playBtn').disabled = false;
}
2020-07-04 07:18:05 +08:00
function cycleStart() {
periodical_id = nextCycleView.periodical(cycleRefreshTimeout);
$('pauseBtn').disabled = false;
$('playBtn').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() {
2020-07-04 07:18:05 +08:00
if ( monIdx ) {
monIdx -= 1;
2019-03-11 11:56:08 +08:00
} else {
monIdx = monitorData.length - 1;
}
window.location.replace('?view=cycle&mid='+monitorData[monIdx].id+'&mode='+mode, cycleRefreshTimeout);
}
2017-05-19 01:50:56 +08:00
function initCycle() {
periodical_id = nextCycleView.periodical(cycleRefreshTimeout);
2020-10-20 02:28:02 +08:00
var scale = $j('#scale').val();
if ( scale == '0' || scale == 'auto' ) changeScale();
}
function changeSize() {
var width = $('width').get('value');
var height = $('height').get('value');
// 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 */
var streamImg = $('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);
}
$('scale').set('value', '');
2019-03-06 00:01:58 +08:00
Cookie.write('zmCycleScale', '', {duration: 10*365});
Cookie.write('zmCycleWidth', width, {duration: 10*365});
Cookie.write('zmCycleHeight', height, {duration: 10*365});
} // end function changeSize()
function changeScale() {
var scale = $('scale').get('value');
$('width').set('value', 'auto');
$('height').set('value', 'auto');
2019-03-11 11:56:08 +08:00
Cookie.write('zmCycleScale', scale, {duration: 10*365});
Cookie.write('zmCycleWidth', 'auto', {duration: 10*365});
Cookie.write('zmCycleHeight', 'auto', {duration: 10*365});
// 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()
window.addEventListener('DOMContentLoaded', initCycle);