-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
tour_3.7.js
185 lines (155 loc) · 5.89 KB
/
tour_3.7.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// Enable you to create an HTML Popup startup
function htmlPopup(tour) {
var html = '';
var title = 'My popup';
var content = 'The content of the popup.'
// Header
html += '<div class="modal-header" style="background-color:rgba(0, 0, 0, 0.7);">';
html += '<h3 style="color:white;">' + title + '</h3></div>';
// Main content : body
html += '<div class="modal-body">';
html += '<p>' + content + '</p>';
// Project Metadata
html += $('#metadata').html();
// End of main content body
html += '</div>';
// Footer
html += '<div class="modal-footer" style="background-color:rgba(0, 0, 0, 0.7);"></div>';
// Return shepherd
return {
id: 'Popup Startup',
text: html,
attachTo: {
element: 'body',
},
buttons: [{ text: 'See tutorial', action: tour.next }],
}
}
// Check the browser's localstorage
function dismissTour() {
if (!localStorage.getItem('shepherd-tour')) {
localStorage.setItem('shepherd-tour', 'yes');
}
}
// Start the tutorial
function startTutorial() {
// Create a tour
const tour = new Shepherd.Tour({
useModalOverlay: true,
defaultStepOptions: {
classes: 'shepherd-theme-custom',
scrollTo: true,
cancelIcon: { enabled: true },
keyboardNavigation: true,
exitOnEsc: true,
when: {
show() {
// Don't show the progress bar on first and final step
if (tour.steps.indexOf(tour.currentStep) != 0 && tour.steps.indexOf(tour.currentStep) != tour.steps.length - 1) {
const currentStepElement = tour.currentStep.el;
const header = currentStepElement.querySelector('.shepherd-footer');
const progress = document.createElement('div');
const innerBar = document.createElement('span');
const progressPercentage = ((tour.steps.indexOf(tour.currentStep) + 1) / tour.steps.length) * 100 + '%';
progress.className = 'shepherd-progress-bar';
innerBar.style.width = progressPercentage;
progress.style.minWidth = '10px';
progress.appendChild(innerBar);
header.insertBefore(progress, currentStepElement.querySelector('.shepherd-button'));
}
}
}
},
});
tour.addStep(htmlPopup(tour));
// Add automatic tour steps
const tourSteps = $('.nav.nav-list li').filter(function () {
return this.style.display !== 'none' && !this.classList.contains('hide');
}).map(function (index, element) {
const aElement = $(element).find('a')[0];
return {
id: `Step ${index + 1}`,
title: `Step ${index + 1}`,
text: $(aElement).attr('data-original-title'),
attachTo: {
element: aElement,
on: 'right',
},
buttons: [{ text: 'Previous', action: tour.back }, { text: 'Next', action: tour.next }],
};
}
).get();
// Add 3 more personal tour steps
const stepHappyCoding = [
{
id: 'move-map',
title: 'Move the map',
text: 'Move the map',
attachTo: {
element: 'span#navbar',
on: 'left',
},
buttons: [{ text: 'Previous', action: tour.back }, { text: 'Next', action: tour.next }],
},
{
id: 'overview',
title: 'Overview box',
text: 'Overview box',
attachTo: {
element: '#overview-box',
on: 'top',
},
buttons: [{ text: 'Previous', action: tour.back }, { text: 'Next', action: tour.next }],
},
{
id: 'happy-coding',
title: 'Happy Coding',
text: 'And that is all, go ahead and start adding tours to your applications.',
attachTo: {
element: 'body',
},
buttons: [
{ text: 'Previous', action: tour.back },
{
text: 'Finish',
action() {
// Dismiss the tour when the finish button is clicked
dismissTour();
return this.hide();
}
}],
}
];
// Spread the steps into the tour array
tourSteps.push(...stepHappyCoding);
tour.addSteps(tourSteps);
// Return the
return tour;
}
lizMap.events.on({
uicreated: function () {
// Include the CSS CDN of shepherd
var link = document.createElement('link');
link.href = 'https://cdn.jsdelivr.net/npm/[email protected]/dist/css/shepherd.css';
link.rel = 'stylesheet';
document.head.appendChild(link);
// Include the JS CDN of shepherd
var script = document.createElement('script');
script.src = 'https://cdn.jsdelivr.net/npm/[email protected]/dist/js/shepherd.min.js';
script.type = 'text/javascript';
script.onload = function () {
console.log('Shepherd.js has been loaded successfully!');
const tour = startTutorial();
// Dismiss the tour when the cancel icon is clicked
tour.on('cancel', dismissTour);
// Start the tour
if (!localStorage.getItem('shepherd-tour')) {
tour.start();
}
};
script.onerror = function () {
console.error('Error when loading shepherd.js');
};
document.head.appendChild(script);
}
});