diff --git a/kitsune/sumo/static/sumo/js/kbox.js b/kitsune/sumo/static/sumo/js/kbox.js index 4f1a51b89e4..64f53b5eb5d 100644 --- a/kitsune/sumo/static/sumo/js/kbox.js +++ b/kitsune/sumo/static/sumo/js/kbox.js @@ -66,6 +66,8 @@ * Override the template to use for creating the modal. * title: * The kbox's title. + * windowMargin: + * Minimum margin between the kbox and the edge of the window. */ var TEMPLATE = ( @@ -105,7 +107,9 @@ KBox.prototype = { preOpen: false, preClose: false, template: TEMPLATE, - title: self.$el.attr('title') || self.$el.attr('data-title') + title: self.$el.attr('title') || self.$el.attr('data-title'), + windowMargin: self.$el.data('viewport-margin') === undefined ? + 20 : parseInt(self.$el.data('viewport-margin'), 10), }, options); self.options = options; self.$clickTarget = options.clickTarget && $(options.clickTarget); @@ -187,7 +191,9 @@ KBox.prototype = { self.render(); } self.$kbox.addClass('kbox-open'); + self.handleOverflow(); self.setPosition(); + self.addResizeHandler(); if (self.options.modal) { self.createOverlay(); } @@ -215,8 +221,27 @@ KBox.prototype = { }, 0); } }, + addResizeHandler: function () { + var self = this; + // If position is none, return early instead of adding a listener that will never do anything + if (self.options.position === 'none') { + return; + } + self.resizeHandler = function () { + self.setPosition(); + }; + $(window).on('resize', self.resizeHandler); + }, + removeResizeHandler: function () { + var self = this; + if (self.resizeHandler) { + $(window).off('resize', self.resizeHandler); + delete self.resizeHandler; + } + }, setPosition: function (position) { var self = this; + const minMargin = self.options.windowMargin; if (!position) { position = self.options.position; } @@ -226,18 +251,72 @@ KBox.prototype = { if (position === 'center') { let windowWidth = $(window).width(); let windowHeight = $(window).height(); + + // Reset height and width limitations to get the actual initial kbox size + self.resetOverflow(); + let modalWidth = self.$kbox.outerWidth(); let modalHeight = self.$kbox.outerHeight(); + let left = Math.max((windowWidth - modalWidth) / 2, minMargin); + let top = Math.max((windowHeight - modalHeight) / 2, minMargin); + self.$kbox.css({ - 'left': (windowWidth - modalWidth) / 2, - 'top': (windowHeight - modalHeight) / 2, + 'left': left, + 'top': top, 'right': 'inherit', 'bottom': 'inherit', 'position': 'fixed' }); + + self.handleOverflow(); + } + }, + handleOverflow: function () { + var self = this; + const minMargin = self.options.windowMargin; + + let windowWidth = $(window).width(); + let windowHeight = $(window).height(); + let modalWidth = self.$kbox.outerWidth(); + let modalHeight = self.$kbox.outerHeight(); + let rect = self.$kbox[0].getBoundingClientRect(); + + if (rect.right > windowWidth - minMargin) { + self.$kbox.css({ + 'max-width': windowWidth - minMargin - rect.left + }); + } + else if (rect.right < windowWidth - minMargin) { + self.$kbox.css({ + 'max-width': '' + }); + } + + // Due to max-width, kbox height may have changed. + rect = self.$kbox[0].getBoundingClientRect(); + + if (rect.bottom > windowHeight) { + self.$kbox.css({ + 'max-height': windowHeight - minMargin - rect.top, + 'overflow-y': 'auto' + }); + } + else if (rect.bottom < windowHeight - minMargin) { + self.$kbox.css({ + 'max-height': '', + 'overflow-y': '' + }); } }, + resetOverflow: function () { + var self = this; + self.$kbox.css({ + 'max-width': '', + 'max-height': '', + 'overflow-y': '' + }); + }, close: function () { var self = this; if (self.options.preClose && !self.options.preClose.call(self)) { @@ -250,6 +329,7 @@ KBox.prototype = { } self.isOpen = false; self.$kbox.removeClass('kbox-open'); + self.removeResizeHandler(); if (self.options.modal) { self.destroyOverlay(); } @@ -266,6 +346,7 @@ KBox.prototype = { destroy: function () { // return DOM to how it was originally, if possible. var self = this; + self.removeResizeHandler(); if (self.$container && self.$ph) { self.$ph.replaceWith(self.$el.detach()); } diff --git a/kitsune/sumo/static/sumo/js/wiki.js b/kitsune/sumo/static/sumo/js/wiki.js index fd60a5920cb..70dd26e10b2 100644 --- a/kitsune/sumo/static/sumo/js/wiki.js +++ b/kitsune/sumo/static/sumo/js/wiki.js @@ -443,7 +443,8 @@ import collapsibleAccordionInit from "sumo/js/protocol-details-init"; // when checked. var $checkbox = $('#id_needs_change'), $comment = $('#id_needs_change_comment'), - $commentlabel = $('label[for="id_needs_change_comment"]'); + $commentlabel = $('label[for="id_needs_change_comment"]'), + $kbox = $checkbox.closest('.kbox').data('kbox'); if ($checkbox.length > 0) { updateComment(); @@ -460,6 +461,11 @@ import collapsibleAccordionInit from "sumo/js/protocol-details-init"; $comment.hide(); $comment.find('textarea').prop('required', false); } + if ($kbox && $kbox.isOpen) { + $comment.add($commentlabel).promise().done(function () { + $kbox.handleOverflow(); + }); + } } } diff --git a/kitsune/sumo/static/sumo/scss/base/forms/_fields.scss b/kitsune/sumo/static/sumo/scss/base/forms/_fields.scss index 73e29b9f15c..b4ad3757365 100644 --- a/kitsune/sumo/static/sumo/scss/base/forms/_fields.scss +++ b/kitsune/sumo/static/sumo/scss/base/forms/_fields.scss @@ -128,10 +128,6 @@ label { &.full-width { max-width: 100%; - - select { - max-width: 100%; - } } &.has-error, diff --git a/kitsune/sumo/static/sumo/scss/components/_wiki.scss b/kitsune/sumo/static/sumo/scss/components/_wiki.scss index 189f8ff6df0..5c28b117540 100644 --- a/kitsune/sumo/static/sumo/scss/components/_wiki.scss +++ b/kitsune/sumo/static/sumo/scss/components/_wiki.scss @@ -637,6 +637,15 @@ article { form { padding: 0 0 20px; } + + label[for="id_needs_change_comment"] { + font-weight: normal; + } + + /* Remove margin after the needs-change field before the comment (when it's displayed). */ + div:has(label[for="id_needs_change"]):has(+ div label[for="id_needs_change_comment"]) { + margin-bottom: 0; + } } #preview { @@ -904,11 +913,7 @@ body.review { } #approve-modal { - p { - margin: 0 0 10px; - } - - label { + .field label { font-weight: normal; } @@ -950,11 +955,6 @@ body.review { div.needs-change { margin: 10px 0; } - - textarea { - height: 100px; - width: 350px; - } } .html-rtl { @@ -979,9 +979,13 @@ body.review { } } +#self-approve-warning { + margin-top: 0; +} + .needs-change { .comment { - margin: 0 0 0 17px; + @include p.bidi(((margin, 0 0 0 calc(20px + #{p.$spacing-md}), 0 calc(20px + #{p.$spacing-md}) 0 0),)); label { display: block; diff --git a/kitsune/wiki/jinja2/wiki/edit.html b/kitsune/wiki/jinja2/wiki/edit.html index f42823d3023..3698493db3e 100644 --- a/kitsune/wiki/jinja2/wiki/edit.html +++ b/kitsune/wiki/jinja2/wiki/edit.html @@ -45,7 +45,7 @@