Skip to content

Commit 5ddb3fe

Browse files
committed
Add an example tour using Shepherd.js
Adds an example tour using Shepherd.js and FloatingUI, to test out the capabilities of Shepherd.js. The content and coding is just for testing: in no way final! For Shepherd.js, see: https://shepherdjs.dev/ Contributes to #535.
1 parent 3075030 commit 5ddb3fe

File tree

4 files changed

+257
-16
lines changed

4 files changed

+257
-16
lines changed

server/apps/main/templates/main/home.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
{% block content %}
88

9+
<script type="module" src="{% static 'js/tour.js' %}"></script>
10+
911
<!--Navigation-->
1012
<section id="title">
1113
<!-- Navigation-->
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
22
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
33
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
4+
<script src="https://cdn.jsdelivr.net/npm/shepherd.js@11.1.1/dist/js/shepherd.min.js"></script>
5+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/shepherd.js@11.1.1/dist/css/shepherd.css"/>

server/apps/main/templates/main/partials/navigation.html

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,65 +11,65 @@
1111
<div class="collapse navbar-collapse" id="navbarText">
1212
<ul class="navbar-nav mr-auto mt-2 mt-lg-0">
1313
<li>
14-
<a class="nav-content nav-item nav-link" href="{% url 'main:what_autism_is' %}">What is Autism</a>
14+
<a class="nav-content nav-item nav-link" id="nav-what-is-autism" href="{% url 'main:what_autism_is' %}">What is Autism</a>
1515
</li>
1616
{% if user.is_authenticated %}
17-
<li class="nav-item dropdown nav-nopadding">
17+
<li class="nav-item dropdown nav-nopadding" id="nav-experiences">
1818
<a class="nav-link dropdown-toggle nav-content" href="#" id="experienceDropdownMenuLink" role="button"
1919
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
2020
Experiences
2121
</a>
2222
<div class="dropdown-menu" aria-labelledby="experienceDropdownMenuLink">
23-
<a class="dropdown-item" href="{% url 'main:public_experiences' %}">View Stories</a>
24-
<a class="dropdown-item" href="{% url 'main:share_exp' %}">Share Stories</a>
23+
<a class="dropdown-item" id="nav-experiences-view" href="{% url 'main:public_experiences' %}">View Stories</a>
24+
<a class="dropdown-item" id="nav-experiences-share" href="{% url 'main:share_exp' %}">Share Stories</a>
2525
</div>
2626
</li>
2727
{% is_moderator user as moderator %}
2828
{% if moderator %}
2929
<li class="nav-item dropdown nav-nopadding">
30-
<a class="nav-link dropdown-toggle nav-content" href="#" id="navbarDropdownMenuLink" role="button"
30+
<a class="nav-link dropdown-toggle nav-content" id="nav-moderation" href="#" id="navbarDropdownMenuLink" role="button"
3131
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
3232
Moderation
3333
</a>
3434
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
35-
<a class="dropdown-item" href="{% url 'main:moderation_list' %}?status=pending">Pending</a>
36-
<a class="dropdown-item" href="{% url 'main:moderation_list' %}?status=approved">Approved</a>
37-
<a class="dropdown-item" href="{% url 'main:moderation_list' %}?status=rejected">Rejected</a>
35+
<a class="dropdown-item" id="nav-moderation-pending" href="{% url 'main:moderation_list' %}?status=pending">Pending</a>
36+
<a class="dropdown-item" id="nav-moderation-approved" href="{% url 'main:moderation_list' %}?status=approved">Approved</a>
37+
<a class="dropdown-item" id="nav-moderation-rejected" href="{% url 'main:moderation_list' %}?status=rejected">Rejected</a>
3838
</div>
3939
</li>
4040

4141
{% endif %}
4242
<li>
43-
<a class="nav-content nav-item nav-link" href="{% url 'main:my_stories' %}">My Stories</a>
43+
<a class="nav-content nav-item nav-link" id="nav-my-stories" href="{% url 'main:my_stories' %}">My Stories</a>
4444
</li>
4545
{% else %}
4646
<li>
47-
<a class="nav-content nav-item nav-link" href="{% url 'main:public_experiences' %}">View Stories</a>
47+
<a class="nav-content nav-item nav-link" id="nav-public-experiences" href="{% url 'main:public_experiences' %}">View Stories</a>
4848
</li>
4949
{% endif %}
5050
<li>
51-
<a class="nav-content nav-item nav-link" href="{% url 'main:about_us' %}">About Us</a>
51+
<a class="nav-content nav-item nav-link" id="nav-about" href="{% url 'main:about_us' %}">About Us</a>
5252
</li>
5353
<li>
54-
<a class="nav-content nav-item nav-link" href="{% url 'main:code_of_conduct' %}">Code of Conduct</a>
54+
<a class="nav-content nav-item nav-link" id="nav-coc" href="{% url 'main:code_of_conduct' %}">Code of Conduct</a>
5555
</li>
5656
<li>
57-
<a class="nav-content nav-item nav-link" href="{% url 'main:help' %}">Help</a>
57+
<a class="nav-content nav-item nav-link" id="nav-help" href="{% url 'main:help' %}">Help</a>
5858
</li>
5959
</ul>
6060

6161

6262

6363
{% if user.is_authenticated %}
6464
<ul class="navbar-nav nav-right">
65-
<li class="nav-item dropdown nav-nopadding">
65+
<li class="nav-item dropdown nav-nopadding" id="nav-account">
6666
<a class="nav-link dropdown-toggle nav-content nav-account" href="#" id="accountDropdownMenuLink" role="button"
6767
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
6868
Account
6969
</a>
7070
<div class="dropdown-menu" aria-labelledby="accountDropdownMenuLink">
71-
<a class="dropdown-item" href="{% url 'users:profile' %}">Profile</a>
72-
<form class="form-inline nav-nomargin" action="{% url 'main:logout' %}" method="post">
71+
<a class="dropdown-item" id="nav-account-profile" href="{% url 'users:profile' %}">Profile</a>
72+
<form class="form-inline nav-nomargin" id="nav-account-logout" action="{% url 'main:logout' %}" method="post">
7373
{% csrf_token %}
7474
<button class="dropdown-item" type="submit">Log out</button>
7575
</form>

static/js/tour.js

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
import {offset} from 'https://cdn.jsdelivr.net/npm/@floating-ui/dom@1.5.0/+esm';
2+
3+
$(function () {
4+
// Set a few things up
5+
$('.dropdown').on('hide.bs.dropdown', function(e) {
6+
return !!$(this).data('closable');
7+
}).data('closable', true);
8+
9+
function setClosable(selector, closable) {
10+
return $(selector).data('closable', closable);
11+
}
12+
13+
function openDropdown(selector) {
14+
let element = $(selector)
15+
if (!element.hasClass("show")) {
16+
element.find('.dropdown-toggle').dropdown('toggle');
17+
}
18+
return element;
19+
}
20+
21+
// Initialise the tour
22+
const tour = new Shepherd.Tour({
23+
useModalOverlay: true,
24+
defaultStepOptions: {
25+
scrollTo: {
26+
behavior: 'smooth',
27+
block: 'center'
28+
},
29+
modalOverlayOpeningPadding: 2,
30+
modalOverlayOpeningRadius: 16,
31+
floatingUIOptions: { middleware: [offset({ mainAxis: 20, crossAxis: 0 })] }
32+
}
33+
});
34+
35+
// Add a tour step
36+
tour.addStep({
37+
id: 'welcome',
38+
text: 'Welcome ot the AutSPACEs platform!<br/></br>Would you like to take a tour?',
39+
buttons: [
40+
{
41+
text: 'No thank you',
42+
action: tour.complete
43+
},
44+
{
45+
text: 'Yes, let\'s go!',
46+
action: tour.next
47+
}
48+
]
49+
});
50+
51+
// Add a tour step
52+
tour.addStep({
53+
id: 'explanation',
54+
text: 'AutSPACEs is all about providing a platform for autistic people to share stories.',
55+
attachTo: {
56+
element: '.title-text',
57+
on: 'bottom'
58+
},
59+
buttons: [
60+
{
61+
text: 'Back',
62+
action: tour.back
63+
},
64+
{
65+
text: 'Next',
66+
action: tour.next
67+
}
68+
]
69+
});
70+
71+
// Add a tour step
72+
tour.addStep({
73+
id: 'code-of-conduct',
74+
text: 'Before submitting a story, please make sure you read our Code of Conduct carefully. It will only take a few minutes. Once you\'ve read it, press your browser\'s \`back\` button to return to this tour.',
75+
attachTo: {
76+
element: '#nav-coc',
77+
on: 'bottom'
78+
},
79+
buttons: [
80+
{
81+
text: 'Back',
82+
action: tour.back
83+
},
84+
{
85+
text: 'Next',
86+
action: tour.next
87+
}
88+
]
89+
});
90+
91+
// Add a tour step
92+
tour.addStep({
93+
id: 'experiences',
94+
text: 'A good place to start is by reading others\'s stories to get an idea of what\'s already here. Select the \'Experiences\' item now to open the experiences submienu.',
95+
attachTo: {
96+
element: '#nav-experiences',
97+
on: 'right-start'
98+
},
99+
advanceOn: {
100+
selector: '#experienceDropdownMenuLink',
101+
event: 'click'
102+
},
103+
buttons: [
104+
{
105+
text: 'Back',
106+
action: tour.back
107+
},
108+
{
109+
text: 'Next',
110+
action: tour.next
111+
}
112+
]
113+
});
114+
115+
// Add a tour step
116+
tour.addStep({
117+
id: 'view',
118+
text: 'A good place to start is by reading others\'s stories to get an idea of what\'s already here. Select the \'View Stories\' option under the \'Experiences\' item to check them out.',
119+
attachTo: {
120+
element: '#nav-experiences-view',
121+
on: 'right-start',
122+
},
123+
when: {
124+
"before-show": function() {
125+
setClosable('#nav-experiences', false);
126+
openDropdown('#nav-experiences');
127+
},
128+
"before-hide": function() {
129+
setClosable('#nav-experiences', true);
130+
}
131+
},
132+
buttons: [
133+
{
134+
text: 'Back',
135+
action: tour.back
136+
},
137+
{
138+
text: 'Next',
139+
action: tour.next
140+
}
141+
]
142+
});
143+
144+
// Add a tour step
145+
tour.addStep({
146+
id: 'account',
147+
text: 'Before you submit your first experience, please take the time to fill out your details in the user profile. To open your profile select the Account menu.',
148+
attachTo: {
149+
element: '#nav-account',
150+
on: 'left-start'
151+
},
152+
advanceOn: {
153+
selector: '#accountDropdownMenuLink',
154+
event: 'click'
155+
},
156+
buttons: [
157+
{
158+
text: 'Back',
159+
action: tour.back
160+
},
161+
{
162+
text: 'Next',
163+
action: tour.next
164+
}
165+
]
166+
});
167+
168+
// Add a tour step
169+
tour.addStep({
170+
id: 'profile',
171+
text: 'Select the profile menu entry to view and edit your profile.',
172+
attachTo: {
173+
element: '#nav-account-profile',
174+
on: 'left-start',
175+
},
176+
when: {
177+
"before-show": function() {
178+
setClosable('#nav-account', false);
179+
openDropdown('#nav-account');
180+
},
181+
"before-hide": function() {
182+
setClosable('#nav-account', true);
183+
}
184+
},
185+
buttons: [
186+
{
187+
text: 'Back',
188+
action: tour.back
189+
},
190+
{
191+
text: 'Next',
192+
action: tour.next
193+
}
194+
]
195+
});
196+
197+
// Add a tour step
198+
tour.addStep({
199+
id: 'get-involved',
200+
text: 'AutSPACEs is co-developed with our community. We\'d love for you to be involved too. Whatever your skills we can use them, from research to design to documentation to development to discussion. Find out more here.',
201+
attachTo: {
202+
element: '#cta',
203+
on: 'top'
204+
},
205+
buttons: [
206+
{
207+
text: 'Back',
208+
action: tour.back
209+
},
210+
{
211+
text: 'Next',
212+
action: tour.next
213+
}
214+
]
215+
});
216+
217+
// Add a tour step
218+
tour.addStep({
219+
id: 'finish',
220+
text: 'That\s it! We hope you find the AutSPACEs platform useful and we look forward to helping share your experiences.',
221+
buttons: [
222+
{
223+
text: 'Back',
224+
action: tour.back
225+
},
226+
{
227+
text: 'Finish',
228+
action: tour.complete
229+
}
230+
]
231+
});
232+
233+
// Start the fans please!
234+
tour.start();
235+
});
236+
237+

0 commit comments

Comments
 (0)