summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js
diff options
context:
space:
mode:
authorqsm-odoo <qsm@odoo.com>2020-09-24 11:33:35 +0000
committerqsm-odoo <qsm@odoo.com>2020-09-24 11:33:35 +0000
commitebd0c90a146145079061e79c2d4c37fa182a2975 (patch)
tree5ae193c2029790f43e7c54a0771647f4f6bb34d3 /addons/web/static/src/js
parentb94f54b5cdcbb58300a643a9c39f8c9d4842e41b (diff)
[FIX] website, *: review modal behaviors with right-panelization
*: web, web_editor Since the right-panelization made with [1], the modals were not compensating the body scrollbar when opened anymore and the backdrop was misplaced. This commit fixes the problems generically, to support modals with non-body scrolling. [1]: https://github.com/odoo/odoo/pull/57975 closes odoo/odoo#58414 Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
Diffstat (limited to 'addons/web/static/src/js')
-rw-r--r--addons/web/static/src/js/core/dom.js7
-rw-r--r--addons/web/static/src/js/libs/bootstrap.js18
-rw-r--r--addons/web/static/src/js/libs/jquery.js22
3 files changed, 47 insertions, 0 deletions
diff --git a/addons/web/static/src/js/core/dom.js b/addons/web/static/src/js/core/dom.js
index f4aba50be8a..e0b0f67ef6d 100644
--- a/addons/web/static/src/js/core/dom.js
+++ b/addons/web/static/src/js/core/dom.js
@@ -148,6 +148,13 @@ var dom = {
return $(el).closestScrollable()[0];
},
/**
+ * @param {HTMLElement} el
+ * @see $.compensateScrollbar
+ */
+ compensateScrollbar(el, ...rest) {
+ $(el).compensateScrollbar(...rest);
+ },
+ /**
* jQuery find function behavior is::
*
* $('A').find('A B') <=> $('A A B')
diff --git a/addons/web/static/src/js/libs/bootstrap.js b/addons/web/static/src/js/libs/bootstrap.js
index 07e04c64a39..3e2962cc490 100644
--- a/addons/web/static/src/js/libs/bootstrap.js
+++ b/addons/web/static/src/js/libs/bootstrap.js
@@ -96,6 +96,24 @@ $.fn.scrollspy.Constructor.prototype.refresh = function () {
}
};
+/* Bootstrap modal scrollbar compensation on non-body */
+const bsSetScrollbarFunction = $.fn.modal.Constructor.prototype._setScrollbar;
+$.fn.modal.Constructor.prototype._setScrollbar = function () {
+ const $scrollable = $().getScrollingElement();
+ if (document.body.contains($scrollable[0])) {
+ $scrollable.compensateScrollbar(true);
+ }
+ return bsSetScrollbarFunction.apply(this, arguments);
+};
+const bsResetScrollbarFunction = $.fn.modal.Constructor.prototype._resetScrollbar;
+$.fn.modal.Constructor.prototype._resetScrollbar = function () {
+ const $scrollable = $().getScrollingElement();
+ if (document.body.contains($scrollable[0])) {
+ $scrollable.compensateScrollbar(false);
+ }
+ return bsResetScrollbarFunction.apply(this, arguments);
+};
+
return {
makeExtendedSanitizeWhiteList: makeExtendedSanitizeWhiteList,
};
diff --git a/addons/web/static/src/js/libs/jquery.js b/addons/web/static/src/js/libs/jquery.js
index 6921b004019..7c3273abc91 100644
--- a/addons/web/static/src/js/libs/jquery.js
+++ b/addons/web/static/src/js/libs/jquery.js
@@ -136,6 +136,28 @@ $.fn.extend({
return $el;
},
/**
+ * Adapt the given css property by adding the size of a scrollbar if any.
+ * Limitation: only works if the given css property is not already used as
+ * inline style for another reason.
+ *
+ * @param {boolean} [add=true]
+ * @param {boolean} [isScrollElement=true]
+ * @param {string} [cssProperty='padding-right']
+ */
+ compensateScrollbar(add = true, isScrollElement = true, cssProperty = 'padding-right') {
+ for (const el of this) {
+ // Compensate scrollbar
+ el.style.removeProperty(cssProperty);
+ if (!add) {
+ return;
+ }
+ const scrollableEl = isScrollElement ? el : $(el).parent().closestScrollable()[0];
+ const style = window.getComputedStyle(el);
+ const newValue = parseInt(style[cssProperty]) + scrollableEl.offsetWidth - scrollableEl.clientWidth;
+ el.style.setProperty(cssProperty, `${newValue}px`, 'important');
+ }
+ },
+ /**
* @returns {jQuery}
*/
getScrollingElement() {