Skip to content

Instantly share code, notes, and snippets.

@z3cka
Created November 9, 2012 23:28
Show Gist options
  • Save z3cka/4049006 to your computer and use it in GitHub Desktop.
Save z3cka/4049006 to your computer and use it in GitHub Desktop.
a poormans tag cloud built from drupal views rows
(function($){
$(document).ready(function(){
// build an awesome tag cloud
function rowobject(param1, param2){
this.name=param1;
this.countresult=param2;
}
// create array that will be filled with objects
var rows = Array();
// grab a tag count for each tag
$.each($('div.view-id-blog_content.view-display-id-block_4 div.views-row-last'), function() {
var rowcount = $(this).attr('class').replace(/\D/g,'');
// put tags into an array as objects
var row=new rowobject($(this).html(),rowcount);
rows.push(row);
});
//sort by count, descending
rows.sort(function(a, b) {
return b.countresult-a.countresult;
});
// print the top 20 tags
var i = 0;
while (i < 20) {
var currentRowSplit = rows[i].name.split("field-content");
// add rank class
rows[i].name = currentRowSplit[0]+"field-content final rank-"+i+currentRowSplit[1];
$('div.view-id-blog_content.view-display-id-block_4').append(rows[i].name);
i++;
}
// remove all old elements
$('div.view-id-blog_content.view-display-id-block_4 div.grouped-tag').remove();
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment