Skip to content

Commit 32d8304

Browse files
committed
Add custom css class for tooltips + complete examples
1 parent 4a36819 commit 32d8304

File tree

3 files changed

+112
-3
lines changed

3 files changed

+112
-3
lines changed

example/custom-class/index.html

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Custom CSS Class</title>
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<meta name="description" content="Intro.js - Better introductions for websites and features with a step-by-step guide for your projects.">
8+
<meta name="author" content="Afshin Mehrabani (@afshinmeh) in usabli.ca group">
9+
10+
<!-- styles -->
11+
<link href="../assets/css/bootstrap.min.css" rel="stylesheet">
12+
<link href="../assets/css/demo.css" rel="stylesheet">
13+
14+
<!-- Add IntroJs styles -->
15+
<link href="../../introjs.css" rel="stylesheet">
16+
17+
<link href="../assets/css/bootstrap-responsive.min.css" rel="stylesheet">
18+
<style>
19+
.forLastStep {
20+
font-weight: bold;
21+
}
22+
.customDefault {
23+
color: gray;
24+
}
25+
.customDefault .introjs-skipbutton {
26+
border-radius: 0;
27+
color: red;
28+
}
29+
</style>
30+
</head>
31+
32+
<body>
33+
34+
<div class="container-narrow">
35+
36+
<div class="masthead">
37+
<ul class="nav nav-pills pull-right" data-step="5" data-tooltipClass='forLastStep' data-intro="Get it, use it.">
38+
<li><a href="https://github.com/usablica/intro.js/tags"><i class='icon-black icon-download-alt'></i> Download</a></li>
39+
<li><a href="https://github.com/usablica/intro.js">Github</a></li>
40+
<li><a href="https://twitter.com/usablica">@usablica</a></li>
41+
</ul>
42+
<h3 class="muted">Intro.js</h3>
43+
</div>
44+
45+
<hr>
46+
47+
<div class="jumbotron">
48+
<h1 data-step="1" data-intro="This is a tooltip!">Custom Class</h1>
49+
<p class="lead" data-step="4" data-intro="Another step.">Add custom CSS class to tooltip boxes using <code>data-tooltipClass</code> attribute and <code>tooltipClass</code> option.</p>
50+
<a class="btn btn-large btn-success" href="javascript:void(0);" onclick="javascript:introJs().setOption('tooltipClass', 'customDefault').start();">Show me how</a>
51+
</div>
52+
53+
<hr>
54+
55+
<div class="row-fluid marketing">
56+
<div class="span6" data-step="2" data-intro="Ok, wasn't that fun?" data-position='right'>
57+
<h4>Section One</h4>
58+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis mollis augue a neque cursus ac blandit orci faucibus. Phasellus nec metus purus.</p>
59+
60+
<h4>Section Two</h4>
61+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis mollis augue a neque cursus ac blandit orci faucibus. Phasellus nec metus purus.</p>
62+
63+
<h4>Section Three</h4>
64+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis mollis augue a neque cursus ac blandit orci faucibus. Phasellus nec metus purus.</p>
65+
</div>
66+
67+
<div class="span6" data-step="3" data-intro="More features, more fun." data-position='left'>
68+
<h4>Section Four</h4>
69+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis mollis augue a neque cursus ac blandit orci faucibus. Phasellus nec metus purus.</p>
70+
71+
<h4>Section Five</h4>
72+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis mollis augue a neque cursus ac blandit orci faucibus. Phasellus nec metus purus.</p>
73+
74+
<h4>Section Six</h4>
75+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis mollis augue a neque cursus ac blandit orci faucibus. Phasellus nec metus purus.</p>
76+
77+
</div>
78+
</div>
79+
80+
<hr>
81+
</div>
82+
<script type="text/javascript" src="../../intro.js"></script>
83+
</body>
84+
</html>

example/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ <h3 class="muted">Examples</h3>
2626
<li><a href="multi-page/index.html" title='Multi-Page introduction'>Multi-Page introduction</a></li>
2727
<li><a href="RTL/index.html" title='RTL version'>RTL version</a></li>
2828
<li><a href="html-tooltip/index.html" title='HTML in tooltip'>HTML in tooltip</a></li>
29+
<li><a href="custom-class/index.html" title='Custom CSS Class'>Custom CSS Class</a></li>
2930
</ul>
3031
</div>
3132
</body>

intro.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,23 @@
3030
this._targetElement = obj;
3131

3232
this._options = {
33+
/* Next button label in tooltip box */
3334
nextLabel: 'Next &rarr;',
35+
/* Previous button label in tooltip box */
3436
prevLabel: '&larr; Back',
37+
/* Skip button label in tooltip box */
3538
skipLabel: 'Skip',
39+
/* Done button label in tooltip box */
3640
doneLabel: 'Done',
41+
/* Default tooltip box position */
3742
tooltipPosition: 'bottom',
43+
/* Next CSS class for tooltip boxes */
44+
tooltipClass: '',
45+
/* Close introduction when pressing Escape button? */
3846
exitOnEsc: true,
47+
/* Close introduction when clicking on overlay layer? */
3948
exitOnOverlayClick: true,
49+
/* Show step numbers in introduction? */
4050
showStepNumbers: true
4151
};
4252
}
@@ -84,6 +94,7 @@
8494
element: currentElement,
8595
intro: currentElement.getAttribute('data-intro'),
8696
step: parseInt(currentElement.getAttribute('data-step'), 10),
97+
tooltipClass: currentElement.getAttribute('data-tooltipClass'),
8798
position: currentElement.getAttribute('data-position') || this._options.tooltipPosition
8899
});
89100
}
@@ -271,6 +282,21 @@
271282
//prevent error when `this._currentStep` is undefined
272283
if(!this._introItems[this._currentStep]) return;
273284

285+
var tooltipCssClass = '';
286+
287+
//if we have a custom css class for each step
288+
var currentStepObj = this._introItems[this._currentStep];
289+
if (typeof (currentStepObj.tooltipClass) === 'string') {
290+
tooltipCssClass = currentStepObj.tooltipClass;
291+
} else {
292+
tooltipCssClass = this._options.tooltipClass;
293+
}
294+
295+
tooltipLayer.className = ('introjs-tooltip ' + tooltipCssClass).replace(/^\s+|\s+$/g, '');
296+
297+
//custom css class for tooltip boxes
298+
var tooltipCssClass = this._options.tooltipClass;
299+
274300
var currentTooltipPosition = this._introItems[this._currentStep].position;
275301
switch (currentTooltipPosition) {
276302
case 'top':
@@ -329,7 +355,7 @@
329355
if (typeof (this._introChangeCallback) !== 'undefined') {
330356
this._introChangeCallback.call(this, targetElement.element);
331357
}
332-
358+
333359
var self = this,
334360
oldHelperLayer = document.querySelector('.introjs-helperLayer'),
335361
elementPosition = _getOffset(targetElement.element);
@@ -391,9 +417,7 @@
391417
this._targetElement.appendChild(helperLayer);
392418

393419
arrowLayer.className = 'introjs-arrow';
394-
tooltipLayer.className = 'introjs-tooltip';
395420

396-
397421
tooltipLayer.innerHTML = '<div class="introjs-tooltiptext">' +
398422
targetElement.intro +
399423
'</div><div class="introjs-tooltipbuttons"></div>';

0 commit comments

Comments
 (0)