What's new? | Help | Directory | Sign in
Google
                
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
<html>

<head>
<script src="http://www.lingr.com/javascripts/prototype.js" type="text/javascript"></script>
</head>

<body>

<h1>Lingr API Testing Page</h1>
<p>Enter a room id and I'll generate a badge:
<form onSubmit="doUpdateRoomInfo(); return false;"><input type="text" id="roomId">&nbsp;<input type="submit" value="Go!"></form>
</p>
<div id="roomInfo" style="background: #ffe0e0; display:none;">
<p><a id="roomLink" href="#"><img id="roomImage" src="#" style="display:none; border:none;" width="32" height="32"><span id="roomName"></span></a></p>
<p id="roomDescription"></p>
<p id="roomStatus"></p>
</div>
<div id="roomInfoError" style="background: #ffe0e0; display:none"></div>

<script type="text/javascript">

function dynamic_script_tag(url)
{
var script=document.createElement('script');
script.src=url;
script.type="text/javascript";

document.getElementsByTagName('head')[0].appendChild(script);
}

function doUpdateRoomInfo()
{
url = 'http://www.lingr.com/api/room/get_info?api_key=foo&format=json&callback=updateRoomInfo&id=' + $F('roomId');
dynamic_script_tag(url);
}

function updateRoomInfo(info)
{
if (info.status == 'ok')
{
$('roomLink').href = info.room.url;

$('roomImage').src = info.room.icon_url;
Element.show('roomImage');

if (!info.room.name) info.room.name = '';
Element.update('roomName', info.room.name);

if (!info.room.description) info.room.description = '';
Element.update('roomDescription', info.room.description);

if (info.occupants.length == 0)
{
summary = 'No one is currently chatting';
}
else if (info.occupants.length == 1)
{
summary = info.occupants[0].nickname + ' is waiting to chat';
}
else
{
nicknames = '';
for (i = 0; i < info.occupants.length; i++)
{
if (nicknames.length > 0)
{
nicknames += ', ';
}

nicknames += info.occupants[i].nickname;
}

summary = info.occupants.length + ' people are chatting (' + nicknames + ')';
}

Element.update('roomStatus', summary);

Element.hide('roomInfoError');
Element.show('roomInfo');
}
else
{
Element.update('roomInfoError', 'Could not get info for room ' + $F('roomId'));
Element.hide('roomInfo');
Element.show('roomInfoError');
}
}

</script>
</body>
</html>
Show details Hide details

Change log

r76 by dburkes on Oct 06, 2008   Diff
move to Google Code repository
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 2723 bytes, 91 lines