//JavaScript Document
$(document).ready(function() {
//get tag feed
$.post("http://www.freeonlinelaughs.com"+"/api/tagcloud.php", function(data) {
//create list for tag links
var jsonData = eval(data);
$("
").attr("id", "tagList").appendTo("#tagCloud");
var maxFreq = 0;
//Find maximum value
$.each(jsonData.tags, function(i, val) {
if(val.freq > maxFreq)
{
maxFreq = val.freq;
}
});
//create tags
$.each(jsonData.tags, function(i, val) {
//create item
var li = $("- ");
//create link
$("").text(val.tag).attr({title:"See all pages tagged with " + val.tag, href:"http://www.freeonlinelaughs.com/browse.php?tag=" + val.tag}).appendTo(li);
var fontSize = "";
if((val.freq/maxFreq) < 0.3)
{
fontSize = "em";
}
else
{
fontSize = (2*(val.freq/maxFreq)) + "em";
}
li.children().css("fontSize", fontSize);
//add to list
li.appendTo("#tagList");
});
$("#tagList").shuffle();
});
});
(function($){
$.fn.shuffle = function() {
return this.each(function(){
var items = $(this).children();
return (items.length)
? $(this).html($.shuffle(items))
: this;
});
}
$.shuffle = function(arr) {
for(
var j, x, i = arr.length; i;
j = parseInt(Math.random() * i),
x = arr[--i], arr[i] = arr[j], arr[j] = x
);
return arr;
}
})(jQuery);