diff options
author | Jochen Topf <jochen@topf.org> | 2012-01-25 20:54:10 +0100 |
---|---|---|
committer | Jochen Topf <jochen@topf.org> | 2012-01-25 20:54:10 +0100 |
commit | 28d7a98cabf28463c63df74cdfe1d30dfdb5fbd8 (patch) | |
tree | f0c22994b24c53eb11afb944a0e1a453980a9190 /web | |
parent | 1421956f528c8c1053e1593c633fc20f3407737e (diff) | |
download | taginfo-28d7a98cabf28463c63df74cdfe1d30dfdb5fbd8.tar taginfo-28d7a98cabf28463c63df74cdfe1d30dfdb5fbd8.tar.gz |
Javascript cleanup for homepage
Diffstat (limited to 'web')
-rw-r--r-- | web/public/js/taginfo.js | 31 | ||||
-rwxr-xr-x | web/taginfo.rb | 7 | ||||
-rw-r--r-- | web/views/index.erb | 11 | ||||
-rw-r--r-- | web/viewsjs/index.js.erb | 46 |
4 files changed, 47 insertions, 48 deletions
diff --git a/web/public/js/taginfo.js b/web/public/js/taginfo.js index 4585179..be57239 100644 --- a/web/public/js/taginfo.js +++ b/web/public/js/taginfo.js @@ -36,37 +36,6 @@ function resize_box() { wrapper.outerHeight(height); } -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 tags = tagcloud_data(), - cloud = ''; - for (var i=0; i < tags.length; i++) { - cloud += link(url_for_key(tags[i][0]), tags[i][0], { style: 'font-size: ' + tags[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 resize_grid(the_grid) { if (grids[the_grid]) { var grid = grids[the_grid][0].grid, diff --git a/web/taginfo.rb b/web/taginfo.rb index 174a197..409d60b 100755 --- a/web/taginfo.rb +++ b/web/taginfo.rb @@ -147,13 +147,6 @@ class Taginfo < Sinatra::Base #------------------------------------- get '/' do - # 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'] } erb :index end diff --git a/web/views/index.erb b/web/views/index.erb index d324f00..bf71425 100644 --- a/web/views/index.erb +++ b/web/views/index.erb @@ -37,13 +37,4 @@ </td> </tr> </table> -<% javascript do - JS.raw('function tagcloud_data() { return ' + @tags.map{ |tag| [tag['key'], tagcloud_size(tag)] }.to_json.gsub(/\],/, "],\n")) + "; }\n" + - JS.raw(<<"JAVASCRIPT") -function page_init() { - jQuery(window).resize(resize_home); - resize_home(); -} -JAVASCRIPT -end -%> +<% javascript "#{ r18n.locale.code }/index" %> diff --git a/web/viewsjs/index.js.erb b/web/viewsjs/index.js.erb new file mode 100644 index 0000000..575834b --- /dev/null +++ b/web/viewsjs/index.js.erb @@ -0,0 +1,46 @@ +<% +# 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(); +} |