Skip to content

Commit 52615fe

Browse files
author
Jordan McCullough
committed
Merge pull request #249 from github/curriculum-controls-fixes
Update and fix timer, timer toggle control
2 parents 8f5b79c + 90df212 commit 52615fe

File tree

4 files changed

+272
-205
lines changed

4 files changed

+272
-205
lines changed

_javascript/curriculum.js

Lines changed: 190 additions & 184 deletions
Original file line numberDiff line numberDiff line change
@@ -1,186 +1,192 @@
11
$(function(){
2-
var timeLeftInterval = 0;
3-
4-
// Bind checkbox/label click for slide toggle
5-
$("#slide-only-toggle").change(function(){
6-
var checkState = $("#slide-only-toggle").attr("checked");
7-
$(".materials > *").toggleClass("hidden");
8-
$(".slide").toggleClass("hidden");
9-
});
10-
11-
12-
// Parse username from querystring
13-
var urlSearch = window.location.search,
14-
teacherQuery = urlSearch.match(/teacher=[a-z,A-Z,0-9]*/),
15-
username;
16-
17-
if(teacherQuery && teacherQuery.length == 1){
18-
username = teacherQuery[0].substring(8, teacherQuery[0].length);
19-
20-
console.log(username);
21-
22-
$.ajax(
23-
{
24-
url: "https://api.github.com/users/"+username,
25-
success: function(data, textStatus, jqXHR){
26-
27-
$("<span/>",
28-
{
29-
class: "teacher-name",
30-
text: data.name
31-
}).appendTo("#teacher-name");
32-
33-
$("<span/>",
34-
{
35-
text: data.login
36-
}).appendTo("#teacher-username");
37-
38-
// Profile email
39-
if(data.email){
40-
$("<span/>",
41-
{
42-
text: data.email
43-
}).appendTo("#teacher-email");
44-
}
45-
else{
46-
$("#teacher-email").toggleClass("hidden");
47-
}
48-
49-
// Profile company
50-
if(data.company){
51-
$("<span/>",
52-
{
53-
text: data.company
54-
}).appendTo("#teacher-organization");
55-
}
56-
else{
57-
$("#teacher-organization").toggleClass("hidden");
58-
}
59-
60-
61-
// Profile location
62-
if(data.location){
63-
$("<span/>",
64-
{
65-
text: data.location
66-
}).appendTo("#teacher-location");
67-
}
68-
else{
69-
$("#teacher-location").toggleClass("hidden");
70-
}
71-
72-
$("<img/>",
73-
{
74-
src: data.avatar_url,
75-
class: "img-circle img-thumbnail"
76-
}).appendTo("#teacher-avatar");
77-
78-
$("<span/>",
79-
{
80-
text: data.public_repos,
81-
class: "badge"
82-
}).appendTo("#teacher-repo");
83-
84-
$("<span/>",
85-
{
86-
text: data.followers,
87-
class: "badge"
88-
}).appendTo("#teacher-followers");
89-
90-
$("<span/>",
91-
{
92-
text: data.following,
93-
class: "badge"
94-
}).appendTo("#teacher-following");
95-
96-
$("#teacher").toggleClass("hidden");
97-
$("#teacher").toggleClass("slide");
98-
99-
updateSlideSize();
100-
}
101-
});
102-
}
103-
104-
// Render the TOC
105-
buildToc();
106-
// Reframe slides on any window resize
107-
$(window).resize(function () {
108-
updateSlideSize();
109-
});
110-
// Ensure slide scale at start
111-
updateSlideSize();
112-
// Startup slide scrollsnap watching
113-
$(document).scrollsnap({
114-
snaps: '.slide',
115-
proximity: 160
116-
});
117-
118-
function updateSlideSize(){
119-
var w = window.innerWidth;
120-
var h = window.innerHeight;
121-
$(".slide").css("height", h);
122-
}
123-
124-
//Time toggle keybinding
125-
$(".timer-toggle").click(function(){
126-
$(".timer-wrapper").toggleClass("fade-out");
127-
resetTimer();
128-
129-
if($(".timer-wrapper").hasClass("fade-out")){
130-
$(".timer-amount").toggle();
131-
}
132-
});
133-
$("#start-stop").click(function(){
134-
var timeLeftDisplay = $("#time-left")
135-
var min = $("#minutes").attr("value");
136-
var duration = min*60;
137-
138-
$(".timer-amount").toggle();
139-
resetTimer();
140-
timeLeftInterval = setInterval(function(){
141-
timeLeftDisplay.html( Math.floor((duration)/60) + ":" + (duration%60 < 10 ? "0"+duration%60:duration%60) );
142-
duration = --duration;
143-
144-
if(duration == -1){
145-
clearInterval(timeLeftInterval);
146-
}
147-
}, 1000);
148-
});
149-
function resetTimer(){
150-
clearInterval(timeLeftInterval);
151-
$("#time-left").html("");
152-
}
153-
154-
// Table of Contents header parsing and builder
155-
function buildToc(){
156-
var headings = $(".curriculum h2"),
157-
toc = $("#toc-list");
158-
159-
for(var h=0; h<headings.length; h++){
160-
var item,
161-
headingOrig;
162-
163-
headingOrig = headings[h].textContent.toLowerCase().replace(/&\s/, "").split(" ");
164-
165-
var headingSep = "";
166-
for(var o=0;o<headingOrig.length;o++){
167-
if(o > 0 && 0 < headingOrig.length){
168-
headingSep += "-";
169-
}
170-
headingSep = headingSep + headingOrig[o]
171-
}
172-
173-
item = $('<li><a href="#' + headingSep + '">' + headings[h].innerHTML + '</a></li>');
174-
toc.append(item);
175-
176-
if(headings[h].parentElement.getAttribute("class").indexOf("alignment")>-1){
177-
headings[h].parentElement.setAttribute("id", headingSep);
178-
}
179-
else{
180-
headings[h].setAttribute("id", headingSep);
181-
}
182-
183-
$('.curriculum').scrollspy({ target: '#toc' });
184-
}
185-
}
2+
var timeLeftInterval = 0;
3+
4+
// Bind checkbox/label click for slide toggle
5+
$("#slide-only-toggle").change(function(){
6+
var checkState = $("#slide-only-toggle").attr("checked");
7+
$(".materials > *").toggleClass("hidden");
8+
$(".slide").toggleClass("hidden");
9+
});
10+
11+
12+
// Parse username from querystring
13+
var urlSearch = window.location.search,
14+
teacherQuery = urlSearch.match(/teacher=[a-z,A-Z,0-9]*/),
15+
username;
16+
17+
if(teacherQuery && teacherQuery.length == 1){
18+
username = teacherQuery[0].substring(8, teacherQuery[0].length);
19+
20+
console.log(username);
21+
22+
$.ajax(
23+
{
24+
url: "https://api.github.com/users/"+username,
25+
success: function(data, textStatus, jqXHR){
26+
27+
$("<span/>",
28+
{
29+
class: "teacher-name",
30+
text: data.name
31+
}).appendTo("#teacher-name");
32+
33+
$("<span/>",
34+
{
35+
text: data.login
36+
}).appendTo("#teacher-username");
37+
38+
// Profile email
39+
if(data.email){
40+
$("<span/>",
41+
{
42+
text: data.email
43+
}).appendTo("#teacher-email");
44+
}
45+
else{
46+
$("#teacher-email").toggleClass("hidden");
47+
}
48+
49+
// Profile company
50+
if(data.company){
51+
$("<span/>",
52+
{
53+
text: data.company
54+
}).appendTo("#teacher-organization");
55+
}
56+
else{
57+
$("#teacher-organization").toggleClass("hidden");
58+
}
59+
60+
61+
// Profile location
62+
if(data.location){
63+
$("<span/>",
64+
{
65+
text: data.location
66+
}).appendTo("#teacher-location");
67+
}
68+
else{
69+
$("#teacher-location").toggleClass("hidden");
70+
}
71+
72+
$("<img/>",
73+
{
74+
src: data.avatar_url,
75+
class: "img-circle img-thumbnail"
76+
}).appendTo("#teacher-avatar");
77+
78+
$("<span/>",
79+
{
80+
text: data.public_repos,
81+
class: "badge"
82+
}).appendTo("#teacher-repo");
83+
84+
$("<span/>",
85+
{
86+
text: data.followers,
87+
class: "badge"
88+
}).appendTo("#teacher-followers");
89+
90+
$("<span/>",
91+
{
92+
text: data.following,
93+
class: "badge"
94+
}).appendTo("#teacher-following");
95+
96+
$("#teacher").toggleClass("hidden");
97+
$("#teacher").toggleClass("slide");
98+
99+
updateSlideSize();
100+
}
101+
});
102+
}
103+
104+
// Render the TOC
105+
buildToc();
106+
// Reframe slides on any window resize
107+
$(window).resize(function () {
108+
updateSlideSize();
109+
});
110+
// Ensure slide scale at start
111+
updateSlideSize();
112+
// Startup slide scrollsnap watching
113+
$(document).scrollsnap({
114+
snaps: '.slide',
115+
proximity: 160
116+
});
117+
118+
function updateSlideSize(){
119+
var w = window.innerWidth;
120+
var h = window.innerHeight;
121+
$(".slide").css("height", h);
122+
}
123+
124+
//Time toggle keybinding
125+
$(".timer-label").click(function(){
126+
$(".timer-wrapper").toggleClass("fade-out");
127+
$(".timer-amount").show();
128+
resetTimer();
129+
});
130+
$(".timer-exit").click(function(){
131+
$(".timer-wrapper").toggleClass("fade-out");
132+
$("#timer-check").removeAttr("checked");
133+
// $(".timer-amount").();
134+
resetTimer();
135+
});
136+
$("#start-stop").click(function(){
137+
var timeLeftDisplay = $("#time-left")
138+
var min = $("#minutes").attr("value");
139+
var duration = min*60;
140+
141+
resetTimer();
142+
143+
$(".timer-amount").hide();
144+
145+
timeLeftInterval = setInterval(function(){
146+
timeLeftDisplay.html( Math.floor((duration)/60) + ":" + (duration%60 < 10 ? "0"+duration%60:duration%60) );
147+
duration = --duration;
148+
149+
if(duration == -1){
150+
clearInterval(timeLeftInterval);
151+
}
152+
}, 1000);
153+
});
154+
function resetTimer(){
155+
clearInterval(timeLeftInterval);
156+
$("#time-left").html("");
157+
}
158+
159+
160+
// Table of Contents header parsing and builder
161+
function buildToc(){
162+
var headings = $(".curriculum h2"),
163+
toc = $("#toc-list");
164+
165+
for(var h=0; h<headings.length; h++){
166+
var item,
167+
headingOrig;
168+
169+
headingOrig = headings[h].textContent.toLowerCase().replace(/&\s/, "").split(" ");
170+
171+
var headingSep = "";
172+
for(var o=0;o<headingOrig.length;o++){
173+
if(o > 0 && 0 < headingOrig.length){
174+
headingSep += "-";
175+
}
176+
headingSep = headingSep + headingOrig[o]
177+
}
178+
179+
item = $('<li><a href="#' + headingSep + '">' + headings[h].innerHTML + '</a></li>');
180+
toc.append(item);
181+
182+
if(headings[h].parentElement.getAttribute("class").indexOf("alignment")>-1){
183+
headings[h].parentElement.setAttribute("id", headingSep);
184+
}
185+
else{
186+
headings[h].setAttribute("id", headingSep);
187+
}
188+
189+
$('.curriculum').scrollspy({ target: '#toc' });
190+
}
191+
}
186192
});

0 commit comments

Comments
 (0)