Skip to content

Commit a739881

Browse files
committed
Fixed events section for ClayHack
1 parent bb1f889 commit a739881

File tree

2 files changed

+96
-1
lines changed

2 files changed

+96
-1
lines changed

_includes/clayhack/foot.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
</footer>
66
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
77
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.3/moment.min.js"></script>
8-
<script type="text/javascript" src="/assets/scripts/main.js"></script>
8+
<script type="text/javascript" src="/assets/scripts/main_clayhack.js"></script>
99
<script>function GAPILoad(){Events.init();}</script>
1010
<script src="https://apis.google.com/js/client.js?onload=GAPILoad"></script>

assets/scripts/main_clayhack.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
$(document).ready(function () {
2+
3+
$('.scroll-to').on('click', function (e) {
4+
e.preventDefault();
5+
var id = $(e.currentTarget).attr('href')
6+
var target = $(id);
7+
$('html,body').animate({
8+
scrollTop: (target.offset().top)
9+
}, 1000);
10+
});
11+
12+
});
13+
14+
var Events = {
15+
init : function () {
16+
gapi.client.setApiKey('AIzaSyBEpd5MquuZ4r1msmMI8L6i-Z-iQuiKMYI');
17+
gapi.client.request({
18+
'path' : '/calendar/v3/calendars/clayhack.public@gmail.com/events',
19+
'callback' : Events.displayEvents,
20+
'orderBy' : 'startTime',
21+
'params' : {
22+
'timeMin': (new Date()).toISOString(),
23+
},
24+
'singleEvents' : true
25+
});
26+
},
27+
showEventPage : function (id) {
28+
$('.event-page').hide();
29+
$('.event-page[data-event-page=' + id + ']').show();
30+
},
31+
changeEventPage : function (e) {
32+
var $target = $(e.target);
33+
Events.showEventPage($target.data('event-page-id'));
34+
$('.event-page-nav').removeClass('active');
35+
$target.addClass('active');
36+
},
37+
displayEvents : function (response) {
38+
if (response.error !== undefined) {
39+
$('#event-list-cta').html('<h4>There was an error getting our events.</h4>');
40+
return false;
41+
}
42+
43+
if (response.items.length === 0) {
44+
$('#event-list-cta').html('<h4>There are no upcoming events.</h4>');
45+
return false;
46+
}
47+
48+
// sort events by date
49+
var events = response.items.sort(function (a ,b) {
50+
if (a.start.dateTime !== undefined)
51+
a.start.date = a.start.dateTime;
52+
if (b.start.dateTime !== undefined)
53+
b.start.date = b.start.dateTime;
54+
return new Date(a.start.date) - new Date(b.start.date);
55+
});
56+
var count = 0;
57+
var numPages = 0;
58+
var html = '<ul id="event-list">';
59+
// print each event
60+
response.items.forEach(function(event) {
61+
if (count === 0) {
62+
numPages++;
63+
html += '<div class="event-page" data-event-page="'+ numPages +'">';
64+
}
65+
html += '<li class="event">';
66+
html += '<h4 class="event-title">' + event.summary + '</h4>';
67+
html += '<ul class="event-info">';
68+
date = moment(event.start.dateTime);
69+
html += '<li><i class="fa fa-calendar-o"></i>' + date.format('MMM D \'YY') + '</li>';
70+
// print out time if set
71+
html += (event.start.dateTime === undefined)?'':'<li><i class="fa fa-clock-o"></i>' + date.format('h:mm A') + '</li>';
72+
html += (event.location === undefined)?'':'<li><i class="fa fa-map-marker"></i>' + event.location + '</li>';
73+
html += '</ul>';
74+
html += '</li>';
75+
count++;
76+
if (count === 4) {
77+
html += '</div>';
78+
count = 0;
79+
}
80+
});
81+
html += '</ul>';
82+
83+
if (numPages > 1) {
84+
for (var i = 1; i <= numPages; i++) {
85+
html += '<span data-event-page-id="'+ i +'" class="event-page-nav';
86+
html += (i === 1)?' active':'';
87+
html += '">&nbsp;</span>';
88+
}
89+
}
90+
$('#event-list-cta').html(html);
91+
Events.showEventPage(1);
92+
$('.event-page-nav').on('click', Events.changeEventPage);
93+
$('#event-list').css('minHeight', $('#event-list').height());
94+
}
95+
}

0 commit comments

Comments
 (0)