Remove Discourse.Mobile constants

This commit is contained in:
Robin Ward 2016-02-18 11:53:25 -05:00
parent ef75f87c8b
commit 849c99f83d
31 changed files with 205 additions and 185 deletions

View file

@ -12,8 +12,8 @@ export default Ember.Component.extend({
return !c.get('parentCategory'); return !c.get('parentCategory');
}), }),
hidden: function(){ hidden: function() {
return Discourse.Mobile.mobileView && !this.get('category'); return this.site.mobileView && !this.get('category');
}.property('category'), }.property('category'),
firstCategory: function() { firstCategory: function() {

View file

@ -18,7 +18,7 @@ export default Ember.Component.extend({
@on('init') @on('init')
_setupPreview() { _setupPreview() {
const val = (Discourse.Mobile.mobileView ? false : (this.keyValueStore.get('composer.showPreview') || 'true')); const val = (this.site.mobileView ? false : (this.keyValueStore.get('composer.showPreview') || 'true'));
this.set('showPreview', val === 'true'); this.set('showPreview', val === 'true');
}, },
@ -218,7 +218,7 @@ export default Ember.Component.extend({
} }
}); });
if (Discourse.Mobile.mobileView) { if (this.site.mobileView) {
this.$(".mobile-file-upload").on("click.uploader", function () { this.$(".mobile-file-upload").on("click.uploader", function () {
// redirect the click on the hidden file input // redirect the click on the hidden file input
$("#mobile-uploader").click(); $("#mobile-uploader").click();

View file

@ -25,7 +25,9 @@ const OP = {
const _createCallbacks = []; const _createCallbacks = [];
function Toolbar() { class Toolbar {
constructor(site) {
this.shortcuts = {}; this.shortcuts = {};
this.groups = [ this.groups = [
@ -106,7 +108,7 @@ function Toolbar() {
perform: e => e.addText("\n\n----------\n") perform: e => e.addText("\n\n----------\n")
}); });
if (Discourse.Mobile.mobileView) { if (site.mobileView) {
this.groups.push({group: 'mobileExtras', buttons: []}); this.groups.push({group: 'mobileExtras', buttons: []});
this.addButton({ this.addButton({
@ -119,9 +121,9 @@ function Toolbar() {
} }
this.groups[this.groups.length-1].lastGroup = true; this.groups[this.groups.length-1].lastGroup = true;
}; }
Toolbar.prototype.addButton = function(button) { addButton(button) {
const g = this.groups.findProperty('group', button.group); const g = this.groups.findProperty('group', button.group);
if (!g) { if (!g) {
throw `Couldn't find toolbar group ${button.group}`; throw `Couldn't find toolbar group ${button.group}`;
@ -171,7 +173,8 @@ Toolbar.prototype.addButton = function(button) {
} else { } else {
g.buttons.push(createdButton); g.buttons.push(createdButton);
} }
}; }
}
export function onToolbarCreate(func) { export function onToolbarCreate(func) {
_createCallbacks.push(func); _createCallbacks.push(func);
@ -237,7 +240,7 @@ export default Ember.Component.extend({
@computed @computed
toolbar() { toolbar() {
const toolbar = new Toolbar(); const toolbar = new Toolbar(this.site);
_createCallbacks.forEach(cb => cb(toolbar)); _createCallbacks.forEach(cb => cb(toolbar));
this.sendAction('extraButtons', toolbar); this.sendAction('extraButtons', toolbar);
return toolbar; return toolbar;

View file

@ -10,17 +10,17 @@ export default Ember.Component.extend({
@computed() @computed()
showKeyboardShortcuts() { showKeyboardShortcuts() {
return !Discourse.Mobile.mobileView && !this.capabilities.touch; return !this.site.mobileView && !this.capabilities.touch;
}, },
@computed() @computed()
showMobileToggle() { showMobileToggle() {
return Discourse.Mobile.mobileView || (this.siteSettings.enable_mobile_theme && this.capabilities.touch); return this.site.mobileView || (this.siteSettings.enable_mobile_theme && this.capabilities.touch);
}, },
@computed() @computed()
mobileViewLinkTextKey() { mobileViewLinkTextKey() {
return Discourse.Mobile.mobileView ? "desktop_view" : "mobile_view"; return this.site.mobileView ? "desktop_view" : "mobile_view";
}, },
@computed() @computed()
@ -68,7 +68,7 @@ export default Ember.Component.extend({
this.sendAction('showKeyboardAction'); this.sendAction('showKeyboardAction');
}, },
toggleMobileView() { toggleMobileView() {
Discourse.Mobile.toggleMobileView(); this.site.toggleMobileView();
} }
} }
}); });

View file

@ -17,7 +17,7 @@ export default Ember.Component.extend({
if (this.siteSettings.login_required && !this.currentUser) { if (this.siteSettings.login_required && !this.currentUser) {
this.sendAction('loginAction'); this.sendAction('loginAction');
} else { } else {
if (Discourse.Mobile.mobileView && this.get('mobileAction')) { if (this.site.mobileView && this.get('mobileAction')) {
this.sendAction('mobileAction'); this.sendAction('mobileAction');
return; return;
} }

View file

@ -14,11 +14,11 @@ export default Ember.Component.extend({
}.property('targetUrl'), }.property('targetUrl'),
showSmallLogo: function() { showSmallLogo: function() {
return !Discourse.Mobile.mobileView && this.get("minimized"); return !this.site.mobileView && this.get("minimized");
}.property("minimized"), }.property("minimized"),
showMobileLogo: function() { showMobileLogo: function() {
return Discourse.Mobile.mobileView && !Ember.isBlank(this.get('mobileBigLogoUrl')); return this.site.mobileView && !Ember.isBlank(this.get('mobileBigLogoUrl'));
}.property(), }.property(),
smallLogoUrl: setting('logo_small_url'), smallLogoUrl: setting('logo_small_url'),

View file

@ -120,17 +120,17 @@ export default Ember.Component.extend({
@computed() @computed()
showKeyboardShortcuts() { showKeyboardShortcuts() {
return !Discourse.Mobile.mobileView && !this.capabilities.touch; return !this.site.mobileView && !this.capabilities.touch;
}, },
@computed() @computed()
showMobileToggle() { showMobileToggle() {
return Discourse.Mobile.mobileView || (this.siteSettings.enable_mobile_theme && this.capabilities.touch); return this.site.mobileView || (this.siteSettings.enable_mobile_theme && this.capabilities.touch);
}, },
@computed() @computed()
mobileViewLinkTextKey() { mobileViewLinkTextKey() {
return Discourse.Mobile.mobileView ? "desktop_view" : "mobile_view"; return this.site.mobileView ? "desktop_view" : "mobile_view";
}, },
@computed() @computed()

View file

@ -19,7 +19,7 @@ export default Ember.Component.extend({
}.property(), }.property(),
skipHeader: function() { skipHeader: function() {
return Discourse.Mobile.mobileView; return this.site.mobileView;
}.property(), }.property(),
showLikes: function(){ showLikes: function(){

View file

@ -10,7 +10,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
revisionsTextKey: "post.revisions.controls.comparing_previous_to_current_out_of_total", revisionsTextKey: "post.revisions.controls.comparing_previous_to_current_out_of_total",
_changeViewModeOnMobile: function() { _changeViewModeOnMobile: function() {
if (Discourse.Mobile.mobileView) { this.set("viewMode", "inline"); } if (this.site.mobileView) { this.set("viewMode", "inline"); }
}.on("init"), }.on("init"),
refresh(postId, postVersion) { refresh(postId, postVersion) {

View file

@ -61,8 +61,10 @@ export default Ember.Controller.extend({
// containing a single invisible character // containing a single invisible character
markerElement.appendChild(document.createTextNode("\ufeff")); markerElement.appendChild(document.createTextNode("\ufeff"));
const isMobileDevice = this.site.isMobileDevice;
// collapse the range at the beginning/end of the selection // collapse the range at the beginning/end of the selection
range.collapse(!Discourse.Mobile.isMobileDevice); range.collapse(!isMobileDevice);
// and insert it at the start of our selection range // and insert it at the start of our selection range
range.insertNode(markerElement); range.insertNode(markerElement);
@ -83,7 +85,7 @@ export default Ember.Controller.extend({
let topOff = markerOffset.top; let topOff = markerOffset.top;
let leftOff = markerOffset.left; let leftOff = markerOffset.left;
if (Discourse.Mobile.isMobileDevice) { if (isMobileDevice) {
topOff = topOff + 20; topOff = topOff + 20;
leftOff = Math.min(leftOff + 10, $(window).width() - $quoteButton.outerWidth()); leftOff = Math.min(leftOff + 10, $(window).width() - $quoteButton.outerWidth());
} else { } else {

View file

@ -45,7 +45,7 @@ export default Ember.Controller.extend({
} }
// Don't show on mobile // Don't show on mobile
if (Discourse.Mobile.mobileView) { if (this.site.mobileView) {
const url = "/users/" + username; const url = "/users/" + username;
DiscourseURL.routeTo(url); DiscourseURL.routeTo(url);
return; return;

View file

@ -12,7 +12,7 @@ export default Ember.Controller.extend({
bulkSelectEnabled: Em.computed.alias('controllers.user-topics-list.bulkSelectEnabled'), bulkSelectEnabled: Em.computed.alias('controllers.user-topics-list.bulkSelectEnabled'),
mobileView: function() { mobileView: function() {
return Discourse.Mobile.mobileView; return this.site.mobileView;
}.property(), }.property(),
showNewPM: function(){ showNewPM: function(){

View file

@ -141,7 +141,7 @@ export default Ember.DefaultResolver.extend({
}, },
findMobileTemplate(parsedName) { findMobileTemplate(parsedName) {
if (Discourse.Mobile.mobileView) { if (this.mobileView) {
var mobileParsedName = this.parseName(parsedName.fullName.replace("template:", "template:mobile/")); var mobileParsedName = this.parseName(parsedName.fullName.replace("template:", "template:mobile/"));
return this.findTemplate(mobileParsedName); return this.findTemplate(mobileParsedName);
} }

View file

@ -1,7 +1,7 @@
export default { export default {
name: 'ensure-image-dimensions', name: 'ensure-image-dimensions',
after: 'mobile', after: 'mobile',
initialize: function() { initialize(container) {
if (!window) { return; } if (!window) { return; }
// This enforces maximum dimensions of images based on site settings // This enforces maximum dimensions of images based on site settings
@ -11,7 +11,8 @@ export default {
var width = Discourse.SiteSettings.max_image_width; var width = Discourse.SiteSettings.max_image_width;
var height = Discourse.SiteSettings.max_image_height; var height = Discourse.SiteSettings.max_image_height;
if (Discourse.Mobile.mobileView) { const site = container.lookup('site:main');
if (site.mobileView) {
width = $(window).width() - 20; width = $(window).width() - 20;
} }

View file

@ -1,14 +1,19 @@
/** import Mobile from 'discourse/lib/mobile';
Initializes the `Discourse.Mobile` helper object.
**/ // Initializes the `Mobile` helper object.
export default { export default {
name: 'mobile', name: 'mobile',
after: 'inject-objects', after: 'inject-objects',
initialize: function(container) { initialize(container, app) {
Discourse.Mobile.init(); Mobile.init();
var site = container.lookup('site:main'); const site = container.lookup('site:main');
site.set('mobileView', Discourse.Mobile.mobileView);
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;
} }
}; };

View file

@ -96,7 +96,7 @@ export default {
}); });
if (!Ember.testing) { if (!Ember.testing) {
if (!Discourse.Mobile.mobileView) { if (!site.mobileView) {
bus.subscribe("/notification-alert/" + user.get('id'), function(data){ bus.subscribe("/notification-alert/" + user.get('id'), function(data){
onNotification(data, user); onNotification(data, user);
}); });

View file

@ -3,7 +3,6 @@
@module $.fn.autocomplete @module $.fn.autocomplete
**/ **/
export var CANCELLED_STATUS = "__CANCELLED"; export var CANCELLED_STATUS = "__CANCELLED";
const allowedLettersRegex = /[\s\t\[\{\(\/]/; const allowedLettersRegex = /[\s\t\[\{\(\/]/;
@ -226,7 +225,7 @@ export default function(options) {
vOffset = div.height(); vOffset = div.height();
} }
if (Discourse.Mobile.mobileView && !isInput) { if (Discourse.Site.currentProp('mobileView') && !isInput) {
div.css('width', 'auto'); div.css('width', 'auto');
if ((me.height() / 2) >= pos.top) { vOffset = -23; } if ((me.height() / 2) >= pos.top) { vOffset = -23; }

View file

@ -161,7 +161,7 @@ function showSelector(options) {
options.appendTo.append('<div class="emoji-modal-wrapper"></div>'); options.appendTo.append('<div class="emoji-modal-wrapper"></div>');
$('.emoji-modal-wrapper').click(() => closeSelector()); $('.emoji-modal-wrapper').click(() => closeSelector());
if (Discourse.Mobile.mobileView) PER_ROW = 9; if (Discourse.Site.currentProp('mobileView')) { PER_ROW = 9; }
const page = keyValueStore.getInt("emojiPage", 0); const page = keyValueStore.getInt("emojiPage", 0);
const offset = keyValueStore.getInt("emojiOffset", 0); const offset = keyValueStore.getInt("emojiOffset", 0);

View file

@ -1,10 +1,10 @@
// An object that is responsible for logic related to mobile devices. // An object that is responsible for logic related to mobile devices.
Discourse.Mobile = { const Mobile = {
isMobileDevice: false, isMobileDevice: false,
mobileView: false, mobileView: false,
init: function() { init() {
var $html = $('html'); const $html = $('html');
this.isMobileDevice = $html.hasClass('mobile-device'); this.isMobileDevice = $html.hasClass('mobile-device');
this.mobileView = $html.hasClass('mobile-view'); this.mobileView = $html.hasClass('mobile-view');
@ -42,3 +42,13 @@ Discourse.Mobile = {
window.location.assign(window.location.pathname + '?mobile_view=' + (mobile ? '1' : '0')); window.location.assign(window.location.pathname + '?mobile_view=' + (mobile ? '1' : '0'));
} }
}; };
// Backwards compatibiltity, deprecated
Object.defineProperty(Discourse, 'Mobile', {
get: function() {
Ember.warn("DEPRECATION: `Discourse.Mobile` is deprecated, use `this.site.mobileView` instead");
return Mobile;
}
});
export default Mobile;

View file

@ -154,7 +154,7 @@ const Composer = RestModel.extend({
usernameLink usernameLink
}); });
if (!Discourse.Mobile.mobileView) { if (!this.site.mobileView) {
const replyUsername = post.get('reply_to_user.username'); const replyUsername = post.get('reply_to_user.username');
const replyAvatarTemplate = post.get('reply_to_user.avatar_template'); const replyAvatarTemplate = post.get('reply_to_user.avatar_template');
if (replyUsername && replyAvatarTemplate && this.get('action') === EDIT) { if (replyUsername && replyAvatarTemplate && this.get('action') === EDIT) {

View file

@ -7,7 +7,7 @@ const NavItem = Discourse.Model.extend({
name = this.get('name'), name = this.get('name'),
count = this.get('count') || 0; count = this.get('count') || 0;
if (name === 'latest' && !Discourse.Mobile.mobileView) { if (name === 'latest' && !Discourse.Site.currentProp('mobileView')) {
count = 0; count = 0;
} }

View file

@ -4,7 +4,7 @@ export default Discourse.Route.extend({
// HACK: Something with the way the user card intercepts clicks seems to break how the // HACK: Something with the way the user card intercepts clicks seems to break how the
// transition into a user's activity works. This makes the back button work on mobile // transition into a user's activity works. This makes the back button work on mobile
// where there is no user card as well as desktop where there is. // where there is no user card as well as desktop where there is.
if (Discourse.Mobile.mobileView) { if (this.site.mobileView) {
this.replaceWith('userActivity'); this.replaceWith('userActivity');
} else { } else {
this.transitionTo('userActivity'); this.transitionTo('userActivity');

View file

@ -9,7 +9,7 @@ export default Ember.View.extend({
$('#discourse-modal').modal('show'); $('#discourse-modal').modal('show');
// Focus on first element // Focus on first element
if (!Discourse.Mobile.mobileView && this.get('focusInput')) { if (!this.site.mobileView && this.get('focusInput')) {
Em.run.schedule('afterRender', () => this.$('input:first').focus()); Em.run.schedule('afterRender', () => this.$('input:first').focus());
} }

View file

@ -82,7 +82,7 @@ export default Ember.View.extend({
$shareLink.css({top: "" + y + "px"}); $shareLink.css({top: "" + y + "px"});
if (!Discourse.Mobile.mobileView) { if (!this.site.mobileView) {
$shareLink.css({left: "" + x + "px"}); $shareLink.css({left: "" + x + "px"});
} }

View file

@ -6,7 +6,7 @@ export default ContainerView.extend({
@on('init') @on('init')
createButtons() { createButtons() {
const mobileView = Discourse.Mobile.mobileView; const mobileView = this.site.mobileView;
if (!mobileView && this.currentUser.get('staff')) { if (!mobileView && this.currentUser.get('staff')) {
const viewArgs = {action: 'showTopicAdminMenu', title: 'topic_admin_menu', icon: 'wrench', position: 'absolute'}; const viewArgs = {action: 'showTopicAdminMenu', title: 'topic_admin_menu', icon: 'wrench', position: 'absolute'};

View file

@ -76,7 +76,7 @@ export default Ember.View.extend({
_focusWhenOpened: function() { _focusWhenOpened: function() {
// Don't focus on mobile or touch // Don't focus on mobile or touch
if (Discourse.Mobile.mobileView || this.capabilities.isIOS) { if (this.site.mobileView || this.capabilities.isIOS) {
return; return;
} }

View file

@ -58,7 +58,7 @@ export default class PostCooked {
// deferring work only for posts with images // deferring work only for posts with images
// we got to use screen here, cause nothing is rendered yet. // we got to use screen here, cause nothing is rendered yet.
// long term we may want to allow for weird margins that are enforced, instead of hardcoding at 70/20 // long term we may want to allow for weird margins that are enforced, instead of hardcoding at 70/20
maxWindowWidth = maxWindowWidth || $(window).width() - (Discourse.Mobile.mobileView ? 20 : 70); maxWindowWidth = maxWindowWidth || $(window).width() - (this.attrs.mobileView ? 20 : 70);
if (maxImageWidth < maxWindowWidth) { if (maxImageWidth < maxWindowWidth) {
maxWindowWidth = maxImageWidth; maxWindowWidth = maxImageWidth;
} }

View file

@ -134,7 +134,7 @@ registerButton('reply', attrs => {
if (!attrs.canCreatePost) { return; } if (!attrs.canCreatePost) { return; }
if (!Discourse.Mobile.mobileView) { if (!attrs.mobileView) {
args.label = 'topic.reply.title'; args.label = 'topic.reply.title';
} }

View file

@ -19,6 +19,7 @@ export default createWidget('post-stream', {
let prevPost; let prevPost;
let prevDate; let prevDate;
const mobileView = this.site.mobileView;
for (let i=0; i<postArray.length; i++) { for (let i=0; i<postArray.length; i++) {
const post = postArray[i]; const post = postArray[i];
@ -31,6 +32,7 @@ export default createWidget('post-stream', {
const transformed = transformPost(this.currentUser, this.site, post, prevPost, nextPost); const transformed = transformPost(this.currentUser, this.site, post, prevPost, nextPost);
transformed.canCreatePost = attrs.canCreatePost; transformed.canCreatePost = attrs.canCreatePost;
transformed.mobileView = mobileView;
if (transformed.canManage) { if (transformed.canManage) {
transformed.multiSelect = attrs.multiSelect; transformed.multiSelect = attrs.multiSelect;

View file

@ -331,7 +331,7 @@ createWidget('post-article', {
const replyPostNumber = this.attrs.reply_to_post_number; const replyPostNumber = this.attrs.reply_to_post_number;
// jump directly on mobile // jump directly on mobile
if (Discourse.Mobile.mobileView) { if (this.attrs.mobileView) {
DiscourseURL.jumpToPost(replyPostNumber); DiscourseURL.jumpToPost(replyPostNumber);
return Ember.RSVP.Promise.resolve(); return Ember.RSVP.Promise.resolve();
} }

View file

@ -1,7 +1,7 @@
import DiscourseResolver from 'discourse/ember/resolver'; import DiscourseResolver from 'discourse/ember/resolver';
var originalTemplates, originalMobileViewFlag; let originalTemplates;
var resolver = DiscourseResolver.create(); let resolver;
function lookupTemplate(name, expectedTemplate, message) { function lookupTemplate(name, expectedTemplate, message) {
var parseName = resolver.parseName(name); var parseName = resolver.parseName(name);
@ -20,13 +20,11 @@ module("lib:resolver", {
originalTemplates = Ember.TEMPLATES; originalTemplates = Ember.TEMPLATES;
Ember.TEMPLATES = {}; Ember.TEMPLATES = {};
originalMobileViewFlag = Discourse.Mobile.mobileView; resolver = DiscourseResolver.create();
Discourse.Mobile.mobileView = false;
}, },
teardown: function() { teardown: function() {
Ember.TEMPLATES = originalTemplates; Ember.TEMPLATES = originalTemplates;
Discourse.Mobile.mobileView = originalMobileViewFlag;
} }
}); });
@ -92,7 +90,7 @@ test("resolves mobile templates to 'mobile/' namespace", function() {
"baz" "baz"
]); ]);
Discourse.Mobile.mobileView = true; resolver.mobileView = true;
lookupTemplate("template:foo", "mobile/foo", "finding mobile version even if normal one is not present"); 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"); lookupTemplate("template:bar", "mobile/bar", "preferring mobile version when both mobile and normal versions are present");