|
1 | 1 | /**
|
2 |
| - * Intro.js v0.7.1 |
| 2 | + * Intro.js v0.8.0 |
3 | 3 | * https://github.com/usablica/intro.js
|
4 | 4 | * MIT licensed
|
5 | 5 | *
|
|
19 | 19 | }
|
20 | 20 | } (this, function (exports) {
|
21 | 21 | //Default config/variables
|
22 |
| - var VERSION = '0.7.1'; |
| 22 | + var VERSION = '0.8.0'; |
23 | 23 |
|
24 | 24 | /**
|
25 | 25 | * IntroJs main class
|
|
85 | 85 | currentItem.element = document.querySelector(currentItem.element);
|
86 | 86 | }
|
87 | 87 |
|
| 88 | + //intro without element |
| 89 | + if (typeof(currentItem.element) === 'undefined' || currentItem.element == null) { |
| 90 | + var floatingElementQuery = document.querySelector(".introjsFloatingElement"); |
| 91 | + |
| 92 | + if (floatingElementQuery == null) { |
| 93 | + floatingElementQuery = document.createElement('div'); |
| 94 | + floatingElementQuery.className = 'introjsFloatingElement'; |
| 95 | + |
| 96 | + document.body.appendChild(floatingElementQuery); |
| 97 | + } |
| 98 | + |
| 99 | + currentItem.element = floatingElementQuery; |
| 100 | + currentItem.position = 'floating'; |
| 101 | + } |
| 102 | + |
88 | 103 | if (currentItem.element != null) {
|
89 | 104 | introItems.push(currentItem);
|
90 | 105 | }
|
|
215 | 230 | * @method _cloneObject
|
216 | 231 | */
|
217 | 232 | function _cloneObject(object) {
|
218 |
| - if (object == null || typeof (object) != 'object' || object.hasOwnProperty("nodeName") === true || typeof (object.nodeType) != 'undefined') { |
| 233 | + if (object == null || typeof (object) != 'object' || typeof (object.nodeType) != 'undefined') { |
219 | 234 | return object;
|
220 | 235 | }
|
221 | 236 | var temp = {};
|
|
266 | 281 | this._introBeforeChangeCallback.call(this, nextStep.element);
|
267 | 282 | }
|
268 | 283 |
|
| 284 | + this._direction = 'forward'; |
269 | 285 | _showElement.call(this, nextStep);
|
270 | 286 | }
|
271 | 287 |
|
|
285 | 301 | this._introBeforeChangeCallback.call(this, nextStep.element);
|
286 | 302 | }
|
287 | 303 |
|
| 304 | + this._direction = 'backward'; |
288 | 305 | _showElement.call(this, nextStep);
|
289 | 306 | }
|
290 | 307 |
|
|
298 | 315 | function _exitIntro(targetElement) {
|
299 | 316 | //remove overlay layer from the page
|
300 | 317 | var overlayLayer = targetElement.querySelector('.introjs-overlay');
|
| 318 | + |
301 | 319 | //return if intro already completed or skipped
|
302 | 320 | if (overlayLayer == null) {
|
303 | 321 | return;
|
304 | 322 | }
|
| 323 | + |
305 | 324 | //for fade-out animation
|
306 | 325 | overlayLayer.style.opacity = 0;
|
307 | 326 | setTimeout(function () {
|
308 | 327 | if (overlayLayer.parentNode) {
|
309 | 328 | overlayLayer.parentNode.removeChild(overlayLayer);
|
310 | 329 | }
|
311 | 330 | }, 500);
|
| 331 | + |
312 | 332 | //remove all helper layers
|
313 | 333 | var helperLayer = targetElement.querySelector('.introjs-helperLayer');
|
314 | 334 | if (helperLayer) {
|
315 | 335 | helperLayer.parentNode.removeChild(helperLayer);
|
316 | 336 | }
|
| 337 | + |
| 338 | + //remove intro floating element |
| 339 | + var floatingElement = document.querySelector('.introjsFloatingElement'); |
| 340 | + if (floatingElement) { |
| 341 | + floatingElement.parentNode.removeChild(floatingElement); |
| 342 | + } |
| 343 | + |
317 | 344 | //remove `introjs-showElement` class from the element
|
318 | 345 | var showElement = document.querySelector('.introjs-showElement');
|
319 | 346 | if (showElement) {
|
|
327 | 354 | fixParents[i].className = fixParents[i].className.replace(/introjs-fixParent/g, '').replace(/^\s+|\s+$/g, '');
|
328 | 355 | };
|
329 | 356 | }
|
| 357 | + |
330 | 358 | //clean listeners
|
331 | 359 | if (window.removeEventListener) {
|
332 | 360 | window.removeEventListener('keydown', this._onKeyDown, true);
|
333 | 361 | } else if (document.detachEvent) { //IE
|
334 | 362 | document.detachEvent('onkeydown', this._onKeyDown);
|
335 | 363 | }
|
| 364 | + |
336 | 365 | //set the step to zero
|
337 | 366 | this._currentStep = undefined;
|
338 | 367 | }
|
|
346 | 375 | * @param {Object} tooltipLayer
|
347 | 376 | * @param {Object} arrowLayer
|
348 | 377 | */
|
349 |
| - function _placeTooltip(targetElement, tooltipLayer, arrowLayer) { |
| 378 | + function _placeTooltip(targetElement, tooltipLayer, arrowLayer, helperNumberLayer) { |
350 | 379 | //reset the old style
|
351 |
| - tooltipLayer.style.top = null; |
352 |
| - tooltipLayer.style.right = null; |
353 |
| - tooltipLayer.style.bottom = null; |
354 |
| - tooltipLayer.style.left = null; |
| 380 | + tooltipLayer.style.top = null; |
| 381 | + tooltipLayer.style.right = null; |
| 382 | + tooltipLayer.style.bottom = null; |
| 383 | + tooltipLayer.style.left = null; |
| 384 | + tooltipLayer.style.marginLeft = null; |
| 385 | + tooltipLayer.style.marginTop = null; |
| 386 | + |
| 387 | + arrowLayer.style.display = 'inherit'; |
| 388 | + |
| 389 | + if (typeof(helperNumberLayer) != 'undefined' && helperNumberLayer != null) { |
| 390 | + helperNumberLayer.style.top = null; |
| 391 | + helperNumberLayer.style.left = null; |
| 392 | + } |
355 | 393 |
|
356 | 394 | //prevent error when `this._currentStep` is undefined
|
357 | 395 | if (!this._introItems[this._currentStep]) return;
|
|
388 | 426 | }
|
389 | 427 | tooltipLayer.style.right = (_getOffset(targetElement).width + 20) + 'px';
|
390 | 428 | arrowLayer.className = 'introjs-arrow right';
|
| 429 | + break; |
| 430 | + case 'floating': |
| 431 | + arrowLayer.style.display = 'none'; |
| 432 | + |
| 433 | + //we have to adjust the top and left of layer manually for intro items without element{ |
| 434 | + var tooltipOffset = _getOffset(tooltipLayer); |
| 435 | + |
| 436 | + tooltipLayer.style.left = '50%'; |
| 437 | + tooltipLayer.style.top = '50%'; |
| 438 | + tooltipLayer.style.marginLeft = '-' + (tooltipOffset.width / 2) + 'px'; |
| 439 | + tooltipLayer.style.marginTop = '-' + (tooltipOffset.height / 2) + 'px'; |
| 440 | + |
| 441 | + if (typeof(helperNumberLayer) != 'undefined' && helperNumberLayer != null) { |
| 442 | + helperNumberLayer.style.left = '-' + ((tooltipOffset.width / 2) + 18) + 'px'; |
| 443 | + helperNumberLayer.style.top = '-' + ((tooltipOffset.height / 2) + 18) + 'px'; |
| 444 | + } |
| 445 | + |
391 | 446 | break;
|
392 | 447 | case 'bottom':
|
393 | 448 | // Bottom going to follow the default behavior
|
|
410 | 465 | //prevent error when `this._currentStep` in undefined
|
411 | 466 | if (!this._introItems[this._currentStep]) return;
|
412 | 467 |
|
413 |
| - var elementPosition = _getOffset(this._introItems[this._currentStep].element); |
| 468 | + var currentElement = this._introItems[this._currentStep]; |
| 469 | + var elementPosition = _getOffset(currentElement.element); |
| 470 | + |
| 471 | + var widthHeightPadding = 10; |
| 472 | + if (currentElement.position == 'floating') { |
| 473 | + widthHeightPadding = 0; |
| 474 | + } |
| 475 | + |
414 | 476 | //set new position to helper layer
|
415 |
| - helperLayer.setAttribute('style', 'width: ' + (elementPosition.width + 10) + 'px; ' + |
416 |
| - 'height:' + (elementPosition.height + 10) + 'px; ' + |
| 477 | + helperLayer.setAttribute('style', 'width: ' + (elementPosition.width + widthHeightPadding) + 'px; ' + |
| 478 | + 'height:' + (elementPosition.height + widthHeightPadding) + 'px; ' + |
417 | 479 | 'top:' + (elementPosition.top - 5) + 'px;' +
|
418 | 480 | 'left: ' + (elementPosition.left - 5) + 'px;');
|
419 | 481 | }
|
|
448 | 510 | //hide the tooltip
|
449 | 511 | oldtooltipContainer.style.opacity = 0;
|
450 | 512 |
|
| 513 | + if (oldHelperNumberLayer != null) { |
| 514 | + var lastIntroItem = this._introItems[(targetElement.step - 2 >= 0 ? targetElement.step - 2 : 0)]; |
| 515 | + |
| 516 | + if (lastIntroItem != null && (this._direction == 'forward' && lastIntroItem.position == 'floating') || (this._direction == 'backward' && targetElement.position == 'floating')) { |
| 517 | + oldHelperNumberLayer.style.opacity = 0; |
| 518 | + } |
| 519 | + } |
| 520 | + |
451 | 521 | //set new position to helper layer
|
452 | 522 | _setHelperLayerPosition.call(self, oldHelperLayer);
|
453 | 523 |
|
|
474 | 544 | //set current tooltip text
|
475 | 545 | oldtooltipLayer.innerHTML = targetElement.intro;
|
476 | 546 | //set the tooltip position
|
477 |
| - _placeTooltip.call(self, targetElement.element, oldtooltipContainer, oldArrowLayer); |
| 547 | + _placeTooltip.call(self, targetElement.element, oldtooltipContainer, oldArrowLayer, oldHelperNumberLayer); |
478 | 548 |
|
479 | 549 | //change active bullet
|
480 | 550 | oldHelperLayer.querySelector('.introjs-bullets li > a.active').className = '';
|
481 | 551 | oldHelperLayer.querySelector('.introjs-bullets li > a[data-stepnumber="' + targetElement.step + '"]').className = 'active';
|
482 | 552 |
|
483 | 553 | //show the tooltip
|
484 | 554 | oldtooltipContainer.style.opacity = 1;
|
| 555 | + oldHelperNumberLayer.style.opacity = 1; |
485 | 556 | }, 350);
|
486 | 557 |
|
487 | 558 | } else {
|
|
605 | 676 | tooltipLayer.appendChild(buttonsLayer);
|
606 | 677 |
|
607 | 678 | //set proper position
|
608 |
| - _placeTooltip.call(self, targetElement.element, tooltipLayer, arrowLayer); |
| 679 | + _placeTooltip.call(self, targetElement.element, tooltipLayer, arrowLayer, helperNumberLayer); |
609 | 680 | }
|
610 | 681 |
|
611 | 682 | if (this._currentStep == 0 && this._introItems.length > 1) {
|
|
0 commit comments