Skip to content

Commit c2848f9

Browse files
committed
Merge pull request usablica#330 from connyay/allow-custom-class-on-helper
Allow custom class on helper
2 parents 1ab36b3 + 403050a commit c2848f9

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ introJs().onafterchange(function(targetElement) {
330330
- `data-intro`: The tooltip text of step
331331
- `data-step`: Optionally define the number (priority) of step
332332
- `data-tooltipClass`: Optionally define a CSS class for tooltip
333+
- `data-highlightClass`: Optionally append a CSS class to the helperLayer
333334
- `data-position`: Optionally define the position of tooltip, `top`, `left`, `right`, `bottom`, `bottom-left-aligned` (same as 'bottom'), 'bottom-middle-aligned' and 'bottom-right-aligned'. Default is `bottom`
334335

335336
###Options:
@@ -341,6 +342,7 @@ introJs().onafterchange(function(targetElement) {
341342
- `doneLabel`: Done button label
342343
- `tooltipPosition`: Default tooltip position
343344
- `tooltipClass`: Adding CSS class to all tooltips
345+
- `highlightClass`: Additional CSS class for the helperLayer
344346
- `exitOnEsc`: Exit introduction when pressing Escape button, `true` or `false`
345347
- `exitOnOverlayClick`: Exit introduction when clicking on overlay layer, `true` or `false`
346348
- `showStepNumbers`: Show steps number in the red circle or not, `true` or `false`

intro.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
tooltipPosition: 'bottom',
4343
/* Next CSS class for tooltip boxes */
4444
tooltipClass: '',
45+
/* CSS class that is added to the helperLayer */
46+
highlightClass: '',
4547
/* Close introduction when pressing Escape button? */
4648
exitOnEsc: true,
4749
/* Close introduction when clicking on overlay layer? */
@@ -130,6 +132,7 @@
130132
intro: currentElement.getAttribute('data-intro'),
131133
step: parseInt(currentElement.getAttribute('data-step'), 10),
132134
tooltipClass: currentElement.getAttribute('data-tooltipClass'),
135+
highlightClass: currentElement.getAttribute('data-highlightClass'),
133136
position: currentElement.getAttribute('data-position') || this._options.tooltipPosition
134137
};
135138
}
@@ -156,6 +159,7 @@
156159
intro: currentElement.getAttribute('data-intro'),
157160
step: nextStep + 1,
158161
tooltipClass: currentElement.getAttribute('data-tooltipClass'),
162+
highlightClass: currentElement.getAttribute('data-highlightClass'),
159163
position: currentElement.getAttribute('data-position') || this._options.tooltipPosition
160164
};
161165
}
@@ -515,7 +519,7 @@
515519
break;
516520
}
517521
}
518-
522+
519523
/**
520524
* Determines the position of the tooltip based on the position precedence and availability
521525
* of screen space.
@@ -655,8 +659,18 @@
655659
var self = this,
656660
oldHelperLayer = document.querySelector('.introjs-helperLayer'),
657661
oldReferenceLayer = document.querySelector('.introjs-tooltipReferenceLayer'),
662+
highlightClass = 'introjs-helperLayer',
658663
elementPosition = _getOffset(targetElement.element);
659664

665+
//check for a current step highlight class
666+
if (typeof (targetElement.highlightClass) === 'string') {
667+
highlightClass += (' ' + targetElement.highlightClass);
668+
}
669+
//check for options highlight class
670+
if (typeof (this._options.highlightClass) === 'string') {
671+
highlightClass += (' ' + this._options.highlightClass);
672+
}
673+
660674
if (oldHelperLayer != null) {
661675
var oldHelperNumberLayer = oldReferenceLayer.querySelector('.introjs-helperNumberLayer'),
662676
oldtooltipLayer = oldReferenceLayer.querySelector('.introjs-tooltiptext'),
@@ -666,6 +680,8 @@
666680
prevTooltipButton = oldReferenceLayer.querySelector('.introjs-prevbutton'),
667681
nextTooltipButton = oldReferenceLayer.querySelector('.introjs-nextbutton');
668682

683+
//update or reset the helper highlight class
684+
oldHelperLayer.className = highlightClass;
669685
//hide the tooltip
670686
oldtooltipContainer.style.opacity = 0;
671687
oldtooltipContainer.style.display = "none";
@@ -727,7 +743,7 @@
727743
bulletsLayer = document.createElement('div'),
728744
buttonsLayer = document.createElement('div');
729745

730-
helperLayer.className = 'introjs-helperLayer';
746+
helperLayer.className = highlightClass;
731747
referenceLayer.className = 'introjs-tooltipReferenceLayer';
732748

733749
//set new position to helper layer

0 commit comments

Comments
 (0)