Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow user to specify separate off event for the tooltip #103

Merged
merged 5 commits into from
Jun 1, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions dist/react-tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ var ReactTooltip = function (_Component) {
delayHide: 0,
delayShow: 0,
event: props.event || null,
eventoff: props.eventOff || null,
isCapture: props.isCapture || false
};
_this.delayShowLoop = null;
Expand Down Expand Up @@ -170,15 +171,26 @@ var ReactTooltip = function (_Component) {
value: function bindListener() {
var targetArray = this.getTargetArray();

var dataEvent = undefined;
var dataEvent = void 0;
var dataEventOff = void 0;
for (var i = 0; i < targetArray.length; i++) {
if (targetArray[i].getAttribute('currentItem') === null) {
targetArray[i].setAttribute('currentItem', 'false');
}
dataEvent = this.state.event || targetArray[i].getAttribute('data-event');
if (dataEvent) {
targetArray[i].removeEventListener(dataEvent, this.checkStatus);
targetArray[i].addEventListener(dataEvent, this.checkStatus, false);
dataEventOff = this.state.eventOff || targetArray[i].getAttribute('data-event-off');
// if off event is specified, we will show tip on data-event and hide it on data-event-off
if (dataEventOff) {
targetArray[i].removeEventListener(dataEvent, this.showTooltip);
targetArray[i].addEventListener(dataEvent, this.showTooltip, false);

targetArray[i].removeEventListener(dataEventOff, this.hideTooltip);
targetArray[i].addEventListener(dataEventOff, this.hideTooltip, false);
} else {
targetArray[i].removeEventListener(dataEvent, this.checkStatus);
targetArray[i].addEventListener(dataEvent, this.checkStatus, false);
}
} else {
targetArray[i].removeEventListener('mouseenter', this.showTooltip);
targetArray[i].addEventListener('mouseenter', this.showTooltip, false);
Expand All @@ -197,7 +209,7 @@ var ReactTooltip = function (_Component) {
key: 'unbindListener',
value: function unbindListener() {
var targetArray = document.querySelectorAll('[data-tip]');
var dataEvent = undefined;
var dataEvent = void 0;

for (var i = 0; i < targetArray.length; i++) {
dataEvent = this.state.event || targetArray[i].getAttribute('data-event');
Expand All @@ -220,7 +232,7 @@ var ReactTooltip = function (_Component) {
value: function getTargetArray() {
var id = this.props.id;

var targetArray = undefined;
var targetArray = void 0;

if (id === undefined) {
targetArray = document.querySelectorAll('[data-tip]:not([data-for])');
Expand Down Expand Up @@ -269,7 +281,7 @@ var ReactTooltip = function (_Component) {
value: function checkStatus(e) {
var show = this.state.show;

var isCapture = undefined;
var isCapture = void 0;

if (e.currentTarget.getAttribute('data-iscapture')) {
isCapture = e.currentTarget.getAttribute('data-iscapture') === 'true';
Expand Down Expand Up @@ -320,7 +332,7 @@ var ReactTooltip = function (_Component) {
/* Detect multiline */
var regexp = /<br\s*\/?>/;
var multiline = e.currentTarget.getAttribute('data-multiline') ? e.currentTarget.getAttribute('data-multiline') : this.props.multiline ? this.props.multiline : false;
var tooltipText = undefined;
var tooltipText = void 0;
var multilineCount = 0;
if (!multiline || multiline === 'false' || !regexp.test(originTooltip)) {
tooltipText = originTooltip;
Expand Down Expand Up @@ -455,8 +467,8 @@ var ReactTooltip = function (_Component) {
var targetHeight = currentTarget.clientHeight;
var windoWidth = window.innerWidth;
var windowHeight = window.innerHeight;
var x = undefined;
var y = undefined;
var x = void 0;
var y = void 0;
var defaultTopY = targetTop - tipHeight - 8;
var defaultBottomY = targetTop + targetHeight + 8;
var defaultLeftX = targetLeft - tipWidth - 6;
Expand Down Expand Up @@ -728,8 +740,8 @@ var ReactTooltip = function (_Component) {
}
firstCount++;
}
for (var i = string.length - 1; i >= 0; i--) {
if (string[i] !== ' ') {
for (var _i = string.length - 1; _i >= 0; _i--) {
if (string[_i] !== ' ') {
break;
}
lastCount++;
Expand Down Expand Up @@ -757,6 +769,7 @@ ReactTooltip.propTypes = {
delayHide: _react.PropTypes.number,
delayShow: _react.PropTypes.number,
event: _react.PropTypes.any,
eventOff: _react.PropTypes.any,
watchWindow: _react.PropTypes.bool,
isCapture: _react.PropTypes.bool
};
Expand Down
Loading