diff --git a/app/assets/javascripts/discourse.js b/app/assets/javascripts/discourse.js index 0e197733ea4..728f0ff5557 100644 --- a/app/assets/javascripts/discourse.js +++ b/app/assets/javascripts/discourse.js @@ -143,7 +143,8 @@ Discourse = Ember.Application.createWithMixins(Discourse.Ajax, { bootbox.animate(false); bootbox.backdrop(true); // clicking outside a bootbox modal closes it - Discourse.Session.currentProp('mobile', $html.hasClass('mobile')) + Discourse.Session.currentProp('mobileDevice', $html.hasClass('mobile-device')); + Discourse.Session.currentProp('mobileView', $html.hasClass('mobile-view')); setInterval(function(){ Discourse.Formatter.updateRelativeAge($('.relative-date')); diff --git a/app/assets/javascripts/discourse/controllers/header_controller.js b/app/assets/javascripts/discourse/controllers/header_controller.js index d06849dd3f2..790a299ad83 100644 --- a/app/assets/javascripts/discourse/controllers/header_controller.js +++ b/app/assets/javascripts/discourse/controllers/header_controller.js @@ -22,7 +22,19 @@ Discourse.HeaderController = Discourse.Controller.extend({ showFavoriteButton: function() { return Discourse.User.current() && !this.get('topic.isPrivateMessage'); - }.property('topic.isPrivateMessage') + }.property('topic.isPrivateMessage'), + + mobileDevice: function() { + return Discourse.Session.currentProp('mobileDevice'); + }.property(), + + mobileView: function() { + return Discourse.Session.currentProp('mobileView'); + }.property(), + + toggleMobileView: function() { + window.location.assign(window.location.pathname + '?mobile_view=' + (Discourse.Session.currentProp('mobileView') ? '0' : '1')); + } }); diff --git a/app/assets/javascripts/discourse/ember/resolver.js b/app/assets/javascripts/discourse/ember/resolver.js index 25d5a98737c..00a09238b41 100644 --- a/app/assets/javascripts/discourse/ember/resolver.js +++ b/app/assets/javascripts/discourse/ember/resolver.js @@ -16,7 +16,7 @@ Discourse.Resolver = Ember.DefaultResolver.extend({ @returns {Template} the template (if found) **/ resolveTemplate: function(parsedName) { - if (Discourse.Session.currentProp('mobile')) { + if (Discourse.Session.currentProp('mobileView')) { var mobileParsedName = this.parseName(parsedName.fullName.replace("template:", "template:mobile/")); var mobileTemplate = this.findTemplate(mobileParsedName); if (mobileTemplate) return mobileTemplate; diff --git a/app/assets/javascripts/discourse/templates/header.js.handlebars b/app/assets/javascripts/discourse/templates/header.js.handlebars index 7349a442a93..b73f1bf83d7 100644 --- a/app/assets/javascripts/discourse/templates/header.js.handlebars +++ b/app/assets/javascripts/discourse/templates/header.js.handlebars @@ -123,6 +123,17 @@ {{#titledLinkTo "list.latest" titleKey="filters.latest.help"}}{{i18n filters.latest.title}}{{/titledLinkTo}}
  • {{faqLink}}
  • + {{#if mobileDevice}} +
  • + + {{#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 92f0ba79146..72e654e48f6 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -20,7 +20,7 @@ module ApplicationHelper end def html_classes - mobile_view? ? 'mobile' : '' + "#{mobile_view? ? 'mobile-view' : ''} #{mobile_device? ? 'mobile-device' : ''}" end def escape_unicode(javascript) @@ -109,7 +109,11 @@ module ApplicationHelper if session[:mobile_view] session[:mobile_view] == '1' else - request.user_agent =~ /Mobile|webOS/ + mobile_device? end end + + def mobile_device? + request.user_agent =~ /Mobile|webOS/ + end end diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 07a961884e7..94c92e1c6f9 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -94,6 +94,8 @@ en: links: Links faq: "FAQ" privacy_policy: "Privacy Policy" + mobile_view: "Mobile View" + desktop_view: "Desktop View" you: "You" or: "or" now: "just now" diff --git a/test/stylesheets/test_helper.css b/test/stylesheets/test_helper.css index 424b07f8025..ecc7a46d825 100644 --- a/test/stylesheets/test_helper.css +++ b/test/stylesheets/test_helper.css @@ -1,4 +1,4 @@ /* - *= require application + *= require desktop *= require_tree . */