jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/343549 )
Change subject: Element: Add special case for document root in getClosestScrollableContainer ...................................................................... Element: Add special case for document root in getClosestScrollableContainer Also documentation improvements, and correction for unattached elements. Bug: T160852 Change-Id: Ifceac7e11ba0db2635f55d554f266fb13dc71807 --- M src/Element.js 1 file changed, 17 insertions(+), 9 deletions(-) Approvals: jenkins-bot: Verified VolkerE: Looks good to me, approved diff --git a/src/Element.js b/src/Element.js index 3b9085d..2c10495 100644 --- a/src/Element.js +++ b/src/Element.js @@ -584,17 +584,18 @@ }() ); /** - * Get scrollable object parent + * Get the root scrollable element of given element's document. * - * documentElement can't be used to get or set the scrollTop - * property on Blink. Changing and testing its value lets us - * use 'body' or 'documentElement' based on what is working. + * On Blink-based browsers (Chrome etc.), `document.documentElement` can't be used to get or set + * the scrollTop property; instead we have to use `document.body`. Changing and testing the value + * lets us use 'body' or 'documentElement' based on what is working. * * https://code.google.com/p/chromium/issues/detail?id=303131 * * @static - * @param {HTMLElement} el Element to find scrollable parent for - * @return {HTMLElement} Scrollable parent + * @param {HTMLElement} el Element to find root scrollable parent for + * @return {HTMLElement} Scrollable parent, `document.body` or `document.documentElement` + * depending on browser */ OO.ui.Element.static.getRootScrollableElement = function ( el ) { var scrollTop, body; @@ -618,8 +619,8 @@ /** * Get closest scrollable container. * - * Traverses up until either a scrollable element or the root is reached, in which case the window - * will be returned. + * Traverses up until either a scrollable element or the root is reached, in which case the root + * scrollable element will be returned (see #getRootScrollableElement). * * @static * @param {HTMLElement} el Element to find scrollable container for @@ -635,6 +636,12 @@ if ( dimension === 'x' || dimension === 'y' ) { props = [ 'overflow-' + dimension ]; + } + + // Special case for the document root (which doesn't really have any scrollable container, since + // it is the ultimate scrollable container, but this is probably saner than null or exception) + if ( $( el ).is( 'html, body' ) ) { + return this.getRootScrollableElement( el ); } while ( $parent.length ) { @@ -655,7 +662,8 @@ } $parent = $parent.parent(); } - return this.getDocument( el ).body; + // The element is unattached... return something mostly sane + return this.getRootScrollableElement( el ); }; /** -- To view, visit https://gerrit.wikimedia.org/r/343549 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ifceac7e11ba0db2635f55d554f266fb13dc71807 Gerrit-PatchSet: 3 Gerrit-Project: oojs/ui Gerrit-Branch: master Gerrit-Owner: Bartosz Dziewoński <[email protected]> Gerrit-Reviewer: Bartosz Dziewoński <[email protected]> Gerrit-Reviewer: Catrope <[email protected]> Gerrit-Reviewer: Krinkle <[email protected]> Gerrit-Reviewer: VolkerE <[email protected]> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
