Skip to content

Instantly share code, notes, and snippets.

var messageElement =
document.querySelector('#message');
cloak.configure({
messages: {
waitingForAnotherPlayer: function() {
messageElement.innerText =
'Waiting for another player...';
},
gameStart: function() {
var waiting = null;
var games = {};
io.sockets.on('connection', function(socket) {
var id = socket.id;
var game = games[id];
if (game === undefined) {
if (waiting !== null && waiting !== id) {
game = new MyGame();
io.sockets.on('connection', function(socket) {
var game = new MyGame();
socket.on('move', function(data) {
game.move(data);
});
});
@incompl
incompl / client.js
Last active December 25, 2015 21:58
CloakChat Example
// client.js
/* global cloak */
var form = document.querySelector('#input-form');
var input = document.querySelector('#input');
var messages = document.querySelector('#messages');
cloak.configure({
messages: {
@incompl
incompl / poke.js
Created September 25, 2013 21:56
jquery custom event to normalize mousedown and touchstart
/* global $ */
// Custom jQuery event that normalizes mousedown and touchstart
// based on http://stackoverflow.com/questions/8503453/click-event-called-twice-on-touchend-in-ipad
$.event.special.poke = {
setup: function() {
var isTouchSupported = "ontouchstart" in document;
var poke = isTouchSupported ? "touchstart" : "mousedown";
$(this).bind(poke + ".poke-event", function(event) {
@incompl
incompl / gist:6525355
Last active December 22, 2015 20:19
Samsung Galaxy S4 Browser Bugs

The Android Browser on this phone has bugs that are newly introcuded on this phone. It's kind of shameful TBH.

Confirmed

  • border-radius is broken
    • You need to spell out border radius as 4 properties.
    • Source
  • Gradient doesn't work
    • incorrectly implements unprefixed gradients
  • works with -webkit prefix
// Test basic messaging, to and from client
messageBasics: function(test) {
test.expect(2);
var server = this.server;
var client = createClient();
server.configure({
port: this.port,
// tearDown is called after every test
// Shut down server and all clients
tearDown: function(callback) {
try {
_(clients).forEach(function(client) {
if (client.connected()) {
console.log('ending client');
client.end();
}
else {
// Used in tests to create a new Cloak client. Using
// this function instead of doing it manually means
// clients will be properly cleaned up after tests
// are done.
function createClient() {
var client = createCloakClient();
client._setLibs(_, io);
clients.push(client);
return client;
}
// setUp is called before every test
// Pepare a server and an empty client list
setUp: function(callback) {
try {
this.port = 8091;
this.host = 'http://localhost:' + this.port;
this.server = cloakServer;
clients = [];
callback();
}