-
Notifications
You must be signed in to change notification settings - Fork 879
Improve styling for the review modal and when editing articles/metadata & Make kbox responsive to window resizing and overflow #7613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's not something I'm very familiar with, let me look into
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've made a change to only call |
||
| if (self.options.modal) { | ||
| self.createOverlay(); | ||
| } | ||
|
|
@@ -215,8 +221,37 @@ 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 () { | ||
| if (self.resizeFrame) { | ||
| return; | ||
| } | ||
| self.resizeFrame = window.requestAnimationFrame(function () { | ||
| self.resizeFrame = null; | ||
| self.setPosition(); | ||
| }); | ||
| }; | ||
| $(window).on('resize', self.resizeHandler); | ||
| }, | ||
| removeResizeHandler: function () { | ||
| var self = this; | ||
| if (self.resizeHandler) { | ||
| $(window).off('resize', self.resizeHandler); | ||
| if (self.resizeFrame) { | ||
| window.cancelAnimationFrame(self.resizeFrame); | ||
| } | ||
| delete self.resizeFrame; | ||
| delete self.resizeHandler; | ||
| } | ||
| }, | ||
| setPosition: function (position) { | ||
| var self = this; | ||
| const minMargin = self.options.windowMargin; | ||
| if (!position) { | ||
| position = self.options.position; | ||
| } | ||
|
|
@@ -226,18 +261,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(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably the 2 vars above are not used
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. they are used: |
||
|
|
||
| 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 +339,7 @@ KBox.prototype = { | |
| } | ||
| self.isOpen = false; | ||
| self.$kbox.removeClass('kbox-open'); | ||
| self.removeResizeHandler(); | ||
| if (self.options.modal) { | ||
| self.destroyOverlay(); | ||
| } | ||
|
|
@@ -266,6 +356,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()); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -128,10 +128,6 @@ label { | |
|
|
||
| &.full-width { | ||
| max-width: 100%; | ||
|
|
||
| select { | ||
| max-width: 100%; | ||
| } | ||
| } | ||
|
|
||
| &.has-error, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Won't this make any
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will, but only inside #approve-modal, and that's actually what we want. Currently, the non-bold font weight applies to #id-approve-comment with textarea. The change will exclude this case from the rule. Given that the modal is quite limited, I don't see any other effect of this change, so it should be fine. |
||
| 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; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
won't this be applied to all kboxes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, but that's what I'm trying to achieve