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