summaryrefslogtreecommitdiff
path: root/addons/website/static/src/js/content/snippets.animation.js
diff options
context:
space:
mode:
authorqsm-odoo <qsm@odoo.com>2020-09-17 10:41:10 +0000
committerqsm-odoo <qsm@odoo.com>2020-09-22 08:29:11 +0000
commit4e7be69825163c0a0ff41c882a196fc7f3158fb3 (patch)
tree517a928cddbfa019033af95f2f284cab4e82496d /addons/website/static/src/js/content/snippets.animation.js
parent416b125803d043badef8e4b022c100e33d1dba04 (diff)
[IMP] website, *: move page scrollbar to #wrapwrap
*: web, web_editor, portal, account, website_blog, website_forum This is probably not ideal to move the scrolling behavior out of the html element but this will be needed for the editor to not have a double scrollbar on the right. This is actually also useful for the scrollbar to appear under the purple odoo menu instead of its right. This commit, if to be reverted in the future, however contains many improvements to make the transition easier that should be kept: jQuery and Odoo functions to be able to scrollTo a specific element, get the top scrollable element, check if an element is scrollable, etc. Also, some magic was done: if some code tries to scroll to a specific scroll position via jQuery's scrollTop or animate functions on the html/body element, those will still work as intended (obviously, using the new utils to do that is however recommended). This commit also reviews our scroll behaviors to make them more robust and share the code. Part of https://github.com/odoo/odoo/pull/57975 task-2344227
Diffstat (limited to 'addons/website/static/src/js/content/snippets.animation.js')
-rw-r--r--addons/website/static/src/js/content/snippets.animation.js41
1 files changed, 12 insertions, 29 deletions
diff --git a/addons/website/static/src/js/content/snippets.animation.js b/addons/website/static/src/js/content/snippets.animation.js
index 81640cde197..368be2e810b 100644
--- a/addons/website/static/src/js/content/snippets.animation.js
+++ b/addons/website/static/src/js/content/snippets.animation.js
@@ -8,6 +8,7 @@ odoo.define('website.content.snippets.animation', function (require) {
var Class = require('web.Class');
var config = require('web.config');
var core = require('web.core');
+const dom = require('web.dom');
var mixins = require('web.mixins');
var publicWidget = require('web.public.widget');
var utils = require('web.utils');
@@ -123,12 +124,13 @@ var AnimationEffect = Class.extend(mixins.ParentedMixin, {
// Initialize the animation startEvents, startTarget, endEvents, endTarget and callbacks
this._updateCallback = updateCallback;
this.startEvents = startEvents || 'scroll';
- this.$startTarget = $($startTarget || window);
+ this.$startTarget = $($startTarget ? $startTarget : this.startEvents === 'scroll' ? $().getScrollingElement()[0] : window);
if (options.getStateCallback) {
this._getStateCallback = options.getStateCallback;
- } else if (this.startEvents === 'scroll' && this.$startTarget[0] === window) {
+ } else if (this.startEvents === 'scroll' && this.$startTarget[0] === $().getScrollingElement()[0]) {
+ const $scrollable = this.$startTarget;
this._getStateCallback = function () {
- return window.pageYOffset;
+ return $scrollable.scrollTop();
};
} else if (this.startEvents === 'resize' && this.$startTarget[0] === window) {
this._getStateCallback = function () {
@@ -898,38 +900,19 @@ registry.anchorSlide = publicWidget.Widget.extend({
* @private
* @param {jQuery} $el the element to scroll to.
* @param {string} [scrollValue='true'] scroll value
+ * @returns {Promise}
*/
- _scrollTo: function ($el, scrollValue = 'true', forcedDelay = undefined) {
- const _computeScrollTo = () => {
- const headerHeight = this._computeHeaderHeight();
- const offset = $el.css('position') !== 'fixed' ? $el.offset().top : $el.position().top;
- return offset - headerHeight;
- };
- const originalScrollTo = _computeScrollTo();
- return new Promise(resolve => {
- $('html, body').animate({
- scrollTop: originalScrollTo,
- }, {
- duration: forcedDelay || (scrollValue === 'true' ? 500 : 0),
- progress: (a, b, remainingMs) => {
- const scrollTo = _computeScrollTo();
- if (Math.abs(scrollTo - originalScrollTo) >= 1.0) {
- $('html, body').stop();
- this._scrollTo($el, scrollValue, remainingMs).then(() => resolve());
- }
- },
- complete: () => resolve(),
- });
+ async _scrollTo($el, scrollValue = 'true') {
+ return dom.scrollTo($el[0], {
+ duration: scrollValue === 'true' ? 500 : 0,
+ extraOffset: this._computeExtraOffset(),
});
},
/**
* @private
*/
- _computeHeaderHeight: function () {
- let headerHeight = 0;
- const $navbarFixed = $('.o_top_fixed_element');
- _.each($navbarFixed, el => headerHeight += $(el).outerHeight());
- return headerHeight;
+ _computeExtraOffset() {
+ return 0;
},
//--------------------------------------------------------------------------