UNPKG

react-tooltip

Version:
78 lines (65 loc) 2.12 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = function (target) { /** * Hide all tooltip * @trigger ReactTooltip.hide() */ target.hide = function (target) { dispatchGlobalEvent(_constant2.default.GLOBAL.HIDE, { target: target }); }; /** * Rebuild all tooltip * @trigger ReactTooltip.rebuild() */ target.rebuild = function () { dispatchGlobalEvent(_constant2.default.GLOBAL.REBUILD); }; /** * Show specific tooltip * @trigger ReactTooltip.show() */ target.show = function (target) { dispatchGlobalEvent(_constant2.default.GLOBAL.SHOW, { target: target }); }; target.prototype.globalRebuild = function () { if (this.mount) { this.unbindListener(); this.bindListener(); } }; target.prototype.globalShow = function (event) { if (this.mount) { // Create a fake event, specific show will limit the type to `solid` // only `float` type cares e.clientX e.clientY var e = { currentTarget: event.detail.target }; this.showTooltip(e, true); } }; target.prototype.globalHide = function (event) { if (this.mount) { var hasTarget = event && event.detail && event.detail.target && true || false; this.hideTooltip({ currentTarget: hasTarget && event.detail.target }, hasTarget); } }; }; var _constant = require('../constant'); var _constant2 = _interopRequireDefault(_constant); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var dispatchGlobalEvent = function dispatchGlobalEvent(eventName, opts) { // Compatible with IE // @see http://stackoverflow.com/questions/26596123/internet-explorer-9-10-11-event-constructor-doesnt-work var event = void 0; if (typeof window.CustomEvent === 'function') { event = new window.CustomEvent(eventName, { detail: opts }); } else { event = document.createEvent('Event'); event.initEvent(eventName, false, true); event.detail = opts; } window.dispatchEvent(event); }; /** * Static methods for react-tooltip */