Files
OctoPrint-CalibrationTools/octoprint_CalibrationTools/static/js/GeneralViewModel.js
T
Sergiu Toporjinschi a2751b96d6 Fix design on standard view (#3)
* Move notes above the fields
* Adding documentation
* Add documentation
* Fix design issue on standard view
2022-02-08 21:34:52 +02:00

41 lines
1.6 KiB
JavaScript

$(function () {
function CalibrationToolsGeneralViewModel(parameters) {
this.loginState = parameters[0];
this.decimal3 = function (defaultVal) {
return {
numeric: {
decimals: 3,
default: defaultVal
}
}
}
this.isSmall = ko.observable($("#tab_plugin_CalibrationTools").width() < 800);
ko.extenders.numeric = function (target, options) {
var returnObs = ko.pureComputed({
read: target,
write: function (value) {
var newVal = options.decimals ? parseFloat(value).toFixed(options.decimals) : parseInt(value);
target(isNaN(newVal) ? options.default : newVal);
}
}).extend({
notify: 'always'
});
returnObs(target());
return returnObs;
};
this.onStartupComplete = function () {
this.isSmall($("#tabs_content").width() < 800);
}
}
OCTOPRINT_VIEWMODELS.push({
// This is the constructor to call for instantiating the plugin
construct: CalibrationToolsGeneralViewModel,
name: "calibrationToolsGeneralViewModel",
// This is a list of dependencies to inject into the plugin, the order which you request
// here is the order in which the dependencies will be injected into your view model upon
// instantiation via the parameters argument
dependencies: ["loginStateViewModel"]
// Finally, this is the list of selectors for all elements we want this view model to be bound to.
});
});