diff --git a/app/assets/javascripts/discourse-common/resolver.js.es6 b/app/assets/javascripts/discourse-common/resolver.js.es6 index 15c099cc28c..a3068b91b1e 100644 --- a/app/assets/javascripts/discourse-common/resolver.js.es6 +++ b/app/assets/javascripts/discourse-common/resolver.js.es6 @@ -9,6 +9,13 @@ var LOADING_WHITELIST = ['badges', 'userActivity', 'userPrivateMessages', 'admin var _dummyRoute; var _loadingView; + +const _options = {}; + +export function setResolverOption(name, value) { + _options[name] = value; +} + function loadingResolver(cb) { return function(parsedName) { var fullNameWithoutType = parsedName.fullNameWithoutType; @@ -158,14 +165,14 @@ export function buildResolver(baseName) { }, findPluginMobileTemplate(parsedName) { - if (this.mobileView) { + if (_options.mobileView) { var pluginParsedName = this.parseName(parsedName.fullName.replace("template:", "template:javascripts/mobile/")); return this.findTemplate(pluginParsedName); } }, findMobileTemplate(parsedName) { - if (this.mobileView) { + if (_options.mobileView) { var mobileParsedName = this.parseName(parsedName.fullName.replace("template:", "template:mobile/")); return this.findTemplate(mobileParsedName); } diff --git a/app/assets/javascripts/discourse/initializers/mobile.js.es6 b/app/assets/javascripts/discourse/initializers/mobile.js.es6 index 2ac54497b2c..8c057a425fc 100644 --- a/app/assets/javascripts/discourse/initializers/mobile.js.es6 +++ b/app/assets/javascripts/discourse/initializers/mobile.js.es6 @@ -1,18 +1,18 @@ import Mobile from 'discourse/lib/mobile'; +import { setResolverOption } from 'discourse-common/resolver'; // Initializes the `Mobile` helper object. export default { name: 'mobile', after: 'inject-objects', - initialize(container, app) { + initialize(container) { Mobile.init(); const site = container.lookup('site:main'); site.set('mobileView', Mobile.mobileView); site.set('isMobileDevice', Mobile.isMobileDevice); - // This is a bit weird but you can't seem to inject into the resolver? - app.registry.resolver.__resolver__.mobileView = Mobile.mobileView; + setResolverOption('mobileView', Mobile.mobileView); } }; diff --git a/test/javascripts/ember/resolver-test.js.es6 b/test/javascripts/ember/resolver-test.js.es6 index 1c81f96df5b..648729d6bd3 100644 --- a/test/javascripts/ember/resolver-test.js.es6 +++ b/test/javascripts/ember/resolver-test.js.es6 @@ -1,4 +1,4 @@ -import { buildResolver } from 'discourse-common/resolver'; +import { setResolverOption, buildResolver } from 'discourse-common/resolver'; let originalTemplates; let resolver; @@ -92,7 +92,7 @@ test("resolves mobile templates to 'mobile/' namespace", function() { "baz" ]); - resolver.mobileView = true; + setResolverOption('mobileView', true); lookupTemplate("template:foo", "mobile/foo", "finding mobile version even if normal one is not present"); lookupTemplate("template:bar", "mobile/bar", "preferring mobile version when both mobile and normal versions are present");