Revamp latest stuff on frontpage
color: #8F8F8F;
text-align: right;
}
+
+#latest h2 {
+ font-size: 16pt;
+}
+
+#latest-posts {
+ height: 92pt;
+ overflow: hidden;
+}
+
+#latest-posts .record {
+ font-size: 12pt;
+ margin: 4pt 0;
+}
+
+.author {
+ font-weight: bold;
+}
<title>Blërg!</title>
<link rel="stylesheet" href="css/blerg.css">
<script type="text/javascript" src="js/prototype.js"></script>
+<script type="text/javascript" src="js/Bytex64.FX.js"></script>
<script type="text/javascript" src="js/blerg.js"></script>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, maximum-scale=1.0"/>
<div id="welcome">
- <div style="float: right; width: 25%; margin: 0 0 8pt 8pt">
- <h2>Quick and dirty hack to show recent tags</h2>
- <div id="newtags"></div>
-
- <h2>And here are some users with recent activity</h2>
- <div id="newusers"></div>
+ <div id="latest">
+ <h2>Latest tags</h2>
+ <div id="latest-tags"></div>
+ <h2>Latest posts</h2>
+ <div id="latest-posts"></div>
</div>
<h2>I am 12 and what is this</h2>
+if (typeof(Bytex64) == 'undefined') Bytex64 = {};
+Bytex64.FX = {};
+Bytex64.FX.version = 1.0;
+
+Bytex64.FX.Effect = function(fx, secs) {
+ this.fx = fx;
+ this.secs = secs;
+
+ this.run = function() {
+ Bytex64.FX.run(this.fx, this.secs);
+ };
+};
+
+Bytex64.FX.ParallelEffect = function(fxs, secs) {
+ this.fx = function(p) {
+ for (i in fxs) {
+ fxs[i](p);
+ }
+ };
+ this.secs = secs;
+
+ this.run = function() {
+ Bytex64.FX.run(this.fx, this.secs);
+ };
+};
+
+Bytex64.FX.EffectChain = function(chain) {
+ this.chain = chain;
+ this.current = 0;
+
+ this.fx_current = function(p) {
+ this.chain[this.current].fx(p);
+ };
+
+ this.run = function() {
+ _this = this;
+
+ fx = function(p) {
+ _this.fx_current(p);
+ if (p == 1.0)
+ _this.run_next();
+ };
+
+ Bytex64.FX.run(fx, this.chain[this.current].secs);
+ };
+
+ this.run_next = function() {
+ this.current++;
+
+ if (this.current >= this.chain.length) {
+ this.current = 0;
+ return;
+ }
+
+ this.run();
+ };
+
+};
+
+Bytex64.FX.updateInterval = 50;
+
+Bytex64.FX.run = function(fx, secs) {
+ secs = secs * 1000;
+
+ var interval;
+ var start = (new Date()).getTime();
+
+ fx(0.0);
+
+ interval = setInterval(function() {
+ var d = (new Date()).getTime() - start;
+ if (d >= secs) {
+ clearInterval(interval);
+ fx(1.0);
+ } else {
+ fx(d/secs);
+ }
+ }, Bytex64.FX.updateInterval);
+}
+
+Bytex64.FX.create = function(fx, secs) {
+ return function() {
+ Bytex64.FX.run(fx, secs);
+ }
+}
+
+Bytex64.FX.fadeIn = function(elem) {
+ return function(p) {
+ if (p == 0.0)
+ elem.style.display = 'block';
+ elem.style.opacity = p;
+ }
+}
+
+Bytex64.FX.fadeOut = function(elem) {
+ return function(p) {
+ elem.style.opacity = 1.0 - p;
+ if (p == 1.0)
+ elem.style.display = 'none';
+ }
+}
+
+/* vim: set ts=4 sts=4 sw=4 expandtab: */
'<div class="record">#{data}<div class="info">Posted #{date}</div></div>'
);
var tagRecordTemplate = new Template(
- '<div class="record">#{data}<div class="info">Posted by <a href="/\##{author}">@#{author}</a> on #{date}</div></div>'
+ '<div class="record">#{data}<div class="info">Posted by <a class="author" href="/\##{author}">@#{author}</a> on #{date}</div></div>'
+);
+var latestRecordsTemplate = new Template(
+ '<div class="record"><a class="author" href="/\##{author}">@#{author}</a> #{data}</div>'
);
// Page elements
}, 150);
}
-function loadNewThings() {
- new Ajax.Request(baseURL + '/newtags.json', {
+var tickerTimer = null;
+var tickerHead, tickerTail;
+
+function tickerFader(a, b, p) {
+ var p2 = 1 - p;
+
+ a.style.opacity = p;
+ a.style.lineHeight = (100 * p) + '%';
+
+ b.style.opacity = p2;
+ b.style.lineHeight = (100 * p2) + '%';
+ if (p == 1.0)
+ b.hide();
+}
+
+function fadeOut(p) {
+}
+
+function ticker() {
+ tickerHead.show();
+ Bytex64.FX.run(tickerFader.curry(tickerHead, tickerTail), 0.5);
+ tickerHead = tickerHead.nextSibling;
+ tickerTail = tickerTail.nextSibling;
+ if (tickerHead == null) {
+ stopTicker();
+ loadLatest.delay(10);
+ }
+}
+
+function startTicker() {
+ stopTicker();
+ for (var elem = $('latest-posts').firstChild; elem != null; elem = elem.nextSibling) {
+ elem.hide();
+ }
+
+ // Show the first five
+ tickerHead = $('latest-posts').firstChild;
+ for (var i = 0; i < 5 && tickerHead; i++) {
+ tickerHead.show();
+ tickerHead = tickerHead.nextSibling;
+ }
+ tickerTail = $('latest-posts').firstChild;
+ tickerTimer = setInterval(ticker, 5000);
+}
+
+function stopTicker() {
+ if (tickerTimer)
+ clearInterval(tickerTimer);
+ tickerTimer = null;
+}
+
+function loadLatest() {
+ new Ajax.Request(baseURL + '/latest.json', {
onSuccess: function(r) {
- $('newtags').update();
- r.responseText.evalJSON().each(function(v) {
+ var j = r.responseText.evalJSON();
+
+ $('latest-tags').update();
+ j.tags.each(function(v) {
var a = new Element('a', {href: '/#tag/' + v});
a.insert('#' + v);
- $('newtags').insert(a);
- $('newtags').insert(new Element('br'));
+ $('latest-tags').insert(a);
+ $('latest-tags').appendChild(document.createTextNode(' '));
});
- }
- });
- new Ajax.Request(baseURL + '/newusers.json', {
- onSuccess: function(r) {
- $('newusers').update();
- r.responseText.evalJSON().each(function(v) {
- var a = new Element('a', {href: '/#' + v});
- a.insert('@' + v);
- $('newusers').insert(a);
- $('newusers').insert(new Element('br'));
+ $('latest-posts').update();
+ j.records.each(function(v) {
+ v.data = v.data.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
+ v.date = (new Date(v.timestamp * 1000)).toString();
+ var html = latestRecordsTemplate.evaluate(v);
+ $('latest-posts').insert(html);
});
+ startTicker();
}
});
}
function hashSwitch() {
var m;
+ stopTicker();
if (m = location.search.match(/^\?post\/([^/]+)\/(.+)/)) {
$('post').show();
$('post.content').value = '[' + decodeURIComponent(m[1]).replace(']','').replace('[','') + '](' + decodeURIComponent(m[2]) + ')';
$('older_link').hide();
$('welcome').show();
$('rss').hide();
- loadNewThings();
+ loadLatest();
}
}