diff --git a/src/octoprint/server/__init__.py b/src/octoprint/server/__init__.py index d6db68d8a..f385b9ac1 100644 --- a/src/octoprint/server/__init__.py +++ b/src/octoprint/server/__init__.py @@ -1359,6 +1359,7 @@ class Server(object): "js/lib/pnotify/pnotify.nonblock.min.js", "js/lib/pnotify/pnotify.reference.min.js", "js/lib/pnotify/pnotify.tooltip.min.js", + "js/lib/pnotify/pnotify.maxheight.js", "js/lib/moment-with-locales.min.js", "js/lib/pusher.color.min.js", "js/lib/detectmobilebrowser.js", diff --git a/src/octoprint/static/js/app/main.js b/src/octoprint/static/js/app/main.js index cdd1886f8..55e613d5c 100644 --- a/src/octoprint/static/js/app/main.js +++ b/src/octoprint/static/js/app/main.js @@ -194,6 +194,11 @@ $(function() { PNotify.prototype.options.delay = 5000; PNotify.prototype.options.animate_speed = "fast"; + PNotify.prototype.options.maxheight.maxheight = function() { + return $(window).height() - 170; // top margin + header + footer + some safety margin + }; + + // single button notify PNotify.singleButtonNotify = function(options) { if (!options.confirm || !options.confirm.buttons || !options.confirm.buttons.length) { return new PNotify(options); diff --git a/src/octoprint/static/js/lib/pnotify/pnotify.maxheight.js b/src/octoprint/static/js/lib/pnotify/pnotify.maxheight.js new file mode 100644 index 000000000..8770b176b --- /dev/null +++ b/src/octoprint/static/js/lib/pnotify/pnotify.maxheight.js @@ -0,0 +1,54 @@ +// Maxheight +(function (factory) { + if (typeof exports === 'object' && typeof module !== 'undefined') { + // CommonJS + module.exports = factory(require('jquery'), require('pnotify')); + } else if (typeof define === 'function' && define.amd) { + // AMD. Register as a module. + define('pnotify.confirm', ['jquery', 'pnotify'], factory); + } else { + // Browser globals + factory(jQuery, PNotify); + } +}(function($, PNotify){ + PNotify.prototype.options.maxheight = { + // Maximum height of text area to enforce + maxheight: false + }; + + var _position = PNotify.prototype.position; + PNotify.prototype.position = function(){ + if (typeof this.options.maxheight.maxheight === "function") { + setMaxHeight(this, this.options.maxheight); + } + _position.apply(this, arguments); + }; + + var setMaxHeight = function(notice, options) { + if (!options.maxheight) return; + + var option = options.maxheight; + if (typeof option === "function") { + option = option(); + } + + var height; + if (typeof option === "number") { + // assuming pixels + height = "" + option + "px"; + } else if (typeof option === "string") { + // assuming css string + height = option + } else { + // unknown, ignore + return; + } + notice.text_container.css("max-height", height); + notice.text_container.css("overflow", "auto"); + }; + + PNotify.prototype.modules.maxheight = { + init: setMaxHeight, + update: setMaxHeight + }; +}));