Skip to content

Commit e2baddf

Browse files
committed
merge with upstream
2 parents c127cd4 + fbcae72 commit e2baddf

File tree

6 files changed

+157
-34
lines changed

6 files changed

+157
-34
lines changed

README.md

Lines changed: 3 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,12 +342,14 @@ 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`
347349
- `keyboardNavigation`: Navigating with keyboard or not, `true` or `false`
348350
- `showButtons`: Show introduction navigation buttons or not, `true` or `false`
349351
- `showBullets`: Show introduction bullets or not, `true` or `false`
352+
- `showProgress`: Show introduction progress or not, `true` or `false`
350353
- `scrollToElement`: Auto scroll to highlighted element if it's outside of viewport, `true` or `false`
351354
- `overlayOpacity`: Adjust the overlay opacity, `Number`
352355
- `disableInteraction`: Disable an interaction inside element or not, `true` or `false`

intro.js

Lines changed: 78 additions & 4 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? */
@@ -54,6 +56,8 @@
5456
showButtons: true,
5557
/* Show tour bullets? */
5658
showBullets: true,
59+
/* Show tour progress? */
60+
showProgress: false,
5761
/* Scroll to highlighted element? */
5862
scrollToElement: true,
5963
/* Set the overlay opacity */
@@ -130,6 +134,7 @@
130134
intro: currentElement.getAttribute('data-intro'),
131135
step: parseInt(currentElement.getAttribute('data-step'), 10),
132136
tooltipClass: currentElement.getAttribute('data-tooltipClass'),
137+
highlightClass: currentElement.getAttribute('data-highlightClass'),
133138
position: currentElement.getAttribute('data-position') || this._options.tooltipPosition
134139
};
135140
}
@@ -156,6 +161,7 @@
156161
intro: currentElement.getAttribute('data-intro'),
157162
step: nextStep + 1,
158163
tooltipClass: currentElement.getAttribute('data-tooltipClass'),
164+
highlightClass: currentElement.getAttribute('data-highlightClass'),
159165
position: currentElement.getAttribute('data-position') || this._options.tooltipPosition
160166
};
161167
}
@@ -197,9 +203,23 @@
197203
} else if(e.keyCode === 37) {
198204
//left arrow
199205
_previousStep.call(self);
200-
} else if (e.keyCode === 39 || e.keyCode === 13) {
201-
//right arrow or enter
206+
} else if (e.keyCode === 39) {
207+
//right arrow
202208
_nextStep.call(self);
209+
} else if (e.keyCode === 13) {
210+
//srcElement === ie
211+
var target = e.target || e.srcElement;
212+
if (target && target.className.indexOf('introjs-prevbutton') > 0) {
213+
//user hit enter while focusing on previous button
214+
_previousStep.call(self);
215+
} else if (target && target.className.indexOf('introjs-skipbutton') > 0) {
216+
//user hit enter while focusing on skip button
217+
_exitIntro.call(self, targetElm);
218+
} else {
219+
//default behavior for responding to enter
220+
_nextStep.call(self);
221+
}
222+
203223
//prevent default behaviour on hitting Enter, to prevent steps being skipped in some browsers
204224
if(e.preventDefault) {
205225
e.preventDefault();
@@ -515,7 +535,7 @@
515535
break;
516536
}
517537
}
518-
538+
519539
/**
520540
* Determines the position of the tooltip based on the position precedence and availability
521541
* of screen space.
@@ -655,8 +675,18 @@
655675
var self = this,
656676
oldHelperLayer = document.querySelector('.introjs-helperLayer'),
657677
oldReferenceLayer = document.querySelector('.introjs-tooltipReferenceLayer'),
678+
highlightClass = 'introjs-helperLayer',
658679
elementPosition = _getOffset(targetElement.element);
659680

681+
//check for a current step highlight class
682+
if (typeof (targetElement.highlightClass) === 'string') {
683+
highlightClass += (' ' + targetElement.highlightClass);
684+
}
685+
//check for options highlight class
686+
if (typeof (this._options.highlightClass) === 'string') {
687+
highlightClass += (' ' + this._options.highlightClass);
688+
}
689+
660690
if (oldHelperLayer != null) {
661691
var oldHelperNumberLayer = oldReferenceLayer.querySelector('.introjs-helperNumberLayer'),
662692
oldtooltipLayer = oldReferenceLayer.querySelector('.introjs-tooltiptext'),
@@ -666,6 +696,8 @@
666696
prevTooltipButton = oldReferenceLayer.querySelector('.introjs-prevbutton'),
667697
nextTooltipButton = oldReferenceLayer.querySelector('.introjs-nextbutton');
668698

699+
//update or reset the helper highlight class
700+
oldHelperLayer.className = highlightClass;
669701
//hide the tooltip
670702
oldtooltipContainer.style.opacity = 0;
671703
oldtooltipContainer.style.display = "none";
@@ -713,9 +745,20 @@
713745
oldReferenceLayer.querySelector('.introjs-bullets li > a.active').className = '';
714746
oldReferenceLayer.querySelector('.introjs-bullets li > a[data-stepnumber="' + targetElement.step + '"]').className = 'active';
715747

748+
oldReferenceLayer.querySelector('.introjs-progress .introjs-progressbar').setAttribute('style', 'width:' + _getProgress.call(self) + '%;');
749+
716750
//show the tooltip
717751
oldtooltipContainer.style.opacity = 1;
718752
if (oldHelperNumberLayer) oldHelperNumberLayer.style.opacity = 1;
753+
754+
//reset button focus
755+
if (nextTooltipButton.tabIndex === -1) {
756+
//tabindex of -1 means we are at the end of the tour - focus on skip / done
757+
skipTooltipButton.focus();
758+
} else {
759+
//still in the tour, focus on next
760+
nextTooltipButton.focus();
761+
}
719762
}, 350);
720763

721764
} else {
@@ -725,9 +768,10 @@
725768
tooltipLayer = document.createElement('div'),
726769
tooltipTextLayer = document.createElement('div'),
727770
bulletsLayer = document.createElement('div'),
771+
progressLayer = document.createElement('div'),
728772
buttonsLayer = document.createElement('div');
729773

730-
helperLayer.className = 'introjs-helperLayer';
774+
helperLayer.className = highlightClass;
731775
referenceLayer.className = 'introjs-tooltipReferenceLayer';
732776

733777
//set new position to helper layer
@@ -772,6 +816,17 @@
772816

773817
bulletsLayer.appendChild(ulContainer);
774818

819+
progressLayer.className = 'introjs-progress';
820+
821+
if (this._options.showProgress === false) {
822+
progressLayer.style.display = 'none';
823+
}
824+
var progressBar = document.createElement('div');
825+
progressBar.className = 'introjs-progressbar';
826+
progressBar.setAttribute('style', 'width:' + _getProgress.call(this) + '%;');
827+
828+
progressLayer.appendChild(progressBar);
829+
775830
buttonsLayer.className = 'introjs-tooltipbuttons';
776831
if (this._options.showButtons === false) {
777832
buttonsLayer.style.display = 'none';
@@ -780,6 +835,7 @@
780835
tooltipLayer.className = 'introjs-tooltip';
781836
tooltipLayer.appendChild(tooltipTextLayer);
782837
tooltipLayer.appendChild(bulletsLayer);
838+
tooltipLayer.appendChild(progressLayer);
783839

784840
//add helper layer number
785841
if (this._options.showStepNumbers == true) {
@@ -853,14 +909,19 @@
853909
_disableInteraction.call(self);
854910
}
855911

912+
prevTooltipButton.removeAttribute('tabIndex');
913+
nextTooltipButton.removeAttribute('tabIndex');
914+
856915
if (this._currentStep == 0 && this._introItems.length > 1) {
857916
prevTooltipButton.className = 'introjs-button introjs-prevbutton introjs-disabled';
917+
prevTooltipButton.tabIndex = '-1';
858918
nextTooltipButton.className = 'introjs-button introjs-nextbutton';
859919
skipTooltipButton.innerHTML = this._options.skipLabel;
860920
} else if (this._introItems.length - 1 == this._currentStep || this._introItems.length == 1) {
861921
skipTooltipButton.innerHTML = this._options.doneLabel;
862922
prevTooltipButton.className = 'introjs-button introjs-prevbutton';
863923
nextTooltipButton.className = 'introjs-button introjs-nextbutton introjs-disabled';
924+
nextTooltipButton.tabIndex = '-1';
864925
} else {
865926
prevTooltipButton.className = 'introjs-button introjs-prevbutton';
866927
nextTooltipButton.className = 'introjs-button introjs-nextbutton';
@@ -1062,6 +1123,19 @@
10621123
return elementPosition;
10631124
}
10641125

1126+
/**
1127+
* Gets the current progress percentage
1128+
*
1129+
* @api private
1130+
* @method _getProgress
1131+
* @returns current progress percentage
1132+
*/
1133+
function _getProgress() {
1134+
// Steps are 0 indexed
1135+
var currentStep = parseInt((this._currentStep + 1), 10);
1136+
return ((currentStep / this._introItems.length) * 100);
1137+
}
1138+
10651139
/**
10661140
* Overwrites obj1's values with obj2's and adds obj2's if non existent in obj1
10671141
* via: http://stackoverflow.com/questions/171251/how-can-i-merge-properties-of-two-javascript-objects-dynamically

introjs.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,24 @@ tr.introjs-showElement > th {
316316
.introjs-bullets ul li a.active {
317317
background: #999;
318318
}
319+
320+
.introjs-progress {
321+
overflow: hidden;
322+
height: 10px;
323+
margin: 10px 0 5px 0;
324+
border-radius: 4px;
325+
background-color: #ecf0f1
326+
}
327+
.introjs-progressbar {
328+
float: left;
329+
width: 0%;
330+
height: 100%;
331+
font-size: 10px;
332+
line-height: 10px;
333+
text-align: center;
334+
background-color: #08c;
335+
}
336+
319337
.introjsFloatingElement {
320338
position: absolute;
321339
height: 0;

themes/introjs-nassim.css

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
z-index: 999999;
44
background: #181818;
55
opacity: 0;
6-
6+
77
-webkit-transition: all 0.3s ease-out;
88
-moz-transition: all 0.3s ease-out;
99
-ms-transition: all 0.3s ease-out;
@@ -128,7 +128,7 @@
128128

129129
.introjs-tooltiptext {
130130
margin-left: -10px;
131-
131+
132132
margin-right: -10px;
133133
/* border-top: 1px solid #FFFFFF; */
134134
/* background: #FAFAFA; */
@@ -144,8 +144,8 @@
144144
padding-bottom: 10px;
145145
}
146146

147-
/*
148-
Buttons style by http://nicolasgallagher.com/lab/css3-github-buttons/
147+
/*
148+
Buttons style by http://nicolasgallagher.com/lab/css3-github-buttons/
149149
Changed by Afshin Mehrabani
150150
*/
151151
.introjs-button {
@@ -185,13 +185,13 @@
185185
.introjs-button:hover {
186186
color: #fff;
187187
background: #2671A2;
188-
text-decoration: none;
188+
text-decoration: none;
189189
border-color: #235677;
190190
}
191191

192192
.introjs-button:focus,
193193
.introjs-button:active {
194-
background: #23587A; text-decoration: none;
194+
background: #23587A; text-decoration: none;
195195
color: #fff;
196196
/* bottom: -1px; */
197197
box-shadow: none;
@@ -211,15 +211,15 @@
211211
}
212212

213213
.introjs-skipbutton:hover {
214-
background: #EB1540;
214+
background: #EB1540;
215215
border-color: #B91D0D;
216-
216+
217217
}
218218

219219
.introjs-skipbutton:active, .introjs-skipbutton:focus {
220-
background: #C02312;
220+
background: #C02312;
221221
/* box-shadow: 0 1px 0px -0px #6F1309; */
222-
222+
223223
}
224224

225225
.introjs-prevbutton {
@@ -279,6 +279,15 @@
279279
.introjs-bullets ul li a.active {
280280
background: #999;
281281
}
282+
283+
.introjs-progress {
284+
background-color: #FAFAFA;
285+
margin: 5px 20px;
286+
}
287+
.introjs-progressbar {
288+
background-color: #2980b9;
289+
}
290+
282291
.introjsFloatingElement {
283292
position: absolute;
284293
height: 0;

0 commit comments

Comments
 (0)