From 009dec833f59fdaba864b564f12e17c2aa39cb02 Mon Sep 17 00:00:00 2001 From: Neil Lalonde <neillalonde@gmail.com> Date: Tue, 27 Aug 2013 13:41:36 -0400 Subject: [PATCH] Use Discourse.Resolver to load mobile templates when they exist --- app/assets/javascripts/discourse.js | 2 ++ app/assets/javascripts/discourse/ember/resolver.js | 10 +++++++++- .../discourse/templates/mobile/topic.js.handlebars | 9 +++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 app/assets/javascripts/discourse/templates/mobile/topic.js.handlebars diff --git a/app/assets/javascripts/discourse.js b/app/assets/javascripts/discourse.js index 55d09cc99..d45c22fa3 100644 --- a/app/assets/javascripts/discourse.js +++ b/app/assets/javascripts/discourse.js @@ -143,6 +143,8 @@ Discourse = Ember.Application.createWithMixins(Discourse.Ajax, { bootbox.animate(false); bootbox.backdrop(true); // clicking outside a bootbox modal closes it + this.set('mobile', $html.hasClass('mobile')); + setInterval(function(){ Discourse.Formatter.updateRelativeAge($('.relative-date')); },60 * 1000); diff --git a/app/assets/javascripts/discourse/ember/resolver.js b/app/assets/javascripts/discourse/ember/resolver.js index ab854b88e..50c4c1e7d 100644 --- a/app/assets/javascripts/discourse/ember/resolver.js +++ b/app/assets/javascripts/discourse/ember/resolver.js @@ -16,6 +16,15 @@ Discourse.Resolver = Ember.DefaultResolver.extend({ @returns {Template} the template (if found) **/ resolveTemplate: function(parsedName) { + if (Discourse.get('mobile')) { + var mobileParsedName = this.parseName(parsedName.fullName.replace("template:", "template:mobile/")); + var mobileTemplate = this.findTemplate(mobileParsedName); + if (mobileTemplate) return mobileTemplate; + } + return this.findTemplate(parsedName) || Ember.TEMPLATES.not_found; + }, + + findTemplate: function(parsedName) { var resolvedTemplate = this._super(parsedName); if (resolvedTemplate) { return resolvedTemplate; } @@ -36,7 +45,6 @@ Discourse.Resolver = Ember.DefaultResolver.extend({ resolvedTemplate = Ember.TEMPLATES[decamelized]; if (resolvedTemplate) { return resolvedTemplate; } } - return Ember.TEMPLATES.not_found; } }); \ No newline at end of file diff --git a/app/assets/javascripts/discourse/templates/mobile/topic.js.handlebars b/app/assets/javascripts/discourse/templates/mobile/topic.js.handlebars new file mode 100644 index 000000000..f2a45cebe --- /dev/null +++ b/app/assets/javascripts/discourse/templates/mobile/topic.js.handlebars @@ -0,0 +1,9 @@ +{{#if postStream.loaded}} + <div class='container'> + Mobile Topic Page Loaded! + </div> +{{else}} + <div class='container'> + <div class='spinner'>{{i18n loading}}</div> + </div> +{{/if}} \ No newline at end of file