1 <?xml version="1.0" encoding="UTF-8"?>
3 <ModulePrefs title="Social Activities World">
4 <Require feature="opensocial-0.7"></Require>
5 <Require feature="dynamic-height"></Require>
9 <style type="text/css">
12 font-family:arial,helvetica,sans-serif;
18 background-color: #E0ECFF;
19 border-top: 1px solid blue;
23 .socialDescription a {
29 .streamdescription a:visited {
33 text-decoration:underline;
34 font-family:arial,helvetica,sans-serif;
40 font-family:arial,helvetica,sans-serif;
41 text-decoration:underline;
49 border-bottom:1px solid #DDE9F5;
63 padding:2px 0pt 3px 10px;
64 font-family:arial,helvetica,sans-serif;
80 font-family:arial,helvetica,sans-serif;
95 border: 2px solid blue;
100 <script type="text/javascript">
102 gadgets.util.registerOnLoadHandler(refreshActivities);
104 function refreshActivities() {
105 var req = opensocial.newDataRequest();
107 req.add(req.newFetchPersonRequest('VIEWER'), 'viewer');
109 req.add(req.newFetchActivitiesRequest('VIEWER'), 'viewerActivities');
110 req.add(req.newFetchActivitiesRequest('VIEWER_FRIENDS'), 'activities');
111 req.send(handleActivities);
114 function postNewActivity() {
115 var activityElement = document.getElementById('newActivity');
116 var mediaItem = new Array(opensocial.newActivityMediaItem("image", "http://cdn.davesdaily.com/pictures/784-awesome-hands.jpg", {'type' : 'image'}));
117 var activity = opensocial.newActivity({ 'title' : viewer.getDisplayName() + ' wrote: ' + activityElement.value,
118 'body' : 'write back!', 'mediaItems' : mediaItem});
120 activityElement.value = '';
121 opensocial.requestCreateActivity(activity, "HIGH", refreshActivities);
126 function handleActivities(dataResponse) {
128 viewer = dataResponse.get('viewer').getData();
130 activities = dataResponse.get('viewerActivities').getData()['activities'].asArray();
131 activities = activities.concat(dataResponse.get('activities').getData()['activities'].asArray());
132 document.getElementById('stream').style.display = 'block';
135 if (!activities || activities.length == 0) {
136 document.getElementById('stream').innerHTML = 'You do not have any activities yet';
140 for (var i = 0; i < activities.length; i++) {
141 html += '<div class="streamrow">';
143 html += '<div class="streamdescription"><a href="' + activities[i].url + '">' + activities[i].getField('title') + '</a></div>';
145 html += '<div class="streamcontents">';
146 html += '<img src="http://www.google.com/s2/sharing/resources/static/images/quot.png?hl=en_US"/>';
148 var body = activities[i].getField('body') || '';
149 html += '<span class="streamhtmlcontents">' + body + '</span>';
152 html += '<div class="mediaitems">';
153 var mediaItems = activities[i].getField('mediaItems');
155 for (var j = 0; j < mediaItems.length; j++) {
156 if (mediaItems[j].getField('type') == 'image') {
157 html += '<img height="150px" style="padding-right:.5em;" src="' + mediaItems[j].getField('url') + '"/>';
163 var shortUrl = activities[i].getField('url');
165 if (shortUrl.indexOf('http://') == 0) {
166 shortUrl = shortUrl.substring(7);
168 html += '<div class="streamurl"><a href="' + activities[i].getField('url') + '">' + shortUrl + '</a></div>';
172 html += '<div class="streamrowline"></div>';
174 document.getElementById('stream').innerHTML = html;
175 gadgets.window.adjustHeight();
178 function hideShowDiv(divToShow, divToHide) {
179 document.getElementById(divToShow).style.display = 'block';
180 document.getElementById(divToHide).style.display = 'none';
184 <div class="streamtitle">Activities from your friends</div>
185 <div class="addActivityDiv">
186 <a id="addActivityText" href="#" onclick="hideShowDiv('addActivity','addActivityText'); return false;"> Add your own activity </a>
187 <span id="addActivity">
188 <input id="newActivity" type="text"/>
189 <input type="button" onclick="postNewActivity(); return false;" value="add"/>
190 <input type="button" onclick="hideShowDiv('addActivityText','addActivity'); return false;" value="cancel"/>
193 <div id="stream" style="display:none"></div>