1 <?xml version="1.0" encoding="UTF-8"?>
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 <ModulePrefs title="Social Activities World"
22 icon="http://localhost:8080/gadgets/files/samplecontainer/examples/icon.png">
23 <Require feature="opensocial-0.7"></Require>
24 <Require feature="dynamic-height"></Require>
28 <style type="text/css">
31 font-family:arial,helvetica,sans-serif;
37 background-color: #E0ECFF;
38 border-top: 1px solid blue;
42 .socialDescription a {
48 .streamdescription a:visited {
52 text-decoration:underline;
53 font-family:arial,helvetica,sans-serif;
59 font-family:arial,helvetica,sans-serif;
60 text-decoration:underline;
68 border-bottom:1px solid #DDE9F5;
82 padding:2px 0pt 3px 10px;
83 font-family:arial,helvetica,sans-serif;
99 font-family:arial,helvetica,sans-serif;
114 border: 2px solid blue;
119 <script type="text/javascript">
121 gadgets.util.registerOnLoadHandler(refreshActivities);
123 function refreshActivities() {
124 var req = opensocial.newDataRequest();
126 req.add(req.newFetchPersonRequest('VIEWER'), 'viewer');
128 req.add(req.newFetchActivitiesRequest('VIEWER'), 'viewerActivities');
129 req.add(req.newFetchActivitiesRequest('VIEWER_FRIENDS'), 'activities');
130 req.send(handleActivities);
133 function postNewActivity() {
134 var activityElement = document.getElementById('newActivity');
135 var mediaItem = new Array(opensocial.newActivityMediaItem("image", "http://cdn.davesdaily.com/pictures/784-awesome-hands.jpg", {'type' : 'image'}));
136 var activity = opensocial.newActivity({ 'title' : viewer.getDisplayName() + ' wrote: ' + activityElement.value,
137 'body' : 'write back!', 'mediaItems' : mediaItem});
139 activityElement.value = '';
140 opensocial.requestCreateActivity(activity, "HIGH", refreshActivities);
145 function handleActivities(dataResponse) {
147 viewer = dataResponse.get('viewer').getData();
149 activities = dataResponse.get('viewerActivities').getData()['activities'].asArray();
150 activities = activities.concat(dataResponse.get('activities').getData()['activities'].asArray());
151 document.getElementById('stream').style.display = 'block';
154 if (!activities || activities.length == 0) {
155 document.getElementById('stream').innerHTML = 'You do not have any activities yet';
159 for (var i = 0; i < activities.length; i++) {
160 html += '<div class="streamrow">';
162 html += '<div class="streamdescription"><a href="' + activities[i].url + '">' + activities[i].getField('title') + '</a></div>';
164 html += '<div class="streamcontents">';
165 html += '<img src="http://www.google.com/s2/sharing/resources/static/images/quot.png?hl=en_US"/>';
167 var body = activities[i].getField('body') || '';
168 html += '<span class="streamhtmlcontents">' + body + '</span>';
171 html += '<div class="mediaitems">';
172 var mediaItems = activities[i].getField('mediaItems');
174 for (var j = 0; j < mediaItems.length; j++) {
175 if (mediaItems[j].getField('type') == 'image') {
176 html += '<img height="150px" style="padding-right:.5em;" src="' + mediaItems[j].getField('url') + '"/>';
182 var shortUrl = activities[i].getField('url');
184 if (shortUrl.indexOf('http://') == 0) {
185 shortUrl = shortUrl.substring(7);
187 html += '<div class="streamurl"><a href="' + activities[i].getField('url') + '">' + shortUrl + '</a></div>';
191 html += '<div class="streamrowline"></div>';
193 document.getElementById('stream').innerHTML = html;
194 gadgets.window.adjustHeight();
197 function hideShowDiv(divToShow, divToHide) {
198 document.getElementById(divToShow).style.display = 'block';
199 document.getElementById(divToHide).style.display = 'none';
203 <div class="streamtitle">Activities from your friends</div>
204 <div class="addActivityDiv">
205 <a id="addActivityText" href="#" onclick="hideShowDiv('addActivity','addActivityText'); return false;"> Add your own activity </a>
206 <span id="addActivity">
207 <input id="newActivity" type="text"/>
208 <input type="button" onclick="postNewActivity(); return false;" value="add"/>
209 <input type="button" onclick="hideShowDiv('addActivityText','addActivity'); return false;" value="cancel"/>
212 <div id="stream" style="display:none"></div>