forked from square/cube
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'add-board-list' of https://github.com/movableink/cube
- Loading branch information
Showing
5 changed files
with
161 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
cube.boards = function(url) { | ||
var socket, | ||
interval; | ||
|
||
var boardList = document.getElementById("boards"); | ||
|
||
function message(message) { | ||
var data = JSON.parse(message.data); | ||
|
||
switch(data.type) { | ||
case "add": { | ||
var board = data.board; | ||
var id = board._id.toString(36); | ||
|
||
var li = document.createElement("li"); | ||
|
||
var selection = d3.select(li) | ||
.attr("class", "board-item"); | ||
|
||
|
||
var link = selection.append("a") | ||
.text(id) | ||
.attr("href", "http://" + document.location.host + "/" + id); | ||
|
||
var count = selection.append("span") | ||
.text(" (" + board.pieces.length + ")"); | ||
|
||
boardList.appendChild(selection.node()); | ||
} | ||
} | ||
} | ||
|
||
function reopen() { | ||
if (socket) { | ||
socket.close(); | ||
} | ||
socket = new WebSocket(url); | ||
socket.onopen = load; | ||
socket.onmessage = message; | ||
if (!interval) interval = setInterval(ping, 5000); | ||
} | ||
|
||
function ping() { | ||
if (socket.readyState == 1) { | ||
socket.send(JSON.stringify({type: "ping"})); | ||
} else if (socket.readyState > 1) { | ||
reopen(); | ||
} | ||
} | ||
|
||
function load() { | ||
if (socket && socket.readyState == 1) { | ||
socket.send(JSON.stringify({type: "load"})); | ||
} | ||
} | ||
|
||
reopen(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
body { | ||
position: relative; | ||
font-family: "Helvetica Neue"; | ||
width: 960px; | ||
margin: auto; | ||
text-rendering: optimizeLegibility; | ||
} | ||
|
||
h1 { | ||
margin: 40px 0; | ||
font-size: 72pt; | ||
font-family: "Yanone Kaffeesatz"; | ||
position: relative; | ||
border-bottom: 1px solid #000; | ||
} | ||
|
||
h2 { | ||
font-family: "Yanone Kaffeesatz"; | ||
position: relative; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Cube</title> | ||
<script type="text/javascript" src="/d3/d3.js"></script> | ||
<script type="text/javascript" src="/cube.js"></script> | ||
<style type="text/css"> | ||
@import url(http://fonts.googleapis.com/css?family=Yanone+Kaffeesatz); | ||
</style> | ||
<link type="text/css" rel="stylesheet" href="/home.css"/> | ||
</head> | ||
<body> | ||
<h1>Cube</h1> | ||
|
||
<h2>Boards</h2> | ||
<ol id="boards"></ol> | ||
|
||
<a href="/new">New Board</a> | ||
|
||
<script type="text/javascript"> | ||
|
||
var mode = "list", | ||
boards = cube.boards("ws://" + location.host + "/boards"); | ||
|
||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters