forked from github/training-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurriculum.js
263 lines (214 loc) · 6.68 KB
/
curriculum.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
$(function(){
// Hide Quizzes and Polls
$(".quiz").hide();
$(".poll").hide();
// Bind checkbox/label click for slide toggle
$("#slide-only-toggle").change(function(){
$(".materials > *").not(".slide").toggleClass("hidden");
$(".lab").toggleClass("hidden");
});
// Parse username from querystring
var urlSearch = window.location.search,
teacherQuery = urlSearch.match(/teacher=[a-z,A-Z,0-9]*/),
username;
if(teacherQuery && teacherQuery.length == 1){
username = teacherQuery[0].substring(8, teacherQuery[0].length);
$.ajax(
{
url: "https://api.github.com/users/"+username,
success: function(data, textStatus, jqXHR){
$("#teachername").text(data.name);
$("<span/>",
{
text: data.login
}).appendTo("#teacherusername");
// Profile email
if(data.email){
$("<span/>",
{
text: data.email
}).appendTo("#teacheremail");
}
else{
$("#teacheremail").toggleClass("hidden");
}
// Profile company
if(data.company){
$("<span/>",
{
text: data.company
}).appendTo("#teacherorganization");
}
else{
$("#teacherorganization").toggleClass("hidden");
}
// Profile location
if(data.location){
$("<span/>",
{
text: data.location
}).appendTo("#teacherlocation");
}
else{
$("#teacherlocation").toggleClass("hidden");
}
$("<img/>",
{
src: data.avatar_url,
class: "img-circle img-thumbnail"
}).appendTo("#teacheravatar");
$("<span/>",
{
text: data.public_repos,
class: "badge"
}).appendTo("#teacherrepo");
$("<span/>",
{
text: data.followers,
class: "badge"
}).appendTo("#teacherfollowers");
$("<span/>",
{
text: data.following,
class: "badge"
}).appendTo("#teacherfollowing");
$("#teacher").toggleClass("hidden");
// Toggle material when self-taught
$("div.video").toggleClass("hidden");
updateSlideSize();
}
});
}
// Bind checkbox toggle for TOC
var shortcuts = {};
shortcuts.toggle = function(event){
console.log(event.keyCode);
// Help "?" toggle
if(event.shiftKey && event.keyCode === 191){
$('#help').modal('toggle');
}
// TOC "T" toggle
else if(event.shiftKey && event.keyCode === 84){
$(".col-content").toggleClass("shift-left");
$(".col-toc").toggleClass("shift-left");
}
}
document.addEventListener("keydown", shortcuts.toggle, false);
// Conditionally Render the TOC
// List of Legacy Classes
var legacyClasses = ["GitHub Foundations", "GitHub Intermediate", "GitHub Advanced"];
// Get the current class title
var classTitle = $("header.colorful > div.container > h2").html();
// If the current class is not in the list of legacy classes, hide the TOC
// Otherwise render it out.
if ($.inArray(classTitle, legacyClasses) == -1) {
$(".module-toc").hide();
}
else {
buildToc();
}
// Reframe slides on any window resize
$(window).resize(function () {
updateSlideSize();
});
// Ensure slide scale at start
updateSlideSize();
// Startup slide scrollsnap watching
$(document).scrollsnap({
snaps: '.slide',
proximity: 100
});
function updateSlideSize(){
var h = window.innerHeight,
even = $("hr:even");
even.each(function(index){
$(this).nextUntil("hr").wrapAll("<div class='slide'><div class='alignment'></div></div>");
});
$(".slide").css("height", h + "px");
}
//Time toggle keybinding
var Timer = (function() {
// this stores target time on window.countDownTo
function now() { return new Date().getTime() }
function bareCallback(aTimer) {
var delta = window.countDownTo.getTime() - now()
var timeLeft = delta > 0
var noTimeLeft = !(timeLeft)
if (noTimeLeft) {
aTimer.clearTimer()
return
}
var min_float = delta / 1000 / 60
var minutes = Math.floor(min_float)
var seconds = Math.floor((min_float - minutes) * 60)
if (minutes < 10) { minutes = "0" + minutes }
if (seconds < 10) { seconds = "0" + seconds}
aTimer.shouldDisplay(minutes + ":" + seconds)
}
var Timer = function(display) {
var aTimer = this
this.display = display
this.callback = function() { bareCallback(aTimer) }
}
Timer.prototype.blankSlate = function() {
this.clearTimer("")
}
Timer.prototype.clearTimer = function(textToShow) {
textToShow = typeof textToShow !== 'undefined' ? textToShow : "00:00"
this.shouldDisplay(textToShow)
window.countDownTo = 0
if (window.counter) { window.clearInterval(window.counter) }
}
Timer.prototype.shouldDisplay = function(text) {
this.display.text(text)
}
Timer.prototype.startCountdown = function(durationInMinutes) {
// timer so that every second, update displayed time
var countDownTo = new Date(now() + (1000 * 60 * durationInMinutes))
window.countDownTo = countDownTo
this.callback()
window.counter = setInterval(this.callback, 1000 * 1)
}
return Timer;
})()
//receive parameter for counttime
var timer = new Timer($("#time-left"));
$('.timer-label').click(function(e) {
e.preventDefault()
timer.blankSlate()
$("#start-stop").show();
$(".time-amount").show();
})
$('#timerForm').submit(function(e) {
e.preventDefault()
$(".time-amount").hide();
var duration = $('#minutes').val()
timer.startCountdown(duration)
})
// Table of Contents header parsing and builder
function buildToc(){
var headings = $(".deck h2"),
toc = $("#toc-list");
for(var h=0; h<headings.length; h++){
var item,
headingOrig;
headingOrig = headings[h].textContent.toLowerCase().replace(/&\s/, "").split(" ");
var headingSep = "";
for(var o=0;o<headingOrig.length;o++){
if(o > 0 && 0 < headingOrig.length){
headingSep += "-";
}
headingSep = headingSep + headingOrig[o]
}
item = $('<li><a href="#' + headingSep + '">' + headings[h].innerHTML + '</a></li>');
toc.append(item);
if(headings[h].parentElement.getAttribute("class").indexOf("alignment")>-1){
headings[h].parentElement.setAttribute("id", headingSep);
}
else{
headings[h].setAttribute("id", headingSep);
}
$('.deck').scrollspy({ target: '#toc' });
}
}
});