diff --git a/app/assets/javascripts/discourse/controllers/header_controller.js b/app/assets/javascripts/discourse/controllers/header_controller.js
index 4612ee719..3d3699493 100644
--- a/app/assets/javascripts/discourse/controllers/header_controller.js
+++ b/app/assets/javascripts/discourse/controllers/header_controller.js
@@ -32,6 +32,10 @@ Discourse.HeaderController = Discourse.Controller.extend({
return Discourse.Mobile.mobileView;
}.property(),
+ showMobileToggle: function() {
+ return Discourse.SiteSettings.enable_mobile_theme;
+ }.property(),
+
toggleMobileView: function() {
Discourse.Mobile.toggleMobileView();
}
diff --git a/app/assets/javascripts/discourse/templates/header.js.handlebars b/app/assets/javascripts/discourse/templates/header.js.handlebars
index ef4df13bd..b0c499737 100644
--- a/app/assets/javascripts/discourse/templates/header.js.handlebars
+++ b/app/assets/javascripts/discourse/templates/header.js.handlebars
@@ -123,15 +123,17 @@
{{#titledLinkTo "list.latest" titleKey="filters.latest.help"}}{{i18n filters.latest.title}}{{/titledLinkTo}}
{{faqLink}}
-
-
- {{#if mobileView}}
- {{i18n desktop_view}}
- {{else}}
- {{i18n mobile_view}}
- {{/if}}
-
-
+ {{#if showMobileToggle}}
+
+
+ {{#if mobileView}}
+ {{i18n desktop_view}}
+ {{else}}
+ {{i18n mobile_view}}
+ {{/if}}
+
+
+ {{/if}}
{{#if categories}}
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 59503ed21..8cfbc5291 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -109,6 +109,7 @@ module ApplicationHelper
end
def mobile_view?
+ return false unless SiteSetting.enable_mobile_theme
if session[:mobile_view]
session[:mobile_view] == '1'
else
diff --git a/app/models/site_setting.rb b/app/models/site_setting.rb
index 9bf4e63d0..849890ad7 100644
--- a/app/models/site_setting.rb
+++ b/app/models/site_setting.rb
@@ -261,6 +261,8 @@ class SiteSetting < ActiveRecord::Base
setting(:sequential_replies_threshold, 2)
+ client_setting(:enable_mobile_theme, true)
+
def self.generate_api_key!
self.api_key = SecureRandom.hex(32)
end
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index ede9bab57..22f8a53cb 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -696,6 +696,8 @@ en:
sequential_replies_threshold: "The amount of posts a user has to make in a row in a topic before being notified"
+ enable_mobile_theme: "Mobile devices use a mobile-friendly theme, with the ability to switch to the full site. Disable this if you want to use a custom stylesheet that is fully responsive."
+
notification_types:
mentioned: "%{display_username} mentioned you in %{link}"
liked: "%{display_username} liked your post in %{link}"
diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb
index f86fcff8e..feeb04b0e 100644
--- a/spec/helpers/application_helper_spec.rb
+++ b/spec/helpers/application_helper_spec.rb
@@ -3,36 +3,70 @@ require 'spec_helper'
describe ApplicationHelper do
describe 'mobile_view?' do
- it "is true if mobile_view is '1' in the session" do
- session[:mobile_view] = '1'
- helper.mobile_view?.should be_true
- end
-
- it "is false if mobile_view is '0' in the session" do
- session[:mobile_view] = '0'
- helper.mobile_view?.should be_false
- end
-
- context "mobile_view is not set" do
- it "is false if user agent is not mobile" do
- controller.request.stubs(:user_agent).returns('Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.17 Safari/537.36')
- helper.mobile_view?.should be_false
+ context "enable_mobile_theme is true" do
+ before do
+ SiteSetting.stubs(:enable_mobile_theme).returns(true)
end
- it "is true for iPhone" do
- controller.request.stubs(:user_agent).returns('Mozilla/5.0 (iPhone; U; ru; CPU iPhone OS 4_2_1 like Mac OS X; ru) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148a Safari/6533.18.5')
+ it "is true if mobile_view is '1' in the session" do
+ session[:mobile_view] = '1'
helper.mobile_view?.should be_true
end
- it "is false for iPad" do
- controller.request.stubs(:user_agent).returns("Mozilla/5.0 (iPad; CPU OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B176 Safari/7534.48.3")
+ it "is false if mobile_view is '0' in the session" do
+ session[:mobile_view] = '0'
helper.mobile_view?.should be_false
end
- it "is false for Android tablet" do
- controller.request.stubs(:user_agent).returns("Mozilla/5.0 (Linux; Android 4.1.2; Nexus 7 Build/JZ054K) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19")
+ context "mobile_view is not set" do
+ it "is false if user agent is not mobile" do
+ controller.request.stubs(:user_agent).returns('Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.17 Safari/537.36')
+ helper.mobile_view?.should be_false
+ end
+
+ it "is true for iPhone" do
+ controller.request.stubs(:user_agent).returns('Mozilla/5.0 (iPhone; U; ru; CPU iPhone OS 4_2_1 like Mac OS X; ru) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148a Safari/6533.18.5')
+ helper.mobile_view?.should be_true
+ end
+
+ it "is false for iPad" do
+ controller.request.stubs(:user_agent).returns("Mozilla/5.0 (iPad; CPU OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B176 Safari/7534.48.3")
+ helper.mobile_view?.should be_false
+ end
+
+ it "is false for Android tablet" do
+ controller.request.stubs(:user_agent).returns("Mozilla/5.0 (Linux; Android 4.1.2; Nexus 7 Build/JZ054K) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19")
+ helper.mobile_view?.should be_false
+ end
+ end
+ end
+
+ context "enable_mobile_theme is false" do
+ before do
+ SiteSetting.stubs(:enable_mobile_theme).returns(false)
+ end
+
+ it "is false if mobile_view is '1' in the session" do
+ session[:mobile_view] = '1'
helper.mobile_view?.should be_false
end
+
+ it "is false if mobile_view is '0' in the session" do
+ session[:mobile_view] = '0'
+ helper.mobile_view?.should be_false
+ end
+
+ context "mobile_view is not set" do
+ it "is false if user agent is not mobile" do
+ controller.request.stubs(:user_agent).returns('Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.17 Safari/537.36')
+ helper.mobile_view?.should be_false
+ end
+
+ it "is false for iPhone" do
+ controller.request.stubs(:user_agent).returns('Mozilla/5.0 (iPhone; U; ru; CPU iPhone OS 4_2_1 like Mac OS X; ru) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148a Safari/6533.18.5')
+ helper.mobile_view?.should be_false
+ end
+ end
end
end