Skip to content

Commit

Permalink
Dirty fix for issue gilbarbara#376
Browse files Browse the repository at this point in the history
  • Loading branch information
keul committed Sep 17, 2018
1 parent aad9040 commit 2fbfb19
Show file tree
Hide file tree
Showing 5 changed files with 1,791 additions and 1,707 deletions.
62 changes: 52 additions & 10 deletions es/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import ExecutionEnvironment from 'exenv';
import is from 'is-lite';
import scroll from 'scroll';
import scrollDoc from 'scroll-doc';
import getScrollParent from 'scrollparent';
import deepmerge from 'deepmerge';
import React from 'react';
import PropTypes from 'prop-types';
Expand Down Expand Up @@ -598,6 +597,49 @@ function createStore(props) {
return new Store(props);
}

/* eslint-disable func-names */

// This is a local port of https://github.com/olahol/scrollparent.js
// It has been copied here to fix https://github.com/olahol/scrollparent.js/issues/7

var regex = /(auto|scroll)/;

var parents = function parents(node, ps) {
if (node.parentNode === null) {
return ps;
}

return parents(node.parentNode, ps.concat([node]));
};

var style = function style(node, prop) {
return getComputedStyle(node, null).getPropertyValue(prop);
};

var overflow = function overflow(node) {
return style(node, 'overflow') + style(node, 'overflow-y') + style(node, 'overflow-x');
};

var scroll$1 = function scroll$$1(node) {
return regex.test(overflow(node));
};

var scrollParent = function scrollParent(node) {
if (!(node instanceof HTMLElement || node instanceof SVGElement)) {
return null;
}

var ps = parents(node.parentNode, []);

for (var i = 0; i < ps.length; i += 1) {
if (scroll$1(ps[i])) {
return ps[i];
}
}

return document.scrollingElement || document.documentElement;
};

/**
* Find the bounding client rect
*
Expand Down Expand Up @@ -642,7 +684,7 @@ function hasCustomScrollParent(element) {
if (!element) {
return false;
}
return getScrollParent(element) !== scrollDoc();
return scrollParent(element) !== scrollDoc();
}

function hasCustomOffsetParent(element) {
Expand Down Expand Up @@ -681,7 +723,7 @@ function getScrollTo(element, offset) {
return 0;
}

var parent = getScrollParent(element);
var parent = scrollParent(element);
var top = element.offsetTop;

if (hasCustomScrollParent(element) && !hasCustomOffsetParent(element)) {
Expand Down Expand Up @@ -718,10 +760,10 @@ function getElement(element) {
*/
function getElementPosition(element, offset) {
var elementRect = getClientRect(element);
var scrollParent = getScrollParent(element);
var scrollParent$$1 = scrollParent(element);
var hasScrollParent = hasCustomScrollParent(element);

var top = elementRect.top + (!hasScrollParent && !isFixed(element) ? scrollParent.scrollTop : 0);
var top = elementRect.top + (!hasScrollParent && !isFixed(element) ? scrollParent$$1.scrollTop : 0);

return Math.floor(top - offset);
}
Expand Down Expand Up @@ -1017,7 +1059,7 @@ function getMergedStep(step, props) {

var mergedStep = deepmerge.all([getTourProps(props), DEFAULTS.step, step]);
var mergedStyles = getStyles(deepmerge(props.styles || {}, step.styles || {}));
var scrollParent = hasCustomScrollParent(getElement(step.target));
var scrollParent$$1 = hasCustomScrollParent(getElement(step.target));
var floaterProps = deepmerge.all([props.floaterProps || {}, DEFAULTS.floaterProps, mergedStep.floaterProps || {}]);

// Set react-floater props
Expand All @@ -1038,7 +1080,7 @@ function getMergedStep(step, props) {
floaterProps.wrapperOptions.placement = step.placementBeacon;
}

if (scrollParent) {
if (scrollParent$$1) {
floaterProps.options.preventOverflow.boundariesElement = 'window';
}

Expand Down Expand Up @@ -1314,7 +1356,7 @@ var Overlay = function (_React$Component) {

if (!disableScrolling) {
var element = getElement(target);
this.scrollParent = hasCustomScrollParent(element) ? getScrollParent(element) : document;
this.scrollParent = hasCustomScrollParent(element) ? scrollParent(element) : document;
}

window.addEventListener('resize', this.handleResize);
Expand Down Expand Up @@ -2399,7 +2441,7 @@ var Joyride = function (_React$Component) {

if (status === STATUS.RUNNING && shouldScroll) {
var hasCustomScroll = hasCustomScrollParent(target);
var scrollParent = getScrollParent(target);
var scrollParent$$1 = scrollParent(target);
var scrollY = Math.floor(getScrollTo(target, scrollOffset));

log({
Expand Down Expand Up @@ -2432,7 +2474,7 @@ var Joyride = function (_React$Component) {
}

if (status === STATUS.RUNNING && shouldScroll && scrollY >= 0) {
scrollTo(scrollY, scrollParent);
scrollTo(scrollY, scrollParent$$1);
}
}
}
Expand Down
Loading

0 comments on commit 2fbfb19

Please sign in to comment.