From c6ba4011089fc1dd964ef42edd90deff59104866 Mon Sep 17 00:00:00 2001 From: Jochen Topf Date: Sat, 19 Jan 2013 12:05:43 +0100 Subject: Include fewer js files --- web/lib/javascript.rb | 24 +++++++++++++++++++++++- web/lib/ui/keys_tags.rb | 3 ++- web/lib/ui/relation.rb | 2 +- web/lib/ui/reports.rb | 1 + web/lib/ui/search.rb | 1 + web/taginfo.rb | 22 +++++++++++++--------- web/views/index.erb | 3 +-- web/views/reports/characters_in_keys.erb | 2 +- web/views/reports/key_lengths.erb | 2 +- 9 files changed, 44 insertions(+), 16 deletions(-) diff --git a/web/lib/javascript.rb b/web/lib/javascript.rb index 27b9790..18e6b50 100644 --- a/web/lib/javascript.rb +++ b/web/lib/javascript.rb @@ -6,11 +6,33 @@ def javascript(url=nil, &block) end def javascript_tags - @javascript.map{ |js| js.to_html }.join("\n") + @javascript.flatten.uniq.map{ |js| js.to_html }.join("\n") +end + +def javascript_for(*ids) + (@javascript ||= [] ) << Javascript.init(ids) end class Javascript + @@js_files = { + :jquery => [ 'jquery-1.9.0.min', 'jquery-ui-1.9.2.custom.min', 'customSelect.jquery.min', 'jquery.tipsy-minified' ], + :taginfo => [ 'taginfo' ], + :flexigrid => [ 'jquery-migrate-1.0.0.min', 'flexigrid-minified' ], + :d3 => [ 'd3/d3.v3.min' ], + :d3_cloud => [ 'd3/d3.layout.cloud' ], + } + + def self.init(ids) + js = [] + ids.each do |id| + @@js_files[id].each do |file| + js << self.new(file) + end + end + js + end + def initialize(file) if file.nil? c = '' diff --git a/web/lib/ui/keys_tags.rb b/web/lib/ui/keys_tags.rb index d944e91..9e2962f 100644 --- a/web/lib/ui/keys_tags.rb +++ b/web/lib/ui/keys_tags.rb @@ -62,7 +62,7 @@ class Taginfo < Sinatra::Base @img_width = TaginfoConfig.get('geodistribution.width') * TaginfoConfig.get('geodistribution.scale_image') @img_height = TaginfoConfig.get('geodistribution.height') * TaginfoConfig.get('geodistribution.scale_image') - javascript 'd3/d3.v3.min' + javascript_for(:flexigrid, :d3) javascript "#{ r18n.locale.code }/key" erb :key end @@ -117,6 +117,7 @@ class Taginfo < Sinatra::Base @image_url = build_image_url(row) end + javascript_for(:flexigrid) javascript "#{ r18n.locale.code }/tag" erb :tag end diff --git a/web/lib/ui/relation.rb b/web/lib/ui/relation.rb index 27a0ea1..d2df9cc 100644 --- a/web/lib/ui/relation.rb +++ b/web/lib/ui/relation.rb @@ -50,7 +50,7 @@ class Taginfo < Sinatra::Base end end - javascript 'd3/d3.v3.min' + javascript_for(:flexigrid, :d3) javascript "#{ r18n.locale.code }/relation" erb :relation end diff --git a/web/lib/ui/reports.rb b/web/lib/ui/reports.rb index 5096a4f..e3698e1 100644 --- a/web/lib/ui/reports.rb +++ b/web/lib/ui/reports.rb @@ -13,6 +13,7 @@ class Taginfo < Sinatra::Base if File.exists?("viewsjs/reports/#{ report.name }.js.erb") javascript "#{ r18n.locale.code }/reports/#{ report.name }" end + javascript_for(:flexigrid) erb ('reports/' + report.name).to_sym end end diff --git a/web/lib/ui/search.rb b/web/lib/ui/search.rb index 1aac663..a5c5b7e 100644 --- a/web/lib/ui/search.rb +++ b/web/lib/ui/search.rb @@ -7,6 +7,7 @@ class Taginfo < Sinatra::Base javascript "#{ r18n.locale.code }/search" @query = params[:q] + javascript_for(:flexigrid) if @query =~ /(.*)=(.*)/ erb :search_tags else diff --git a/web/taginfo.rb b/web/taginfo.rb index ab0cc85..c4c60f8 100755 --- a/web/taginfo.rb +++ b/web/taginfo.rb @@ -102,14 +102,9 @@ class Taginfo < Sinatra::Base params[:locale] = request.cookies['taginfo_locale'] end - javascript 'jquery-1.9.0.min' - javascript 'jquery-migrate-1.0.0.min' # needed for flexigrid - javascript 'jquery-ui-1.9.2.custom.min' - javascript 'customSelect.jquery.min' - javascript 'jquery.tipsy-minified' - javascript 'flexigrid-minified' + javascript_for(:jquery) + javascript_for(:taginfo) javascript r18n.locale.code + '/texts' - javascript 'taginfo' # set to immediate expire on normal pages # (otherwise switching languages doesn't work) @@ -155,9 +150,9 @@ class Taginfo < Sinatra::Base #------------------------------------- - %w(about download keys relations sources tags).each do |page| + %w(about download sources).each do |page| get '/' + page do - @title = (page =~ /^(keys|tags|relations)$/) ? t.osm[page] : t.taginfo[page] + @title = t.taginfo[page] if File.exists?("viewsjs/#{ page }.js.erb") javascript "#{ r18n.locale.code }/#{ page }" end @@ -165,6 +160,15 @@ class Taginfo < Sinatra::Base end end + %w(keys tags relations).each do |page| + get '/' + page do + @title = t.osm[page] + javascript_for(:flexigrid) + javascript "#{ r18n.locale.code }/#{ page }" + erb page.to_sym + end + end + #------------------------------------- get %r{^/js/([a-z][a-z])/(.*).js$} do |lang, js| diff --git a/web/views/index.erb b/web/views/index.erb index 6dbc6b7..381fa94 100644 --- a/web/views/index.erb +++ b/web/views/index.erb @@ -54,5 +54,4 @@ -<% javascript 'd3/d3.v3.min' %> -<% javascript 'd3/d3.layout.cloud' %> +<% javascript_for(:d3, :d3_cloud) %> diff --git a/web/views/reports/characters_in_keys.erb b/web/views/reports/characters_in_keys.erb index 3fe8aba..9b1cba3 100644 --- a/web/views/reports/characters_in_keys.erb +++ b/web/views/reports/characters_in_keys.erb @@ -53,4 +53,4 @@ -<% javascript 'd3/d3.v3.min' %> +<% javascript_for(:d3) %> diff --git a/web/views/reports/key_lengths.erb b/web/views/reports/key_lengths.erb index e6768e7..1796cf0 100644 --- a/web/views/reports/key_lengths.erb +++ b/web/views/reports/key_lengths.erb @@ -18,4 +18,4 @@
-<% javascript 'd3/d3.v3.min' %> +<% javascript_for(:d3) %> -- cgit v1.2.3