This repository was archived by the owner on Sep 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGCalTSS.xml
More file actions
222 lines (194 loc) · 7.41 KB
/
GCalTSS.xml
File metadata and controls
222 lines (194 loc) · 7.41 KB
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
<?xml version="1.0" encoding="UTF-8" ?>
<!--
GCalTSS.xml - Time Spent Summary for Google Calendar.
Copyright (C) 2012 Alex Dioso (alex.dioso@ikaika.org)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<Module>
<ModulePrefs title="GCalTSS"
title_url="http://blog.ikaika.org/search/label/GCalTSS"
description="Displays the most recent labels of a blog in a movable
sphere. This gadget is written in JavaScript, no flash required.
Your blog must be public for this gadget to work. The feed used for
the labels updates slowly so recently created labels will take time to
show up."
author="Alex Dioso"
author_email="alex.dioso@ikaika.org"
author_location="Seattle, Washington, US"
author_affiliation="ikaika.org"
scrolling="true">
<Require feature="opensocial-0.8"/>
<Require feature="minimessage"/>
<Require feature="google.calendar-0.5"/>
<Require feature="google.calendar-0.5.read"/>
</ModulePrefs>
<!--
JavaScript optimized for Closure Compiler
http://code.google.com/closure/compiler/docs/gettingstarted_app.html
-->
<Content type="html">
<![CDATA[
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script type="text/javascript">
/*
* Requires jQuery to be loaded before this script
* Then this script should be loaded with
* gadgets.util.registerOnLoadHandler(function(){ikaika(__MODULE_ID__)});
*/
var ikaika = (function(my) {
if (my === undefined) {
my = {};
}
var groups = {};
var totalTime = 0;
// Provide variables for commonly used things so they can be optimized by
// the closure compiler
//var mSqrt = Math['sqrt'];
var container;
var animate = 'animate';
// Supported skin properties
// http://code.google.com/apis/blogger/docs/gadgets/gadgets_for_blogger.html#BestUIPractices
//var gSkinsGetProp = gadgets['skins']['getProperty'];
//var fontFace = gSkinsGetProp('FONT_FACE');
/*
* Performs all the setup for the gadget, gets list of labels from the
* blog's feed, arranges them around a sphere, and sets event handlers to
* rotate the sphere based on mouse position.
*/
my.init = function(moduleId) {
// Status messages
var msg = new gadgets['MiniMessage'](moduleId);
// If the gadget is not being used on Calendar
if (!google['hasOwnProperty']('calendar')){
var hasOwnPropMsg =
msg['createStaticMessage']("GCalTSS only works in Calendar");
return;
}
// Display a loading status message to let the user know something is
// happening
var loadMessage = msg['createStaticMessage']("Loading...");
container = $('#ikaika-container');
// Animate the div containing the ikaika link
$('#ikaika')['hover']( ikaikaHoverIn, ikaikaHoverOut);
google.calendar.subscribeToDates(datesCallback);
msg['dismissMessage'](loadMessage);
};
/*
* Increase fontsize and opacity of an object when the mouse is over it
*/
function ikaikaHoverIn() {
$(this)[animate]({
opacity: '1',
fontSize: '100%'
},
'fast');
}
/*
* Decrease fontsize and opacity of an object when the mouse isn't over it
*/
function ikaikaHoverOut() {
$(this)[animate]({
opacity: '.5',
fontSize: '70%'
},
'fast');
}
function errorMessage(txt) {
msg['dismissMessage'](loadMessage);
var errorMsg = msg['createStaticMessage'](txt);
}
function datesCallback(dates) {
var start = dates.startTime;
var end = dates.endTime;
google.calendar.read.getEvents(eventsCallback, "selected", start, end);
}
function eventsCallback(calendars) {
var numCalendars = calendars.length;
totalTime = 0;
container.empty();
for (var prop in groups) {
delete groups[prop];
}
for (var i = 0; i < numCalendars; i += 1) {
if (calendars[i]['events'].length > 0) {
createGroup(calendars[i]);
}
}
var percentage = 0;
var html;
var totalPercentage = 0;
var prop;
for (prop in groups) {
if (groups[prop].hasOwnProperty('obj')) {
percentage = Math.round((groups[prop]['time'] / totalTime) * 100);
totalPercentage += percentage;
html = groups[prop]['obj'].html();
groups[prop]['obj'].html(html+"<span class='percentage'>"+percentage+"%</span>");
}
}
totalPercentage -= percentage;
percentage = 100 - totalPercentage;
groups[prop]['obj'].html(html+"<span class='percentage'>"+percentage+"%</span>");
}
function createGroup(group) {
groups[group['name']] = new Object();
//groups[group['name']].css('background-color', 'red');
var time = 0;
var start;
var end;
var events = group['events'];
var numEvents = events.length;
for (var i = 0; i < numEvents; i += 1) {
start = google.calendar.utils.toDate(events[i].startTime);
end = google.calendar.utils.toDate(events[i].endTime);
time += end.getTime() - start.getTime();
}
groups[group['name']]['obj'] = container.append("<div><span>"+group['name']+":</span> </div>").children().last();
groups[group['name']]['time'] = time;
groups[group['name']]['color'] = events[0].palette.lightest;
groups[group['name']]['obj'].css('background-color', groups[group['name']]['color']);
totalTime += time;
}
return my;
} (ikaika));
gadgets.util.registerOnLoadHandler(function(){
ikaika.init(__MODULE_ID__)
});
</script>
<style type="text/css">
#ikaika-container {
/* TODO Fix overflow */
overflow: auto;
}
#ikaika {
position: absolute;
bottom: 0px;
/* TODO - Fix opacity for IE
* http://www.quirksmode.org/css/opacity.html
*/
opacity: .5;
font-size: 70%;
}
.percentage {
float:right;
}
</style>
<div id="ikaika-container">
<div id="ikaika">
<a href="http://blog.ikaika.org/search/label/GCalTSS"
target="_parent">ikaika.org</a>
</div>
</div>
]]>
</Content>
</Module>
<!-- vim: set filetype=google_gadgets : -->