Skip to content

Commit 9ebcdfd

Browse files
committed
3.1.5
1 parent b281953 commit 9ebcdfd

File tree

5 files changed

+49
-14
lines changed

5 files changed

+49
-14
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Change Log
22

3+
### 3.1.5 (2016/08/04 10:43 +00:00)
4+
- [#176](https://github.com/wwayne/react-tooltip/pull/176) Support ReactTooltip.show() #47 (@wwayne)
5+
- [#174](https://github.com/wwayne/react-tooltip/pull/174) Factor transform in css into position calculation #152 (@wwayne)
6+
37
### 3.1.4 (2016/08/03 13:52 +00:00)
48
- [#173](https://github.com/wwayne/react-tooltip/pull/173) Add new attribute afterShow and afterHide (@wwayne)
59
- [#172](https://github.com/wwayne/react-tooltip/pull/172) Add support for aria- and role props #159 (@wwayne)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Check the example [React-tooltip Test](http://wwayne.com/react-tooltip)
8181

8282
**ReactTooltip.show(target)**: Show specific tooltip manually, for example:
8383

84-
```
84+
```js
8585
import {findDOMNode} from 'react-dom'
8686
import ReactTooltip from 'react-tooltip'
8787

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-tooltip",
3-
"version": "3.1.4",
3+
"version": "3.1.5",
44
"description": "react tooltip component",
55
"main": "dist/index.js",
66
"scripts": {

standalone/react-tooltip.js

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,29 @@ exports.default = function (target) {
191191
dispatchGlobalEvent(_constant2.default.GLOBAL.REBUILD);
192192
};
193193

194+
/**
195+
* Show specific tooltip
196+
* @trigger ReactTooltip.show()
197+
*/
198+
target.show = function (target) {
199+
dispatchGlobalEvent(_constant2.default.GLOBAL.SHOW, { target: target });
200+
};
201+
194202
target.prototype.globalRebuild = function () {
195203
if (this.mount) {
196204
this.unbindListener();
197205
this.bindListener();
198206
}
199207
};
208+
209+
target.prototype.globalShow = function (event) {
210+
if (this.mount) {
211+
// Create a fake event, specific show will limit the type to `solid`
212+
// only `float` type cares e.clientX e.clientY
213+
var e = { currentTarget: event.detail.target };
214+
this.showTooltip(e, true);
215+
}
216+
};
200217
};
201218

202219
var _constant = require('../constant');
@@ -205,16 +222,16 @@ var _constant2 = _interopRequireDefault(_constant);
205222

206223
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
207224

208-
var dispatchGlobalEvent = function dispatchGlobalEvent(eventName) {
225+
var dispatchGlobalEvent = function dispatchGlobalEvent(eventName, opts) {
209226
// Compatibale with IE
210227
// @see http://stackoverflow.com/questions/26596123/internet-explorer-9-10-11-event-constructor-doesnt-work
211228
var event = void 0;
212229

213-
if (typeof window.Event === 'function') {
214-
event = new window.Event(eventName);
230+
if (typeof window.CustomEvent === 'function') {
231+
event = new window.CustomEvent(eventName, { detail: opts });
215232
} else {
216233
event = document.createEvent('Event');
217-
event.initEvent(eventName, false, true);
234+
event.initEvent(eventName, false, true, opts);
218235
}
219236

220237
window.dispatchEvent(event);
@@ -239,6 +256,10 @@ exports.default = function (target) {
239256
window.removeEventListener(_constant2.default.GLOBAL.REBUILD, this.globalRebuild);
240257
window.addEventListener(_constant2.default.GLOBAL.REBUILD, this.globalRebuild, false);
241258

259+
// ReactTooltip.show
260+
window.removeEventListener(_constant2.default.GLOBAL.SHOW, this.globalShow);
261+
window.addEventListener(_constant2.default.GLOBAL.SHOW, this.globalShow, false);
262+
242263
// Resize
243264
window.removeEventListener('resize', this.onWindowResize);
244265
window.addEventListener('resize', this.onWindowResize, false);
@@ -247,6 +268,7 @@ exports.default = function (target) {
247268
target.prototype.unbindWindowEvents = function () {
248269
window.removeEventListener(_constant2.default.GLOBAL.HIDE, this.hideTooltip);
249270
window.removeEventListener(_constant2.default.GLOBAL.REBUILD, this.globalRebuild);
271+
window.removeEventListener(_constant2.default.GLOBAL.SHOW, this.globalShow);
250272
window.removeEventListener('resize', this.onWindowResize);
251273
};
252274

@@ -361,7 +383,7 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
361383
ariaProps: (0, _aria.parseAria)(props) // aria- and role attributes
362384
};
363385

364-
_this.bind(['showTooltip', 'updateTooltip', 'hideTooltip', 'globalRebuild', 'onWindowResize']);
386+
_this.bind(['showTooltip', 'updateTooltip', 'hideTooltip', 'globalRebuild', 'globalShow', 'onWindowResize']);
365387

366388
_this.mount = true;
367389
_this.delayShowLoop = null;
@@ -525,9 +547,17 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
525547

526548
}, {
527549
key: 'showTooltip',
528-
value: function showTooltip(e) {
550+
value: function showTooltip(e, isGlobalCall) {
529551
var _this5 = this;
530552

553+
if (isGlobalCall) {
554+
// Don't trigger other elements belongs to other ReactTooltip
555+
var targetArray = this.getTargetArray(this.props.id);
556+
var isMyElement = targetArray.some(function (ele) {
557+
return ele === e.currentTarget;
558+
});
559+
if (!isMyElement || this.state.show) return;
560+
}
531561
// Get the tooltip content
532562
// calculate in this phrase so that tip width height can be detected
533563
var _props3 = this.props;
@@ -549,13 +579,13 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
549579
}
550580
var placeholder = (0, _getTipContent2.default)(originTooltip, content, isMultiline);
551581

552-
// If it is focus event, switch to `solid` effect
553-
var isFocus = e instanceof window.FocusEvent;
582+
// If it is focus event or called by ReactTooltip.show, switch to `solid` effect
583+
var switchToSolid = e instanceof window.FocusEvent || isGlobalCall;
554584
this.setState({
555585
placeholder: placeholder,
556586
place: e.currentTarget.getAttribute('data-place') || this.props.place || 'top',
557587
type: e.currentTarget.getAttribute('data-type') || this.props.type || 'dark',
558-
effect: isFocus && 'solid' || e.currentTarget.getAttribute('data-effect') || this.props.effect || 'float',
588+
effect: switchToSolid && 'solid' || e.currentTarget.getAttribute('data-effect') || this.props.effect || 'float',
559589
offset: e.currentTarget.getAttribute('data-offset') || this.props.offset || {},
560590
html: e.currentTarget.getAttribute('data-html') ? e.currentTarget.getAttribute('data-html') === 'true' : this.props.html || false,
561591
delayShow: e.currentTarget.getAttribute('data-delay-show') || this.props.delayShow || 0,
@@ -1128,7 +1158,7 @@ var calculateOffset = function calculateOffset(offset) {
11281158
var getParent = function getParent(currentTarget) {
11291159
var currentParent = currentTarget;
11301160
while (currentParent) {
1131-
if (currentParent.style.transform.length > 0) break;
1161+
if (window.getComputedStyle(currentParent).getPropertyValue('transform') !== 'none') break;
11321162
currentParent = currentParent.parentElement;
11331163
}
11341164

standalone/react-tooltip.min.js

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)