Add link in hamburger menu to switch between mobile and desktop views

This commit is contained in:
Neil Lalonde 2013-08-29 15:19:28 -04:00
parent 4827634df9
commit 82bc6b677f
7 changed files with 36 additions and 6 deletions

View file

@ -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'));

View file

@ -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'));
}
});

View file

@ -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;

View file

@ -123,6 +123,17 @@
{{#titledLinkTo "list.latest" titleKey="filters.latest.help"}}{{i18n filters.latest.title}}{{/titledLinkTo}}
</li>
<li>{{faqLink}}</li>
{{#if mobileDevice}}
<li>
<a href="#" {{action toggleMobileView}}>
{{#if mobileView}}
{{i18n desktop_view}}
{{else}}
{{i18n mobile_view}}
{{/if}}
</a>
</li>
{{/if}}
</ul>
{{#if categories}}

View file

@ -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

View file

@ -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"

View file

@ -1,4 +1,4 @@
/*
*= require application
*= require desktop
*= require_tree .
*/