2021-01-10 06:01:32 +08:00
|
|
|
var table = $j('#frameStatsTable');
|
2021-01-10 05:08:08 +08:00
|
|
|
var backBtn = $j('#backBtn');
|
2021-01-10 06:01:32 +08:00
|
|
|
var statsBtn = $j('#statsBtn');
|
2021-01-10 05:08:08 +08:00
|
|
|
|
2016-10-27 01:34:28 +08:00
|
|
|
function changeScale() {
|
2019-01-18 23:00:55 +08:00
|
|
|
var scale = $j('#scale').val();
|
|
|
|
var img = $j('#frameImg');
|
|
|
|
var controlsLinks = {
|
|
|
|
next: $j('#nextLink'),
|
|
|
|
prev: $j('#prevLink'),
|
|
|
|
first: $j('#firstLink'),
|
|
|
|
last: $j('#lastLink')
|
|
|
|
};
|
2017-11-22 11:49:27 +08:00
|
|
|
|
2021-10-30 06:54:23 +08:00
|
|
|
if (img) {
|
2019-01-18 23:00:55 +08:00
|
|
|
var baseWidth = $j('#base_width').val();
|
|
|
|
var baseHeight = $j('#base_height').val();
|
2021-10-30 06:54:23 +08:00
|
|
|
if (!parseInt(scale)) {
|
2019-01-18 23:00:55 +08:00
|
|
|
var newSize = scaleToFit(baseWidth, baseHeight, img, $j('#controls'));
|
2017-11-22 11:49:27 +08:00
|
|
|
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;
|
|
|
|
}
|
2017-12-07 23:31:25 +08:00
|
|
|
img.css('width', newWidth + 'px');
|
|
|
|
img.css('height', newHeight + 'px');
|
2016-10-27 01:34:28 +08:00
|
|
|
}
|
2021-01-09 00:04:46 +08:00
|
|
|
setCookie('zmWatchScale', scale, 3600);
|
2019-01-19 23:32:40 +08:00
|
|
|
$j.each(controlsLinks, function(k, anchor) { //Make frames respect scale choices
|
2021-10-30 06:54:23 +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
|
|
|
}
|
2017-11-22 11:49:27 +08:00
|
|
|
});
|
2021-01-10 06:01:32 +08:00
|
|
|
|
|
|
|
// After a resize, check if we still have room to display the event stats table
|
|
|
|
onStatsResize(newWidth);
|
|
|
|
}
|
|
|
|
|
2021-10-30 06:54:23 +08:00
|
|
|
function getFrameStatsCookie() {
|
2021-01-10 06:01:32 +08:00
|
|
|
var cookie = 'zmFrameStats';
|
|
|
|
var stats = getCookie(cookie);
|
|
|
|
|
2021-10-30 06:54:23 +08:00
|
|
|
if (!stats) {
|
2021-01-10 06:01:32 +08:00
|
|
|
stats = 'on';
|
|
|
|
setCookie(cookie, stats, 10*365);
|
|
|
|
}
|
|
|
|
return stats;
|
2016-10-27 01:34:28 +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) {
|
2021-10-30 06:54:23 +08:00
|
|
|
var stats = data.raw;
|
|
|
|
|
2020-12-14 03:20:26 +08:00
|
|
|
|
|
|
|
$j('#frameStatsTable').empty().append('<tbody>');
|
2021-10-30 06:54:23 +08:00
|
|
|
for (const stat of stats) {
|
|
|
|
$j.each(statHeaderStrings, function(key) {
|
|
|
|
var th = $j('<th>').addClass('text-right').text(statHeaderStrings[key]);
|
|
|
|
var tdString;
|
|
|
|
|
|
|
|
switch (stat ? key : 'n/a') {
|
|
|
|
case 'FrameId':
|
|
|
|
case 'EventId':
|
|
|
|
//tdString = '<a href="?view=stats&eid=' + params.eid + '&fid=' + params.fid + '">' + stat[key] + '</a>';
|
|
|
|
break;
|
|
|
|
case 'n/a':
|
|
|
|
tdString = 'n/a';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
tdString = stat[key];
|
|
|
|
}
|
|
|
|
|
|
|
|
var td = $j('<td>').html(tdString);
|
|
|
|
var row = $j('<tr>').append(th, td);
|
|
|
|
|
|
|
|
$j('#frameStatsTable tbody').append(row);
|
|
|
|
});
|
|
|
|
} // end foreach stat
|
2020-12-14 03:20:26 +08:00
|
|
|
})
|
|
|
|
.fail(logAjaxFail);
|
|
|
|
}
|
|
|
|
|
2021-01-10 06:01:32 +08:00
|
|
|
function onStatsResize(vidwidth) {
|
|
|
|
var minWidth = 300; // An arbitrary value in pixels used to hide the stats table
|
|
|
|
var width = $j(window).width() - vidwidth;
|
|
|
|
|
|
|
|
// Hide the stats table if we have run out of room to show it properly
|
2021-10-30 06:54:23 +08:00
|
|
|
if (width < minWidth) {
|
2021-01-10 06:01:32 +08:00
|
|
|
statsBtn.prop('disabled', true);
|
2021-10-30 06:54:23 +08:00
|
|
|
if (table.is(':visible')) {
|
2021-01-10 06:01:32 +08:00
|
|
|
table.toggle(false);
|
|
|
|
wasHidden = true;
|
|
|
|
}
|
|
|
|
// Show the stats table if we hid it previously and sufficient room becomes available
|
2021-10-30 06:54:23 +08:00
|
|
|
} else if (width >= minWidth) {
|
2021-01-10 06:01:32 +08:00
|
|
|
statsBtn.prop('disabled', false);
|
2021-10-30 06:54:23 +08:00
|
|
|
if (!table.is(':visible') && wasHidden) {
|
2021-01-10 06:01:32 +08:00
|
|
|
table.toggle(true);
|
|
|
|
wasHidden = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-23 03:43:53 +08:00
|
|
|
function initPage() {
|
2021-10-30 06:54:23 +08:00
|
|
|
if (scale == '0' || scale == 'auto') changeScale();
|
2020-08-24 02:17:03 +08:00
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2021-01-10 06:01:32 +08:00
|
|
|
// Manage the Frame STATISTICS Button
|
|
|
|
document.getElementById("statsBtn").addEventListener("click", function onStatsClick(evt) {
|
2020-08-24 06:53:47 +08:00
|
|
|
evt.preventDefault();
|
2021-01-10 06:01:32 +08:00
|
|
|
var cookie = 'zmFrameStats';
|
|
|
|
|
|
|
|
// Toggle the visiblity of the stats table and write an appropriate cookie
|
2021-10-30 06:54:23 +08:00
|
|
|
if (table.is(':visible')) {
|
2021-01-10 06:01:32 +08:00
|
|
|
setCookie(cookie, 'off', 10*365);
|
|
|
|
table.toggle(false);
|
|
|
|
} else {
|
|
|
|
setCookie(cookie, 'on', 10*365);
|
|
|
|
table.toggle(true);
|
|
|
|
}
|
2020-08-24 06:53:47 +08:00
|
|
|
});
|
2020-12-14 03:20:26 +08:00
|
|
|
|
2021-01-10 06:13:33 +08:00
|
|
|
// Manage the Frame STATISTICS VIEW button
|
|
|
|
document.getElementById("statsViewBtn").addEventListener("click", function onViewClick(evt) {
|
|
|
|
evt.preventDefault();
|
|
|
|
window.location.href = thisUrl+'?view=stats&eid='+eid+'&fid='+fid;
|
|
|
|
});
|
|
|
|
|
2020-12-14 04:42:39 +08:00
|
|
|
// Load the frame stats
|
|
|
|
getStat({eid: eid, fid: fid});
|
2021-01-10 06:01:32 +08:00
|
|
|
|
2021-10-30 06:54:23 +08:00
|
|
|
if (getFrameStatsCookie() != 'on') {
|
2021-01-10 06:01:32 +08:00
|
|
|
table.toggle(false);
|
|
|
|
} else {
|
|
|
|
onStatsResize($j('#base_width').val() * scale / SCALE_BASE);
|
|
|
|
}
|
2020-08-23 03:43:53 +08:00
|
|
|
}
|
|
|
|
|
2021-01-10 05:08:08 +08:00
|
|
|
// Kick everything off
|
|
|
|
$j(document).ready(initPage);
|