<% # This is the maximum number of tags in the tag cloud. Javascript code will remove tags if the # window is to small to show all of them. tagcloud_number_of_tags = 260 tags = @db.select("SELECT key, scale1 FROM popular_keys ORDER BY scale1 DESC LIMIT #{ tagcloud_number_of_tags }"). execute(). each_with_index{ |tag, idx| tag['pos'] = (tagcloud_number_of_tags - idx) / tagcloud_number_of_tags.to_f }. sort_by{ |row| row['key'] } %> var tagcloud_data = <%= tags.map{ |tag| [tag['key'], tagcloud_size(tag)] }.to_json.gsub(/\],/, "],\n") %>; function resize_home() { var tagcloud = jQuery('#tagcloud'); tagcloud.empty(); tagcloud.height(0); resize_box(); var height = tagcloud.parent().innerHeight(); tagcloud.parent().children().each(function(index) { if (this.id != 'tagcloud') { height -= jQuery(this).outerHeight(true); } }); tagcloud.height(height - 20); var cloud = ''; for (var i=0; i < tagcloud_data.length; i++) { cloud += link(url_for_key(tagcloud_data[i][0]), tagcloud_data[i][0], { style: 'font-size: ' + tagcloud_data[i][1] + 'px;' }) + ' '; } tagcloud.append(cloud); var tags_array = tagcloud.children().toArray().sort(function(a, b) { return parseInt(jQuery(a).css('font-size')) - parseInt(jQuery(b).css('font-size')); }); while (tagcloud.get(0).scrollHeight > tagcloud.height()) { jQuery(tags_array.shift()).remove(); } } function page_init() { jQuery(window).resize(resize_home); resize_home(); }