Skip to content

Instantly share code, notes, and snippets.

@nilya
Created April 8, 2013 11:36
Show Gist options
  • Save nilya/5336173 to your computer and use it in GitHub Desktop.
Save nilya/5336173 to your computer and use it in GitHub Desktop.
Helper script, allows to debug gadget locally without setting up a proper environment (gadget container, etc.). Include this script into your HTML-file with gadget code. More info at https://rizzoma.com/!/ec233aca0354f039c71c3e38bb5a3c696cc7bd/2J
var Participant = function(id, name, avatar) {
this.getId = function() {
return id;
};
this.getDisplayName = function() {
return name;
};
this.getThumbnailUrl = function() {
return avatar;
};
};
var wave = {
isInWaveContainer: function() {
return true;
},
state: {
'key1': 'value 1',
'key2': 'value 2'
},
participants: [
new Participant(1, 'Player 1', 'http://assets.github.com/images/gravatars/gravatar-user-420.png'),
new Participant(2, 'Player 2', 'http://assets.github.com/images/gravatars/gravatar-140.png'),
new Participant(3, 'Spectator', '')
],
getViewer: function() {
return wave.participants[1];
},
getState: function() {
return {
get: function(key) {
return wave.state[key];
},
getKeys: function() {
return Object.keys(wave.state);
},
submitDelta: function(delta) {
for (var i in delta) {
var value = delta[i];
if (value == null) {
if (i in wave.state) {
delete wave.state[i];
}
} else {
wave.state[i] = value;
}
}
wave.stateCallback();
}
};
},
getParticipants: function() {
return wave.participants;
},
getParticipantById: function(id) {
for (var i in wave.participants) {
var participant = wave.participants[i];
if (participant.getId() == id) {
return participant;
}
}
return null;
},
stateCallback: function() {},
setStateCallback: function(callback) {
wave.stateCallback = callback;
},
participantCallback: function() {},
setParticipantCallback: function(callback) {
wave.participantCallback = callback;
}
};
var callbacks = [];
var gadgets = {
json: JSON,
util: {
registerOnLoadHandler: function(callback) {
callbacks.push(callback);
}
},
window: {
adjustHeight: function() {
console.log('adjust window height');
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment