UNPKG

react-tooltip

Version:
52 lines (43 loc) 1.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = function (target) { target.prototype.bindRemovalTracker = function () { var _this = this; var MutationObserver = getMutationObserverClass(); if (MutationObserver == null) return; var observer = new MutationObserver(function (mutations) { for (var m1 = 0; m1 < mutations.length; m1++) { var mutation = mutations[m1]; for (var m2 = 0; m2 < mutation.removedNodes.length; m2++) { var element = mutation.removedNodes[m2]; if (element === _this.state.currentTarget) { _this.hideTooltip(); return; } } } }); observer.observe(window.document, { childList: true, subtree: true }); this.removalTracker = observer; }; target.prototype.unbindRemovalTracker = function () { if (this.removalTracker) { this.removalTracker.disconnect(); this.removalTracker = null; } }; }; /** * Tracking target removing from DOM. * It's necessary to hide tooltip when it's target disappears. * Otherwise, the tooltip would be shown forever until another target * is triggered. * * If MutationObserver is not available, this feature just doesn't work. */ // https://hacks.mozilla.org/2012/05/dom-mutationobserver-reacting-to-dom-changes-without-killing-browser-performance/ var getMutationObserverClass = function getMutationObserverClass() { return window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver; };