♻ Backport some more pieces from devel

This commit is contained in:
Gina Häußge committed 2019-03-12 13:40:58 +01:00
1 parent f0ee7f343e
commit 21c9c51858
2 files changed
+26 -25

No files matched your search

+17 -22
View File
@@ -122,13 +122,13 @@ $(function() {
exports.onBrowserVisibilityChange = function(callback) {
browserVisibilityCallbacks.push(callback);
};
exports.hashFromTabChange = false;
exports.updateTab = function () {
exports.updateTab = function() {
if (exports.hashFromTabChange) {
exports.hashFromTabChange = false;
return;
}
var tabs = $('#tabs');
var hashtag = window.location.hash;
@@ -150,6 +150,7 @@ $(function() {
}
}
};
return exports;
})();
@@ -536,9 +537,6 @@ $(function() {
});
};
// Use bootstrap tabdrop for tabs and pills
$('.nav-pills, .nav-tabs').tabdrop();
// Allow components to react to tab change
var onTabChange = function(current, previous) {
log.debug("Selected OctoPrint tab changed: previous = " + previous + ", current = " + current);
@@ -553,24 +551,22 @@ $(function() {
var tabs = $('#tabs').find('a[data-toggle="tab"]');
tabs.on('show', function (e) {
var current = e.target.hash;
var previous = e.relatedTarget.hash;
var previous = e.relatedTarget ? e.relatedTarget.hash : undefined;
onTabChange(current, previous);
});
tabs.on('shown', function (e) {
var current = e.target.hash;
var previous = e.relatedTarget.hash;
var previous = e.relatedTarget ? e.relatedTarget.hash : undefined;
onAfterTabChange(current, previous);
// make sure we also update the hash but stick to the current scroll position
var scrollmem = $('body').scrollTop() || $('html').scrollTop();
OctoPrint.coreui.hashFromTabChange = true;
window.location.hash = current;
$('html,body').scrollTop(scrollmem);
});
onTabChange(OCTOPRINT_INITIAL_TAB);
onAfterTabChange(OCTOPRINT_INITIAL_TAB, undefined);
// Fix input element click problems on dropdowns
$(".dropdown input, .dropdown label").click(function(e) {
e.stopPropagation();
@@ -689,14 +685,6 @@ $(function() {
callViewModels(allViewModels, "onAllBound", [allViewModels]);
log.info("... binding done");
// startup complete
callViewModels(allViewModels, "onStartupComplete");
setOnViewModels(allViewModels, "_startupComplete", true);
// this will also allow selecting any tabs that will be hidden later due to overflowing since our
// overflow plugin tabdrop hasn't run yet
OctoPrint.coreui.updateTab();
// make sure we can track the browser tab visibility
OctoPrint.coreui.onBrowserVisibilityChange(function(status) {
log.debug("Browser tab is now " + (status ? "visible" : "hidden"));
@@ -707,11 +695,18 @@ $(function() {
OctoPrint.coreui.updateTab();
});
if (window.location.hash !== "") {
OctoPrint.coreui.updateTab();
}
log.info("Application startup complete");
// startup complete
callViewModels(allViewModels, "onStartupComplete");
setOnViewModels(allViewModels, "_startupComplete", true);
// this will also allow selecting any tabs that will be hidden later due to overflowing since our
// overflow plugin tabdrop hasn't run yet
OctoPrint.coreui.updateTab();
// Use bootstrap tabdrop for tabs and pills
$('.nav-pills, .nav-tabs').tabdrop();
};
var fetchSettings = function() {
@@ -760,8 +760,9 @@ $(function() {
}
};
self.onAfterTabChange = function(current, previous) {
if (current !== "#temp") {
self.initOrUpdate = function() {
if (OctoPrint.coreui.selectedTab !== "#temp" || !$("#temp").is(":visible")) {
// do not try to initialize the graph when it's not visible or its sizing will be off
return;
}
@@ -772,6 +773,10 @@ $(function() {
}
};
self.onAfterTabChange = function() {
self.initOrUpdate();
};
self.onStartup = function() {
var graph = $("#temperature-graph");
if (graph.length && !OctoPrint.coreui.browser.mobile) {
@@ -789,6 +794,7 @@ $(function() {
};
self.onStartupComplete = function() {
self.initOrUpdate();
self._printerProfileUpdated();
};
@@ -797,6 +803,6 @@ $(function() {
OCTOPRINT_VIEWMODELS.push({
construct: TemperatureViewModel,
dependencies: ["loginStateViewModel", "settingsViewModel"],
elements: ["#temp", "#change_offset_dialog", "#temp_link"]
elements: ["#temp", "#temp_link", "#change_offset_dialog"]
});
});