diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a9b6abbc9..c1f920181 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -26,6 +26,7 @@ class ApplicationController < ActionController::Base end end + before_filter :set_mobile_view before_filter :inject_preview_style before_filter :block_if_maintenance_mode before_filter :authorize_mini_profiler @@ -117,6 +118,10 @@ class ApplicationController < ActionController::Base end end + def set_mobile_view + session[:mobile_view] = params[:mobile_view] if params.has_key?(:mobile_view) + end + def inject_preview_style style = request['preview-style'] diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 606936b19..92f0ba791 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -19,6 +19,10 @@ module ApplicationHelper end end + def html_classes + mobile_view? ? 'mobile' : '' + end + def escape_unicode(javascript) if javascript javascript.gsub(/\342\200\250/u, ' ').gsub(/(<\/)/u, '\u003C/').html_safe @@ -100,4 +104,12 @@ module ApplicationHelper def login_path return "#{Discourse::base_uri}/login" end + + def mobile_view? + if session[:mobile_view] + session[:mobile_view] == '1' + else + request.user_agent =~ /Mobile|webOS/ + end + end end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 49bde9e01..78246fc03 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,5 +1,5 @@ - +