From ba984009f803f51c6d1e966e10b429b904b171dc Mon Sep 17 00:00:00 2001 From: maxwell Date: Thu, 1 Jul 2010 16:38:32 -0700 Subject: [PATCH] added chrome frame --- app/views/layouts/application.html.haml | 3 +- config.ru | 2 + lib/chrome_frame.rb | 63 +++++++++++++++++++++++++ public/javascripts/google.js | 7 +-- 4 files changed, 67 insertions(+), 8 deletions(-) create mode 100644 lib/chrome_frame.rb diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 03053b705..d2a037589 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -5,12 +5,11 @@ = "diaspora " = "- #{User.first.real_name}" if User.first %meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/ - %meta{"http-equiv"=> "X-UA-Compatible", :content =>"chrome=1" } = stylesheet_link_tag "blueprint/screen", :media => 'screen' = stylesheet_link_tag "application" /= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" - = javascript_include_tag 'jquery142', 'rails', 'view', 'publisher', 'http://ajax.googleapis.com/ajax/libs/chrome-frame/1/CFInstall.min.js', 'google_a' + = javascript_include_tag 'jquery142', 'rails', 'view', 'publisher', 'google_a' = javascript_include_tag 'tiny_mce/tiny_mce', 'jquery.infieldlabel' = render 'js/websocket_js' diff --git a/config.ru b/config.ru index 10d1ee578..84859db97 100644 --- a/config.ru +++ b/config.ru @@ -2,4 +2,6 @@ require ::File.expand_path('../config/environment', __FILE__) #use Rack::FiberPool +require 'lib/chrome_frame' +use Rack::ChromeFrame run Diaspora::Application diff --git a/lib/chrome_frame.rb b/lib/chrome_frame.rb new file mode 100644 index 000000000..eeba58312 --- /dev/null +++ b/lib/chrome_frame.rb @@ -0,0 +1,63 @@ +module Rack + class ChromeFrame + + def initialize(app, options={}) + @app = app + @options = options + end + + def call(env) + + if env['HTTP_USER_AGENT'] =~ /MSIE/ + if env['HTTP_USER_AGENT'] =~ /chromeframe/ + status, headers, response = @app.call(env) + new_body = insert_tag(build_response_body(response)) + new_headers = recalculate_body_length(headers, new_body) + return [status, new_headers, new_body] + elsif @options[:minimum].nil? or ie_version(env['HTTP_USER_AGENT']) < @options[:minimum] + html = <<-HTML + + + + + You need to use a real browser in order to use Diaspora! + + +
+ + + + + HTML + return [200, {'Content-Type' => 'text/html', 'Content-Length' => html.size.to_s}, Rack::Response.new([html])] + end + end + @app.call(env) + end + + def build_response_body(response) + response_body = "" + response.each { |part| response_body += part } + response_body + end + + def recalculate_body_length(headers, body) + new_headers = headers + new_headers["Content-Length"] = body.length.to_s + new_headers + end + + def insert_tag(body) + head = <<-HEAD + + HEAD + + body.gsub!('', "\n" + head ) + body + end + + def ie_version(ua_string) + ua_string.match(/MSIE (\S+)/)[1].to_f + end + end +end \ No newline at end of file diff --git a/public/javascripts/google.js b/public/javascripts/google.js index 5fa635656..b544a8075 100644 --- a/public/javascripts/google.js +++ b/public/javascripts/google.js @@ -7,9 +7,4 @@ _gaq.push(['_trackPageview']); var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); -})(); - -CFInstall.check({ - mode: "overlay", - destination: "http://www.waikiki.com" -}); \ No newline at end of file +})(); \ No newline at end of file