forked from bradoyler/GoogleCalReader-jquery-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.googlecalreader-1.0.js
121 lines (99 loc) · 4.58 KB
/
jquery.googlecalreader-1.0.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
/// <reference path="jquery-1.5.1.min.js" />
/*
* Google Calendar feed reader - plugin to get upcoming events from a *public* google calendar
* Parameters: FeedUri, MaxResults & DisplayCount
* README: Make sure that your gCal feed url end with "/public/full".
* @version 1.0
*/
(function ($) {
//Add gcal element
$(document).ready(function () {
$('body').prepend('<div id="gcal">Loading...</div>');
});
//Resize image on ready or resize
$.gCalReader = function (options) {
//Default settings
var settings = {
feedUri: 'http://www.google.com/calendar/feeds/en.usa%23holiday%40group.v.calendar.google.com/public/full',
maxresults: 20,
displayCount: 1
};
var feedUri = options.feedUri;
if (feedUri.indexOf("public/full") == -1) {
feedUri = settings.feedUri;
}
var options = $.extend(settings, options);
function _run() {
var calendarService = new google.gdata.calendar.CalendarService('GoogleInc-jsguide-1.0');
// The "public/full" feed is used to retrieve events from the named public calendar with full projection.
var query = new google.gdata.calendar.CalendarEventQuery(feedUri);
query.setOrderBy('starttime');
query.setSortOrder('ascending');
query.setFutureEvents(true);
query.setSingleEvents(true);
query.setMaxResults(options.maxresults);
var callback = function (result) {
var entries = result.feed.getEntries();
$('#gcal').html('');
if (options.displayCount) {
$('#gcal').html(entries.length + ' upcoming events');
}
$('#gcal').append('<ul id="eventlist"></ul>');
for (var i = 0; i < entries.length; i++) {
var eventEntry = entries[i];
var eventTitle = eventEntry.getTitle().getText();
var startDateTime = null;
var eventDate = null;
var eventWhere = null;
var eventContent = eventEntry.getContent().getText();
var times = eventEntry.getTimes();
if (times.length > 0) {
startDateTime = times[0].getStartTime();
eventDate = startDateTime.getDate();
}
var d_names = new Array("Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat");
var m_names = new Array("Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec");
var a_p = "";
var d = eventDate;
var curr_hour = d.getHours();
if (curr_hour < 12) {
a_p = "am";
}
else {
a_p = "pm";
}
if (curr_hour == 0) {
curr_hour = 12;
}
if (curr_hour > 12) {
curr_hour = curr_hour - 12;
}
var curr_min = d.getMinutes();
curr_min = curr_min + "";
if (curr_min.length == 1) {
curr_min = "0" + curr_min;
}
var time = curr_hour + ':' + curr_min + a_p;
var day = eventDate.getDay();
var month = eventDate.getMonth();
var date = eventDate.getDate();
var dayname = d_names[day];
var monthname = m_names[month];
var location = eventEntry.getLocations();
var eventWhere = location[0].getValueString();
var eventhtml = '<div id="eventtitle">' + eventTitle + '</div> When: ' + dayname + ' ' + monthname + ' ' + date + ', ' + time + '<br>Where: ' + eventWhere + '<br>' + eventContent;
$('#eventlist').append('<li>' + eventhtml + '</li>');
}
};
// Error handler to be invoked when getEventsFeed() produces an error
var handleError = function (error) {
$('#gcal').html('<pre>' + error + '</pre>');
};
// Submit the request using the calendar service object
calendarService.getEventsFeed(query, callback, handleError);
}
google.setOnLoadCallback(_run);
$(window).load(function () {
}); //End window load
};
})(jQuery);