6/27/2008 12:45:00 AM
A project on which I've been working required some nifty trickery and I thought it was something worth sharing. I bet one could easily add some transition effects to make it more nice-looking but the idea's pretty simple; rotate the titles of the articles you want displayed in a handy-dandy little auto-rotator as links to the article content. The code for this view is below.
<style>
#newsBox
{
width: 300px;
vertical-align: bottom;
border: dotted 1px #eee;
padding: 2px;
}
</style>
<div id="newsBox"></div>
<script language="javascript" type="text/javascript">
var NewsArticle = Class.create({
initialize: function(title, url)
{
this.Title = title;
this.Url = url;
}
});
var NewsArticleRotator = Class.create({
initialize: function()
{
this.Articles = new Array();
#foreach($post in $data.PostsByCategory("news",10))
this.Articles.push( new NewsArticle("$post.Title","$post.Url") );
#end
},
rotate: function()
{
var rnd = Math.floor(Math.random()*this.Articles.length);
$('newsBox').innerHTML = '<a onmouseover=\'toggleNewsLink();\' onmouseout=\'toggleNewsLink()\' href=\'' + this.Articles[rnd].Url + '\'>' + this.Articles[rnd].Title + '</a>';
}
});
var isNewsLinkHot = false;
function toggleNewsLink()
{
isNewsLinkHot = !isNewsLinkHot;
if(!isNewsLinkHot)
rotateNews();
}
function rotateNews()
{
if(isNewsLinkHot) return;
var rttr = new NewsArticleRotator();
rttr.rotate();
window.setTimeout(rotateNews, 3000);
}
rotateNews();
</script>
Happy Coding!
Note - Syntax Highlighter is busted and I'm sleepy so it'll look better tomorrow.
Further update - I touched a few files and all seems well again.
Kick it! |
del.icio.us |
Comments (0) |
Permalink
2/21/2008 12:39:00 AM
I'm getting started with Graffiti CMS right now and so far feel pretty good about all of the excellent features they've thrown in. I prefer the SQL provider method to the default of VistaDB, so I had to go to the Graffiti support site to find information on how convert to the SQL provider. I figure if I need to do it, so will some other people. To make life easier I've written a NAnt script to perform this, and you'll find it right here.
Happy coding!
Kick it! |
del.icio.us |
Comments (2) |
Permalink