forked from usablica/intro.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintroJQHelper.js
46 lines (41 loc) · 2.09 KB
/
introJQHelper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//check if exists
$.fn.exists = function () {
return this.length !== 0;
};
//quick attach numbered intro text
$.fn.introText = function (t, c){
if(this.exists()){
c.val == 1 ? t=t+' (You can use the ←, →, enter or exit keys to navigate the tour.)' : 0;
this.first().attr('data-intro',t);
this.first().attr('data-step',c.val);
this.first().attr('data-intro-text',t); //if using the intro.js on this git
this.first().attr('data-intro-step',c.val); // if using the intro.js on this git
c.val++;
return true;
}
return false;
};
//Start intro click (just set class introStart on a clickable element)
$('.introStart').click(function(){
//c is an object so it can be passed by memory reference
var c = new Object({val: 1});
/* attach objects you want a tour on like this
$('div').introText('This is a Div',c); // step 1
$('span').introText('This is a span',c); // step 2
this can be done outside of the .click function
make sure if you do this elsewhere you declare c as an object as seen above
personally I like it here because it doesn't get loaded into the DOM unless needed (when clicked)
*/
var nextPage = $(this).attr('data-intro-next-href'); //a valid href for next page does not validate
var nextSection = $(this).attr('data-intro-next-section'); //the selector designated by data-intro-next-section kinda works, seems clunky
var section = $(this).attr('data-intro-section'); //the selector designated by data-intro-section
if(nextPage){
//Arbitrarily decided next page is only on whole page intros, and will not do a section intro if section is set
introJs().setOption('doneLabel','Next Page').start().oncomplete(function(){ window.location.href=nextPage });
}else if($(nextSection).exists()){
//this works but is wonky
$(section).exists() ? introJs(section).setOption('doneLabel','Next Section').start().oncomplete(function(){ introJs(nextSection).start() }) : introJs().setOption('doneLabel','Next Section').start().oncomplete(function(){ introJs(nextSection).start() });
}else{
$(section).exists() ? introJs(section).start() : introJs().start();
}
});