Skip to content

Commit 553840d

Browse files
committed
Extract get position method
Add static method ReactTooltip.show s
1 parent 250d029 commit 553840d

File tree

9 files changed

+290
-357
lines changed

9 files changed

+290
-357
lines changed

circle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
machine:
22
node:
3-
version: 0.12.0
3+
version: 4.2.1
44

55
dependencies:
66
override:

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-tooltip",
3-
"version": "2.0.3",
3+
"version": "3.0.0",
44
"description": "react tooltip component",
55
"main": "index.js",
66
"scripts": {
@@ -64,7 +64,7 @@
6464
"http-server": "^0.8.0",
6565
"jsdom": "^9.2.1",
6666
"mocha": "^2.5.3",
67-
"node-sass": "^3.3.2",
67+
"node-sass": "^3.7.0",
6868
"react-addons-test-utils": "^15.1.0",
6969
"sinon": "^1.17.4",
7070
"snazzy": "^2.0.1",

src/constant.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export default {
22

33
GLOBAL: {
44
HIDE: '__react_tooltip_hide_event',
5-
REBUILD: '__react_tooltip_rebuild_event'
5+
REBUILD: '__react_tooltip_rebuild_event',
6+
SHOW: '__react_tooltip_show_event'
67
}
78
}

src/decorators/staticMethods.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,24 @@ export default function (target) {
3434
target.rebuild = () => {
3535
dispatchGlobalEvent(CONSTANT.GLOBAL.REBUILD)
3636
}
37+
38+
target.prototype.globalRebuild = function () {
39+
if (this.mount) {
40+
this.unbindListener()
41+
this.bindListener()
42+
}
43+
}
44+
45+
/**
46+
* show a specific tooltip
47+
* @trigger ReactTooltip.show()
48+
*/
49+
target.show = (id) => {
50+
dispatchGlobalEvent(CONSTANT.GLOBAL.SHOW)
51+
}
52+
53+
target.prototype.globalShow = function () {
54+
// id comes from I don't know
55+
this.getTargetArray(id)
56+
}
3757
}

src/decorators/windowListener.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export default function (target) {
1313
window.removeEventListener(CONSTANT.GLOBAL.REBUILD, this.globalRebuild)
1414
window.addEventListener(CONSTANT.GLOBAL.REBUILD, ::this.globalRebuild, false)
1515

16+
// ReactTooltip.show
17+
window.removeEventListener(CONSTANT.GLOBAL.SHOW, this.globalShow)
18+
window.addEventListener(CONSTANT.GLOBAL.SHOW, ::this.globalShow, false)
19+
1620
// Resize
1721
window.removeEventListener('resize', this.onWindowResize)
1822
window.addEventListener('resize', ::this.onWindowResize, false)
@@ -21,6 +25,15 @@ export default function (target) {
2125
target.prototype.unbindWindowEvents = function () {
2226
window.removeEventListener(CONSTANT.GLOBAL.HIDE, this.hideTooltip)
2327
window.removeEventListener(CONSTANT.GLOBAL.REBUILD, this.globalRebuild)
28+
window.removeEventListener(CONSTANT.GLOBAL.REBUILD, this.globalShow)
2429
window.removeEventListener('resize', this.onWindowResize)
2530
}
31+
32+
/**
33+
* invoked by resize event of window
34+
*/
35+
target.prototype.onWindowResize = function () {
36+
if (!this.mount) return
37+
this.hideTooltip()
38+
}
2639
}

0 commit comments

Comments
 (0)