1 <?xml version="1.0" encoding="UTF-8"?>
3 <ModulePrefs title="Social Hello World">
4 <Require feature="opensocial-0.7"></Require>
5 <Require feature="caja"></Require>
6 <Require feature="dynamic-height"></Require>
10 <style type="text/css">
13 font-family: arial, sans-serif;
22 background-image: url(/gadgets/files/samplecontainer/examples/bubble.gif);
23 background-repeat: no-repeat;
26 padding: 12px 0px 0px 12px;
32 .c0 { color: #008000; }
33 .c1 { color: #FF8A00; }
34 .c2 { color: #7777CC; }
35 .c3 { color: #008000; }
36 .c4 { color: #CC0000; }
37 .c5 { color: #73A6FF; }
51 <script type="text/javascript">
52 var hellos = new Array('Hello World', 'Hallo Welt', 'Ciao a tutti', 'Hola mundo',
53 'Появление на свет', 'こんにちは世界', '你好世界', '여러분, 안녕하세요');
54 var numberOfStyles = 6;
57 var allPeople, viewerFriendData;
58 function render(data) {
59 var viewer = data.get('viewer').getData();
60 allPeople = data.get('viewerFriends').getData().asArray() || new Array();
62 allPeople.push(viewer);
65 var viewerData = data.get('viewerData').getData() || {};
66 viewerCount = getCount(viewerData[viewer.getId()]);
68 viewerFriendData = data.get('viewerFriendData').getData() || {};
69 viewerFriendData[viewer.getId()] = viewerData[viewer.getId()];
72 for (var i = 0; i < allPeople.length; i++) {
73 var count = getCount(viewerFriendData[allPeople[i].getId()]);
78 html += '<div class="person">';
79 html += '<div class="bubble c' + count % numberOfStyles + '">' + hellos[count % hellos.length];
80 html += '<div class="name">' + allPeople[i].getDisplayName() + ' (' + count + ') ' + allPeople[i].getField(opensocial.Person.Field.GENDER).getDisplayValue();
81 html += '</div></div>';
83 if (allPeople[i].getField(opensocial.Person.Field.THUMBNAIL_URL)
84 && allPeople[i].getField(opensocial.Person.Field.THUMBNAIL_URL).indexOf('null') == -1) {
85 html += '<img src="' + allPeople[i].getField(opensocial.Person.Field.THUMBNAIL_URL) + '"/>';
87 html += '<img src="/gadgets/files/samplecontainer/examples/nophoto.gif"/>';
89 html += '<br style="clear:both"></div>';
91 document.getElementById('helloworlds').innerHTML = html;
93 gadgets.window.adjustHeight();
96 function getCount(data) {
97 return data && data['count'] ? Number(data['count']) : 0;
100 function sayHelloWorld() {
102 var req = opensocial.newDataRequest();
103 req.add(req.newUpdatePersonAppDataRequest('VIEWER', 'count', viewerCount), 'updateData');
109 opts[opensocial.DataRequest.PeopleRequestFields.FIRST] = 0;
110 opts[opensocial.DataRequest.PeopleRequestFields.MAX] = 40;
111 opts[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] =
112 [opensocial.Person.Field.AGE,
113 opensocial.Person.Field.NAME,
114 opensocial.Person.Field.GENDER,
115 opensocial.Person.Field.PROFILE_URL,
116 opensocial.Person.Field.THUMBNAIL_URL,
117 opensocial.Person.Field.STATUS];
118 opts[opensocial.DataRequest.PeopleRequestFields.SORT_ORDER] = opensocial.DataRequest.SortOrder.NAME;
122 function initData() {
123 var req = opensocial.newDataRequest();
124 req.add(req.newFetchPersonRequest('VIEWER', opts), 'viewer');
125 req.add(req.newFetchPeopleRequest('VIEWER_FRIENDS', opts), 'viewerFriends');
126 req.add(req.newFetchPersonAppDataRequest('VIEWER', 'count'), 'viewerData');
127 req.add(req.newFetchPersonAppDataRequest('VIEWER_FRIENDS', 'count'), 'viewerFriendData');
131 gadgets.util.registerOnLoadHandler(initData);
134 <div style="margin-bottom: 1em">
135 <input type="button" value="Say hello" onclick="sayHelloWorld(); return false;"/>
137 <div id="helloworlds" style="margin: 4px">