From 2c18a40dcb6dfaadbf9ff208d982d2bb3682e4db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 1 Apr 2019 14:47:42 +0200 Subject: [PATCH] =?UTF-8?q?=E2=AC=86=20Update=20bootstrap=20modal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #3095 --- .../js/lib/bootstrap/bootstrap-modal.js | 94 ++++++++------- .../lib/bootstrap/bootstrap-modalmanager.js | 109 ++++++++++-------- 2 files changed, 105 insertions(+), 98 deletions(-) diff --git a/src/octoprint/static/js/lib/bootstrap/bootstrap-modal.js b/src/octoprint/static/js/lib/bootstrap/bootstrap-modal.js index 79ef5a553..1911f2a69 100644 --- a/src/octoprint/static/js/lib/bootstrap/bootstrap-modal.js +++ b/src/octoprint/static/js/lib/bootstrap/bootstrap-modal.js @@ -1,5 +1,5 @@ /* =========================================================== - * bootstrap-modal.js v2.1 + * bootstrap-modal.js v2.2.5 * =========================================================== * Copyright 2012 Jordan Schroter * @@ -33,12 +33,17 @@ constructor: Modal, init: function (element, options) { + var that = this; + this.options = options; this.$element = $(element) .delegate('[data-dismiss="modal"]', 'click.dismiss.modal', $.proxy(this.hide, this)); - this.options.remote && this.$element.find('.modal-body').load(this.options.remote); + this.options.remote && this.$element.find('.modal-body').load(this.options.remote, function () { + var e = $.Event('loaded'); + that.$element.trigger(e); + }); var manager = typeof this.options.manager === 'function' ? this.options.manager.call(this) : this.options.manager; @@ -76,7 +81,7 @@ this.$element.trigger(e); - if (!this.isShown || e.isDefaultPrevented()) return (this.isShown = false); + if (!this.isShown || e.isDefaultPrevented()) return; this.isShown = false; @@ -102,8 +107,7 @@ layout: function () { var prop = this.options.height ? 'height' : 'max-height', - value = this.options.height || this.options.maxHeight, - minHeight = this.options.minHeight; + value = this.options.height || this.options.maxHeight; if (this.options.width){ this.$element.css('width', this.options.width); @@ -123,10 +127,7 @@ this.$element.find('.modal-body') .css('overflow', '') - .css(prop, '') - .css('min-height', ''); - - var modalOverflow = $(window).height() - 10 < this.$element.height(); + .css(prop, ''); if (value){ this.$element.find('.modal-body') @@ -134,10 +135,7 @@ .css(prop, value); } - if (minHeight) { - this.$element.find('.modal-body') - .css('min-height', minHeight); - } + var modalOverflow = $(window).height() - 10 < this.$element.height(); if (modalOverflow || this.options.modalOverflow) { this.$element @@ -156,23 +154,24 @@ if (this.isShown && this.options.consumeTab) { this.$element.on('keydown.tabindex.modal', '[data-tabindex]', function (e) { if (e.keyCode && e.keyCode == 9){ - var $next = $(this), - $rollover = $(this); + var elements = [], + tabindex = Number($(this).data('tabindex')); - that.$element.find('[data-tabindex]:enabled:not([readonly])').each(function (e) { - if (!e.shiftKey){ - $next = $next.data('tabindex') < $(this).data('tabindex') ? - $next = $(this) : - $rollover = $(this); - } else { - $next = $next.data('tabindex') > $(this).data('tabindex') ? - $next = $(this) : - $rollover = $(this); - } + that.$element.find('[data-tabindex]:enabled:visible:not([readonly])').each(function (ev) { + elements.push(Number($(this).data('tabindex'))); }); + elements.sort(function(a,b){return a-b}); - $next[0] !== $(this)[0] ? - $next.focus() : $rollover.focus(); + var arrayPos = $.inArray(tabindex, elements); + if (!e.shiftKey){ + arrayPos < elements.length-1 ? + that.$element.find('[data-tabindex='+elements[arrayPos+1]+']').focus() : + that.$element.find('[data-tabindex='+elements[0]+']').focus(); + } else { + arrayPos == 0 ? + that.$element.find('[data-tabindex='+elements[elements.length-1]+']').focus() : + that.$element.find('[data-tabindex='+elements[arrayPos-1]+']').focus(); + } e.preventDefault(); } @@ -209,10 +208,6 @@ }, hideModal: function () { - this.$element - .hide() - .trigger('hidden'); - var prop = this.options.height ? 'height' : 'max-height'; var value = this.options.height || this.options.maxHeight; @@ -222,6 +217,9 @@ .css(prop, ''); } + this.$element + .hide() + .trigger('hidden'); }, removeLoading: function () { @@ -297,28 +295,26 @@ destroy: function () { var e = $.Event('destroy'); + this.$element.trigger(e); + if (e.isDefaultPrevented()) return; - this.teardown(); - }, - - teardown: function () { - if (!this.$parent.length){ - this.$element.remove(); - this.$element = null; - return; - } - - if (this.$parent !== this.$element.parent()){ - this.$element.appendTo(this.$parent); - } - - this.$element.off('.modal'); - this.$element.removeData('modal'); this.$element + .off('.modal') + .removeData('modal') .removeClass('in') .attr('aria-hidden', true); + + if (this.$parent !== this.$element.parent()) { + this.$element.appendTo(this.$parent); + } else if (!this.$parent.length) { + // modal is not part of the DOM so remove it. + this.$element.remove(); + this.$element = null; + } + + this.$element.trigger('destroyed'); } }; @@ -346,7 +342,6 @@ width: null, height: null, maxHeight: null, - minHeight: null, modalOverflow: false, consumeTab: true, focusOn: null, @@ -354,7 +349,8 @@ resize: false, attentionAnimation: 'shake', manager: 'body', - spinner: '
' + spinner: '
', + backdropTemplate: '