Skip to content

Instantly share code, notes, and snippets.

@lakenen
Created September 28, 2012 00:20
Show Gist options
  • Save lakenen/3797237 to your computer and use it in GitHub Desktop.
Save lakenen/3797237 to your computer and use it in GitHub Desktop.
Pulls posts from http://reddit.com/r/nocontext and shows them nicely.
TEXT_DISPLAY_TIME = 10000
delay = (ms, fn) -> setTimeout fn, ms
class NoContexts
constructor: ->
@next()
refreshData: (cb) ->
@noContexts = []
$.getJSON "http://www.reddit.com/r/nocontext.json?limit=100&jsonp=?", (data) =>
for child in data.data.children
if child.data.title?
@noContexts.push
url: child.data.url
text: child.data.title.replace /^['"`]|['"`]$/g, ''
cb()
updateText: (nc) ->
@elt = $('<a>').append(nc.text).addClass('nocon-text').attr
href: nc.url
target: '_blank'
$('body').append @elt
wh = $(window).height()
ww = $(window).width()
@elt.addClass('animate').css
color: 'hsl('+(Math.random() * 360)+',50%,50%)'
top: wh/4 + Math.random() * (wh/2 - @elt.height())
left: ww/4 + Math.random() * (ww/2 - @elt.width())
next: ->
if @elt?
@elt.removeClass('animate').addClass 'goaway'
delay 300, => @update()
else
@update()
update: ->
if @noContexts?.length > 0
ind = Math.floor Math.random() * (@noContexts.length - 1)
nc = @noContexts.splice ind, 1
@updateText nc[0]
delay TEXT_DISPLAY_TIME, => @next()
else
@refreshData => @next()
new NoContexts
@import "compass";
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
body {
background: black;
overflow: hidden;
font-family: "Verdana", "Arial", sans-serif;
text-align: center;
}
.nocon-text {
position: absolute;
opacity: 0.0;
font-size: 2em;
max-width: 40%;
-webkit-transform: scale(0.7);
-webkit-transition: -webkit-transform 10s, opacity 5s ease-out;
text-decoration: none;
}
.animate {
opacity: 1.0;
-webkit-transform: scale(1.5);
}
.goaway {
opacity: 0.1;
-webkit-transform: scale(0.3);
-webkit-transition: -webkit-transform 10s, opacity 5s ease-out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment