Skip to content

Commit

Permalink
get socket.io running again
Browse files Browse the repository at this point in the history
fixes #93

affects #94, #95, #96, #97
  • Loading branch information
Gerad Suyderhoud committed Nov 5, 2013
1 parent 4390b83 commit 52758e0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
3 changes: 2 additions & 1 deletion config/nap.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ nap({
"/public/javascripts/2013/judges.coffee",
"/public/javascripts/2013/prizes.coffee",
"/public/javascripts/2013/jobs.coffee",
"/public/javascripts/2013/votes.coffee"
"/public/javascripts/2013/votes.coffee",
'/public/javascripts/2013/websocket.coffee'

],
"2012": [
Expand Down
42 changes: 42 additions & 0 deletions public/javascripts/2013/websocket.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
load = ->
ws = io.connect(window.location.origin)

# reload the page after ~10 seconds (if you're on the index page)
ws.on 'reload', ->
setTimeout ->
if window.location.pathname is '/'
window.location.reload()
, (Math.random() * 10000)

ws.on 'updateStats', (stats) ->
updateStats $("#overall-stats"), stats

# update the stats billboard on the team page
ws.on 'updateTeamStats', (json) ->
{ teamId, stats } = json
updateStats $(".team-stats[data-team-id=#{teamId}]"), stats

# update the deployed stuff
ws.on 'deploy', (team) ->
updateEntryInfo($('#recent-deploys'), team)

# update the interesting entrys on judge visit
ws.on 'judgeVisit', (team) ->
updateEntryInfo($('#interesting-teams'), team)

updateStats = ($el, stats) ->
for k, v of stats
$el.find(".#{k} .number").text(v)

updateEntryInfo = ($el, team) ->
$toAdd = template 'entry-info', team: team

$toRemove = $el.find(".entry-info[data-team-id=#{team.id}]:first")
if $toRemove.length is 0
$toRemove = $el.find('.entry-info:last')

$toRemove.remove()
$toAdd.hide().prependTo($el).animate width: 'show'

$(load)
# note no pjax load here
1 change: 1 addition & 0 deletions views/layout-2013.jade
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ html
script _gaq = [['_setAccount', 'UA-16773586-1'], ['_trackPageview']];
script( async=true, src='//www.google-analytics.com/ga.js' )
script( src='/javascripts/vendor/modernizr-2.5.3.min.js' )
script( src='/socket.io/socket.io.js' )

script( src='//use.typekit.net/unt8jhx.js' )
script( type='text/javascript' )
Expand Down

0 comments on commit 52758e0

Please sign in to comment.