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.animate(false);
bootbox.backdrop(true); // clicking outside a bootbox modal closes it 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(){ setInterval(function(){
Discourse.Formatter.updateRelativeAge($('.relative-date')); Discourse.Formatter.updateRelativeAge($('.relative-date'));

View File

@ -22,7 +22,19 @@ Discourse.HeaderController = Discourse.Controller.extend({
showFavoriteButton: function() { showFavoriteButton: function() {
return Discourse.User.current() && !this.get('topic.isPrivateMessage'); 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) @returns {Template} the template (if found)
**/ **/
resolveTemplate: function(parsedName) { resolveTemplate: function(parsedName) {
if (Discourse.Session.currentProp('mobile')) { if (Discourse.Session.currentProp('mobileView')) {
var mobileParsedName = this.parseName(parsedName.fullName.replace("template:", "template:mobile/")); var mobileParsedName = this.parseName(parsedName.fullName.replace("template:", "template:mobile/"));
var mobileTemplate = this.findTemplate(mobileParsedName); var mobileTemplate = this.findTemplate(mobileParsedName);
if (mobileTemplate) return mobileTemplate; if (mobileTemplate) return mobileTemplate;

View File

@ -123,6 +123,17 @@
{{#titledLinkTo "list.latest" titleKey="filters.latest.help"}}{{i18n filters.latest.title}}{{/titledLinkTo}} {{#titledLinkTo "list.latest" titleKey="filters.latest.help"}}{{i18n filters.latest.title}}{{/titledLinkTo}}
</li> </li>
<li>{{faqLink}}</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> </ul>
{{#if categories}} {{#if categories}}

View File

@ -20,7 +20,7 @@ module ApplicationHelper
end end
def html_classes def html_classes
mobile_view? ? 'mobile' : '' "#{mobile_view? ? 'mobile-view' : ''} #{mobile_device? ? 'mobile-device' : ''}"
end end
def escape_unicode(javascript) def escape_unicode(javascript)
@ -109,7 +109,11 @@ module ApplicationHelper
if session[:mobile_view] if session[:mobile_view]
session[:mobile_view] == '1' session[:mobile_view] == '1'
else else
mobile_device?
end
end
def mobile_device?
request.user_agent =~ /Mobile|webOS/ request.user_agent =~ /Mobile|webOS/
end end
end
end end

View File

@ -94,6 +94,8 @@ en:
links: Links links: Links
faq: "FAQ" faq: "FAQ"
privacy_policy: "Privacy Policy" privacy_policy: "Privacy Policy"
mobile_view: "Mobile View"
desktop_view: "Desktop View"
you: "You" you: "You"
or: "or" or: "or"
now: "just now" now: "just now"

View File

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