Skip to content

Commit 12064c2

Browse files
committed
add hint close button + add document.onclick
1 parent 8ae5227 commit 12064c2

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

intro.js

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,19 @@
11391139
return true;
11401140
};
11411141

1142+
/**
1143+
* Removes open hint (tooltip hint)
1144+
*
1145+
* @api private
1146+
* @method _removeHintTooltip
1147+
*/
1148+
function _removeHintTooltip() {
1149+
var tooltip = this._targetElement.querySelector('.introjs-hintTooltip');
1150+
1151+
if (tooltip) {
1152+
tooltip.parentNode.removeChild(tooltip);
1153+
}
1154+
};
11421155

11431156
/**
11441157
* Start parsing hint items
@@ -1184,6 +1197,31 @@
11841197
}
11851198

11861199
_addHints.call(this);
1200+
1201+
if (window.addEventListener) {
1202+
window.addEventListener('click', _removeHintTooltip.bind(this), true);
1203+
//for window resize
1204+
//window.addEventListener('resize', this._onResize, true);
1205+
} else if (document.attachEvent) { //IE
1206+
//for window resize
1207+
document.attachEvent('onclick', _removeHintTooltip.bind(this));
1208+
//document.attachEvent('onresize', self._onResize);
1209+
}
1210+
};
1211+
1212+
/**
1213+
* Remove single hint from the page
1214+
*
1215+
* @api private
1216+
* @method _removeHint
1217+
*/
1218+
function _removeHint(stepId) {
1219+
_removeHintTooltip.call(this);
1220+
var hint = this._targetElement.querySelector('.introjs-hint[data-step="' + stepId + '"]');
1221+
1222+
if (hint) {
1223+
hint.parentNode.removeChild(hint);
1224+
}
11871225
};
11881226

11891227
/**
@@ -1203,7 +1241,7 @@
12031241
hint.href = "javascript:void(0);";
12041242

12051243
// when user clicks on the hint element
1206-
hint.onclick = _hintClick.bind(this, hint, item);
1244+
hint.onclick = _hintClick.bind(this, hint, item, i);
12071245

12081246
hint.className = 'introjs-hint';
12091247
var hintDot = document.createElement('div');
@@ -1266,8 +1304,11 @@
12661304
* @method _hintClick
12671305
* @param {Object} hintElement
12681306
* @param {Object} item
1307+
* @param {Number} stepId
12691308
*/
1270-
function _hintClick(hintElement, item) {
1309+
function _hintClick(hintElement, item, stepId) {
1310+
_removeHintTooltip.call(this);
1311+
12711312
var tooltipLayer = document.createElement('div');
12721313
var tooltipTextLayer = document.createElement('div');
12731314
var arrowLayer = document.createElement('div');
@@ -1283,6 +1324,7 @@
12831324
var closeButton = document.createElement('a');
12841325
closeButton.className = 'introjs-button';
12851326
closeButton.innerHTML = this._options.hintButtonLabel;
1327+
closeButton.onclick = _removeHint.bind(this, stepId);
12861328

12871329
tooltipTextLayer.appendChild(tooltipWrapper);
12881330
tooltipTextLayer.appendChild(closeButton);

0 commit comments

Comments
 (0)