|
428 | 428 | * @param {HTMLElement} tooltipLayer
|
429 | 429 | * @param {HTMLElement} arrowLayer
|
430 | 430 | * @param {HTMLElement} helperNumberLayer
|
| 431 | + * @param {Boolean} hintMode |
431 | 432 | */
|
432 |
| - function _placeTooltip(targetElement, tooltipLayer, arrowLayer, helperNumberLayer) { |
| 433 | + function _placeTooltip(targetElement, tooltipLayer, arrowLayer, helperNumberLayer, hintMode) { |
433 | 434 | var tooltipCssClass = '',
|
434 | 435 | currentStepObj,
|
435 | 436 | tooltipOffset,
|
436 | 437 | targetOffset,
|
437 | 438 | windowSize,
|
438 | 439 | currentTooltipPosition;
|
439 | 440 |
|
| 441 | + hintMode = hintMode || false; |
| 442 | + |
440 | 443 | //reset the old style
|
441 | 444 | tooltipLayer.style.top = null;
|
442 | 445 | tooltipLayer.style.right = null;
|
|
474 | 477 | targetOffset = _getOffset(targetElement);
|
475 | 478 | tooltipOffset = _getOffset(tooltipLayer);
|
476 | 479 | windowSize = _getWinSize();
|
| 480 | + |
477 | 481 | switch (currentTooltipPosition) {
|
478 | 482 | case 'top':
|
479 | 483 | arrowLayer.className = 'introjs-arrow bottom';
|
480 | 484 |
|
481 |
| - var tooltipLayerStyleLeft = 15; |
| 485 | + if (hintMode) { |
| 486 | + var tooltipLayerStyleLeft = 0; |
| 487 | + } else { |
| 488 | + var tooltipLayerStyleLeft = 15; |
| 489 | + } |
| 490 | + |
482 | 491 | _checkRight(targetOffset, tooltipLayerStyleLeft, tooltipOffset, windowSize, tooltipLayer);
|
483 | 492 | tooltipLayer.style.bottom = (targetOffset.height + 20) + 'px';
|
484 | 493 | break;
|
|
494 | 503 | }
|
495 | 504 | break;
|
496 | 505 | case 'left':
|
497 |
| - if (this._options.showStepNumbers == true) { |
| 506 | + if (!hintMode && this._options.showStepNumbers == true) { |
498 | 507 | tooltipLayer.style.top = '15px';
|
499 | 508 | }
|
500 | 509 |
|
|
536 | 545 | arrowLayer.className = 'introjs-arrow top-middle';
|
537 | 546 |
|
538 | 547 | var tooltipLayerStyleLeftRight = targetOffset.width / 2 - tooltipOffset.width / 2;
|
| 548 | + |
| 549 | + // a fix for middle aligned hints |
| 550 | + if (hintMode) { |
| 551 | + tooltipLayerStyleLeftRight += 5; |
| 552 | + } |
| 553 | + |
539 | 554 | if (_checkLeft(targetOffset, tooltipLayerStyleLeftRight, tooltipOffset, tooltipLayer)) {
|
540 | 555 | tooltipLayer.style.right = null;
|
541 | 556 | _checkRight(targetOffset, tooltipLayerStyleLeftRight, tooltipOffset, windowSize, tooltipLayer);
|
|
1146 | 1161 | * @method _removeHintTooltip
|
1147 | 1162 | */
|
1148 | 1163 | function _removeHintTooltip() {
|
1149 |
| - var tooltip = this._targetElement.querySelector('.introjs-hintTooltip'); |
| 1164 | + var tooltip = this._targetElement.querySelector('.introjs-hintReference'); |
| 1165 | + |
1150 | 1166 |
|
1151 | 1167 | if (tooltip) {
|
| 1168 | + var step = tooltip.getAttribute('data-step'); |
1152 | 1169 | tooltip.parentNode.removeChild(tooltip);
|
| 1170 | + return step; |
1153 | 1171 | }
|
1154 | 1172 | };
|
1155 | 1173 |
|
|
1198 | 1216 |
|
1199 | 1217 | _addHints.call(this);
|
1200 | 1218 |
|
1201 |
| - if (window.addEventListener) { |
1202 |
| - window.addEventListener('click', _removeHintTooltip.bind(this), true); |
| 1219 | + if (document.addEventListener) { |
| 1220 | + document.addEventListener('click', _removeHintTooltip.bind(this), false); |
1203 | 1221 | //for window resize
|
1204 | 1222 | //window.addEventListener('resize', this._onResize, true);
|
1205 | 1223 | } else if (document.attachEvent) { //IE
|
|
1231 | 1249 | * @method _addHints
|
1232 | 1250 | */
|
1233 | 1251 | function _addHints() {
|
| 1252 | + var self = this; |
1234 | 1253 | var hintsWrapper = document.createElement('div');
|
1235 | 1254 | hintsWrapper.className = 'introjs-hints';
|
1236 | 1255 |
|
|
1240 | 1259 | var hint = document.createElement('a');
|
1241 | 1260 | hint.href = "javascript:void(0);";
|
1242 | 1261 |
|
1243 |
| - // when user clicks on the hint element |
1244 |
| - hint.onclick = _hintClick.bind(this, hint, item, i); |
| 1262 | + (function (hint, item, i) { |
| 1263 | + // when user clicks on the hint element |
| 1264 | + hint.onclick = function(e) { |
| 1265 | + var evt = e ? e : window.event; |
| 1266 | + if (evt.stopPropagation) evt.stopPropagation(); |
| 1267 | + if (evt.cancelBubble != null) evt.cancelBubble = true; |
| 1268 | + |
| 1269 | + _hintClick.call(self, hint, item, i); |
| 1270 | + }; |
| 1271 | + }(hint, item, i)); |
1245 | 1272 |
|
1246 | 1273 | hint.className = 'introjs-hint';
|
1247 | 1274 | var hintDot = document.createElement('div');
|
|
1307 | 1334 | * @param {Number} stepId
|
1308 | 1335 | */
|
1309 | 1336 | function _hintClick(hintElement, item, stepId) {
|
1310 |
| - _removeHintTooltip.call(this); |
| 1337 | + // remove all open tooltips |
| 1338 | + var removedStep = _removeHintTooltip.call(this); |
| 1339 | + |
| 1340 | + // to toggle the tooltip |
| 1341 | + if (parseInt(removedStep, 10) == stepId) { |
| 1342 | + return; |
| 1343 | + } |
1311 | 1344 |
|
1312 | 1345 | var tooltipLayer = document.createElement('div');
|
1313 | 1346 | var tooltipTextLayer = document.createElement('div');
|
|
1316 | 1349 |
|
1317 | 1350 | tooltipLayer.className = 'introjs-tooltip';
|
1318 | 1351 |
|
| 1352 | + tooltipLayer.onclick = function (e) { |
| 1353 | + //IE9 & Other Browsers |
| 1354 | + if (e.stopPropagation) { |
| 1355 | + e.stopPropagation(); |
| 1356 | + } |
| 1357 | + //IE8 and Lower |
| 1358 | + else { |
| 1359 | + e.cancelBubble = true; |
| 1360 | + } |
| 1361 | + }; |
| 1362 | + |
1319 | 1363 | tooltipTextLayer.className = 'introjs-tooltiptext';
|
1320 | 1364 |
|
1321 | 1365 | var tooltipWrapper = document.createElement('p');
|
|
1338 | 1382 | this._currentStep = hintElement.getAttribute('data-step');
|
1339 | 1383 |
|
1340 | 1384 | // align reference layer position
|
1341 |
| - referenceLayer.className = 'introjs-tooltipReferenceLayer introjs-hintTooltip'; |
| 1385 | + referenceLayer.className = 'introjs-tooltipReferenceLayer introjs-hintReference'; |
1342 | 1386 | referenceLayer.setAttribute('data-step', hintElement.getAttribute('data-step'));
|
1343 | 1387 | _setHelperLayerPosition.call(this, referenceLayer);
|
1344 | 1388 |
|
1345 | 1389 | referenceLayer.appendChild(tooltipLayer);
|
1346 | 1390 | document.body.appendChild(referenceLayer);
|
1347 | 1391 |
|
1348 | 1392 | //set proper position
|
1349 |
| - _placeTooltip.call(this, hintElement, tooltipLayer, arrowLayer); |
| 1393 | + _placeTooltip.call(this, hintElement, tooltipLayer, arrowLayer, null, true); |
1350 | 1394 | };
|
1351 | 1395 |
|
1352 | 1396 | /**
|
|
1508 | 1552 | }
|
1509 | 1553 | return this;
|
1510 | 1554 | },
|
| 1555 | + onhintsadded: function(providedCallback) { |
| 1556 | + if (typeof (providedCallback) === 'function') { |
| 1557 | + this._hintsAddedCallback = providedCallback; |
| 1558 | + } else { |
| 1559 | + throw new Error('Provided callback for onhintsadded was not a function.'); |
| 1560 | + } |
| 1561 | + return this; |
| 1562 | + }, |
| 1563 | + onhintclick: function(providedCallback) { |
| 1564 | + if (typeof (providedCallback) === 'function') { |
| 1565 | + this._hintClickCallback = providedCallback; |
| 1566 | + } else { |
| 1567 | + throw new Error('Provided callback for onhintclick was not a function.'); |
| 1568 | + } |
| 1569 | + return this; |
| 1570 | + }, |
| 1571 | + onhintremove: function(providedCallback) { |
| 1572 | + if (typeof (providedCallback) === 'function') { |
| 1573 | + this._hintRemoveCallback = providedCallback; |
| 1574 | + } else { |
| 1575 | + throw new Error('Provided callback for onhintremove was not a function.'); |
| 1576 | + } |
| 1577 | + return this; |
| 1578 | + }, |
1511 | 1579 | onexit: function(providedCallback) {
|
1512 | 1580 | if (typeof (providedCallback) === 'function') {
|
1513 | 1581 | this._introExitCallback = providedCallback;
|
|
0 commit comments