-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbidder.xml
77 lines (74 loc) · 2.59 KB
/
bidder.xml
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
<Module>
<ModulePrefs title="Wave Bidding" height="250">
<Require feature="rpc"/>
</ModulePrefs>
<Content type="html">
<![CDATA[
<script type="text/javascript"
src="http://wave-api.appspot.com/public/wave.js"></script>
<script type="text/javascript">
function buttonClicked() {
var viewerId = wave.getViewer().getId();
var state = wave.getState();
var bid = parseInt(document.getElementById('yourBid').value);
var currentBid = parseInt(state.get(viewerId, '0'));
if (bid > currentBid) {
delta = {};
delta[viewerId] = bid;
state.submitDelta(delta);
}
}
function renderInfo() {
if (!wave.getState()) {
return;
}
var highestBid = 0;
var highestBidderId = null;
var state = wave.getState();
var keys = state.getKeys();
for (var i = 0; i < keys.length; ++i) {
var bidder = keys[i];
var bid = parseInt(state.get(bidder));
if (bid > highestBid) {
highestBid = bid;
highestBidderId = bidder;
}
}
var bidderName = 'Nobody';
var thumbNail = 'http://wave-api.appspot.com/public/unknown.gif';
if (highestBidderId) {
bidderName = highestBidderId;
var participants = wave.getParticipants();
if (participants) {
for (var i = 0; i < participants.length; ++i) {
if (participants[i].getId() == highestBidderId) {
var highestBidder = participants[i];
bidderName = highestBidder.getDisplayName();
if (!bidderName) {
bidderName = highestBidder.getId();
}
thumbNail = highestBidder.getThumbnailUrl();
}
}
}
}
document.getElementById('bidderThumbnail').src = thumbNail;
document.getElementById('bidderName').firstChild.nodeValue = bidderName;
document.getElementById('highestBid').firstChild.nodeValue = highestBid;
document.getElementById('yourBid').value = highestBid;
}
function main() {
if (wave && wave.isInWaveContainer()) {
wave.setStateCallback(renderInfo);
wave.setParticipantCallback(renderInfo);
}
}
gadgets.util.registerOnLoadHandler(main);
</script>
<img id="bidderThumbnail" src="http://wave-api.appspot.com/public/gadgets/unknown.gif" width="50" height="50"/><br/>
<span id="bidderName">Nobody</span><br/>
Highest bid: <span id="highestBid">0</span><br/>
Your bid: <input id="yourBid" size="5" value="0"><button id="butCount" onclick="buttonClicked()">Bid</button><br/>
]]>
</Content>
</Module>