wix-style-react
Version:
wix-style-react
69 lines (55 loc) • 2.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var TooltipContainerStrategy = exports.TooltipContainerStrategy = function () {
function TooltipContainerStrategy(appendTo, appendToParent, appendByPredicate) {
_classCallCheck(this, TooltipContainerStrategy);
this._predicates = [function (element) {
return element.getAttribute('data-class') === 'page-scrollable-content';
}, function (element) {
return element === document.body;
}];
this._ancestor = null;
this._appendTo = appendTo;
this._appendToParent = appendToParent;
if (appendByPredicate) {
this._predicates.push(appendByPredicate);
}
}
_createClass(TooltipContainerStrategy, [{
key: '_findAncestor',
value: function _findAncestor(element) {
while (element) {
if (this._predicates.some(function (pred) {
return pred(element);
})) {
// eslint-disable-line
break;
}
element = element.parentElement;
}
return element || document.body;
}
}, {
key: 'getContainer',
value: function getContainer(element) {
if (!document) {
return null;
}
if (this._appendTo) {
return this._appendTo;
}
if (this._appendToParent) {
return element.parentElement;
}
if (!this._ancestor) {
this._ancestor = this._findAncestor(element);
}
return this._ancestor;
}
}]);
return TooltipContainerStrategy;
}();