jellyfin-server/MediaBrowser.WebDashboard/Html/scripts/LogPage.js

86 lines
2.5 KiB
JavaScript
Raw Normal View History

2013-02-21 01:33:05 +00:00
var LogPage = {
onPageShow: function () {
LogPage.startLine = 0;
$('#logContents', this).html('');
$(document).on("websocketmessage", LogPage.onWebSocketMessage).on("websocketopen", LogPage.onWebSocketConnectionChange).on("websocketerror", LogPage.onWebSocketConnectionChange).on("websocketclose", LogPage.onWebSocketConnectionChange);
LogPage.startInterval();
var autoScroll = localStorage.getItem("autoScrollLogPage");
if (autoScroll == "true") {
LogPage.updateAutoScroll(true);
}
else if (autoScroll == "false") {
LogPage.updateAutoScroll(false);
}
},
onPageHide: function () {
$(document).off("websocketmessage", LogPage.onWebSocketMessage).off("websocketopen", LogPage.onWebSocketConnectionChange).off("websocketerror", LogPage.onWebSocketConnectionChange).off("websocketclose", LogPage.onWebSocketConnectionChange);
LogPage.stopInterval();
},
startInterval: function () {
if (Dashboard.isWebSocketOpen()) {
Dashboard.sendWebSocketMessage("LogFileStart", "0,2000");
}
},
stopInterval: function () {
if (Dashboard.isWebSocketOpen()) {
Dashboard.sendWebSocketMessage("LogFileStop");
}
},
onWebSocketConnectionChange: function () {
LogPage.stopInterval();
LogPage.startInterval();
},
onWebSocketMessage: function (e, msg) {
if (msg.MessageType == "LogFile") {
LogPage.appendLines(msg.Data);
}
},
appendLines: function (lines) {
if (!lines.length) {
return;
}
LogPage.startLine += lines.length;
lines = lines.join('\n') + '\n';
var elem = $('#logContents', $.mobile.activePage).append(lines)[0];
elem.style.height = (elem.scrollHeight) + 'px';
if ($('#chkAutoScroll', $.mobile.activePage).checked()) {
$('html, body').animate({ scrollTop: $(document).height() }, 'slow');
}
},
updateAutoScroll: function (value) {
var page = $.mobile.activePage;
$('#chkAutoScrollBottom', page).checked(value).checkboxradio('refresh');
$('#chkAutoScroll', page).checked(value).checkboxradio('refresh');
localStorage.setItem("autoScrollLogPage", value.toString());
}
};
$(document).on('pageshow', "#logPage", LogPage.onPageShow).on('pagehide', "#logPage", LogPage.onPageHide);