Skip to content

Commit 4cd2e24

Browse files
author
Jordan McCullough
committed
Merge pull request #255 from github/deck-framework-update
Support full-width slide, updated TOC controls
2 parents 52615fe + b234ab0 commit 4cd2e24

File tree

4 files changed

+6146
-630
lines changed

4 files changed

+6146
-630
lines changed

_javascript/curriculum.js

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

0 commit comments

Comments
 (0)