Remove `Discourse.Mobile` constants
This commit is contained in:
parent
ef75f87c8b
commit
849c99f83d
|
@ -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() {
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -25,153 +25,156 @@ const OP = {
|
||||||
|
|
||||||
const _createCallbacks = [];
|
const _createCallbacks = [];
|
||||||
|
|
||||||
function Toolbar() {
|
class Toolbar {
|
||||||
this.shortcuts = {};
|
|
||||||
|
|
||||||
this.groups = [
|
constructor(site) {
|
||||||
{group: 'fontStyles', buttons: []},
|
this.shortcuts = {};
|
||||||
{group: 'insertions', buttons: []},
|
|
||||||
{group: 'extras', buttons: []}
|
|
||||||
];
|
|
||||||
|
|
||||||
this.addButton({
|
this.groups = [
|
||||||
id: 'bold',
|
{group: 'fontStyles', buttons: []},
|
||||||
group: 'fontStyles',
|
{group: 'insertions', buttons: []},
|
||||||
shortcut: 'B',
|
{group: 'extras', buttons: []}
|
||||||
perform: e => e.applySurround('**', '**', 'bold_text')
|
];
|
||||||
});
|
|
||||||
|
|
||||||
this.addButton({
|
|
||||||
id: 'italic',
|
|
||||||
group: 'fontStyles',
|
|
||||||
shortcut: 'I',
|
|
||||||
perform: e => e.applySurround('_', '_', 'italic_text')
|
|
||||||
});
|
|
||||||
|
|
||||||
this.addButton({id: 'link', group: 'insertions', shortcut: 'K', action: 'showLinkModal'});
|
|
||||||
|
|
||||||
this.addButton({
|
|
||||||
id: 'quote',
|
|
||||||
group: 'insertions',
|
|
||||||
icon: 'quote-right',
|
|
||||||
shortcut: 'Shift+9',
|
|
||||||
perform: e => e.applySurround('> ', '', 'code_text')
|
|
||||||
});
|
|
||||||
|
|
||||||
this.addButton({
|
|
||||||
id: 'code',
|
|
||||||
group: 'insertions',
|
|
||||||
shortcut: 'Shift+C',
|
|
||||||
perform(e) {
|
|
||||||
if (e.selected.value.indexOf("\n") !== -1) {
|
|
||||||
e.applySurround(' ', '', 'code_text');
|
|
||||||
} else {
|
|
||||||
e.applySurround('`', '`', 'code_text');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
this.addButton({
|
|
||||||
id: 'bullet',
|
|
||||||
group: 'extras',
|
|
||||||
icon: 'list-ul',
|
|
||||||
shortcut: 'Shift+8',
|
|
||||||
title: 'composer.ulist_title',
|
|
||||||
perform: e => e.applyList('* ', 'list_item')
|
|
||||||
});
|
|
||||||
|
|
||||||
this.addButton({
|
|
||||||
id: 'list',
|
|
||||||
group: 'extras',
|
|
||||||
icon: 'list-ol',
|
|
||||||
shortcut: 'Shift+7',
|
|
||||||
title: 'composer.olist_title',
|
|
||||||
perform: e => e.applyList(i => !i ? "1. " : `${parseInt(i) + 1}. `, 'list_item')
|
|
||||||
});
|
|
||||||
|
|
||||||
this.addButton({
|
|
||||||
id: 'heading',
|
|
||||||
group: 'extras',
|
|
||||||
icon: 'font',
|
|
||||||
shortcut: 'Alt+1',
|
|
||||||
perform: e => e.applyList('## ', 'heading_text')
|
|
||||||
});
|
|
||||||
|
|
||||||
this.addButton({
|
|
||||||
id: 'rule',
|
|
||||||
group: 'extras',
|
|
||||||
icon: 'minus',
|
|
||||||
shortcut: 'Alt+R',
|
|
||||||
title: 'composer.hr_title',
|
|
||||||
perform: e => e.addText("\n\n----------\n")
|
|
||||||
});
|
|
||||||
|
|
||||||
if (Discourse.Mobile.mobileView) {
|
|
||||||
this.groups.push({group: 'mobileExtras', buttons: []});
|
|
||||||
|
|
||||||
this.addButton({
|
this.addButton({
|
||||||
id: 'preview',
|
id: 'bold',
|
||||||
group: 'mobileExtras',
|
group: 'fontStyles',
|
||||||
icon: 'television',
|
shortcut: 'B',
|
||||||
title: 'composer.hr_preview',
|
perform: e => e.applySurround('**', '**', 'bold_text')
|
||||||
perform: e => e.preview()
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
this.groups[this.groups.length-1].lastGroup = true;
|
this.addButton({
|
||||||
};
|
id: 'italic',
|
||||||
|
group: 'fontStyles',
|
||||||
|
shortcut: 'I',
|
||||||
|
perform: e => e.applySurround('_', '_', 'italic_text')
|
||||||
|
});
|
||||||
|
|
||||||
Toolbar.prototype.addButton = function(button) {
|
this.addButton({id: 'link', group: 'insertions', shortcut: 'K', action: 'showLinkModal'});
|
||||||
const g = this.groups.findProperty('group', button.group);
|
|
||||||
if (!g) {
|
|
||||||
throw `Couldn't find toolbar group ${button.group}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const createdButton = {
|
this.addButton({
|
||||||
id: button.id,
|
id: 'quote',
|
||||||
className: button.className || button.id,
|
group: 'insertions',
|
||||||
icon: button.icon || button.id,
|
icon: 'quote-right',
|
||||||
action: button.action || 'toolbarButton',
|
shortcut: 'Shift+9',
|
||||||
perform: button.perform || Ember.K
|
perform: e => e.applySurround('> ', '', 'code_text')
|
||||||
};
|
});
|
||||||
|
|
||||||
if (button.sendAction) {
|
this.addButton({
|
||||||
createdButton.sendAction = button.sendAction;
|
id: 'code',
|
||||||
}
|
group: 'insertions',
|
||||||
|
shortcut: 'Shift+C',
|
||||||
|
perform(e) {
|
||||||
|
if (e.selected.value.indexOf("\n") !== -1) {
|
||||||
|
e.applySurround(' ', '', 'code_text');
|
||||||
|
} else {
|
||||||
|
e.applySurround('`', '`', 'code_text');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const title = I18n.t(button.title || `composer.${button.id}_title`);
|
this.addButton({
|
||||||
if (button.shortcut) {
|
id: 'bullet',
|
||||||
const mac = /Mac|iPod|iPhone|iPad/.test(navigator.platform);
|
group: 'extras',
|
||||||
const mod = mac ? 'Meta' : 'Ctrl';
|
icon: 'list-ul',
|
||||||
var shortcutTitle = `${mod}+${button.shortcut}`;
|
shortcut: 'Shift+8',
|
||||||
|
title: 'composer.ulist_title',
|
||||||
|
perform: e => e.applyList('* ', 'list_item')
|
||||||
|
});
|
||||||
|
|
||||||
// Mac users are used to glyphs for shortcut keys
|
this.addButton({
|
||||||
if (mac) {
|
id: 'list',
|
||||||
shortcutTitle = shortcutTitle
|
group: 'extras',
|
||||||
.replace('Shift', "\u21E7")
|
icon: 'list-ol',
|
||||||
.replace('Meta', "\u2318")
|
shortcut: 'Shift+7',
|
||||||
.replace('Alt', "\u2325")
|
title: 'composer.olist_title',
|
||||||
.replace(/\+/g, '');
|
perform: e => e.applyList(i => !i ? "1. " : `${parseInt(i) + 1}. `, 'list_item')
|
||||||
} else {
|
});
|
||||||
shortcutTitle = shortcutTitle
|
|
||||||
.replace('Shift', I18n.t('shortcut_modifier_key.shift'))
|
this.addButton({
|
||||||
.replace('Ctrl', I18n.t('shortcut_modifier_key.ctrl'))
|
id: 'heading',
|
||||||
.replace('Alt', I18n.t('shortcut_modifier_key.alt'));
|
group: 'extras',
|
||||||
|
icon: 'font',
|
||||||
|
shortcut: 'Alt+1',
|
||||||
|
perform: e => e.applyList('## ', 'heading_text')
|
||||||
|
});
|
||||||
|
|
||||||
|
this.addButton({
|
||||||
|
id: 'rule',
|
||||||
|
group: 'extras',
|
||||||
|
icon: 'minus',
|
||||||
|
shortcut: 'Alt+R',
|
||||||
|
title: 'composer.hr_title',
|
||||||
|
perform: e => e.addText("\n\n----------\n")
|
||||||
|
});
|
||||||
|
|
||||||
|
if (site.mobileView) {
|
||||||
|
this.groups.push({group: 'mobileExtras', buttons: []});
|
||||||
|
|
||||||
|
this.addButton({
|
||||||
|
id: 'preview',
|
||||||
|
group: 'mobileExtras',
|
||||||
|
icon: 'television',
|
||||||
|
title: 'composer.hr_preview',
|
||||||
|
perform: e => e.preview()
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
createdButton.title = `${title} (${shortcutTitle})`;
|
this.groups[this.groups.length-1].lastGroup = true;
|
||||||
|
|
||||||
this.shortcuts[`${mod}+${button.shortcut}`.toLowerCase()] = createdButton;
|
|
||||||
} else {
|
|
||||||
createdButton.title = title;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (button.unshift) {
|
addButton(button) {
|
||||||
g.buttons.unshift(createdButton);
|
const g = this.groups.findProperty('group', button.group);
|
||||||
} else {
|
if (!g) {
|
||||||
g.buttons.push(createdButton);
|
throw `Couldn't find toolbar group ${button.group}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const createdButton = {
|
||||||
|
id: button.id,
|
||||||
|
className: button.className || button.id,
|
||||||
|
icon: button.icon || button.id,
|
||||||
|
action: button.action || 'toolbarButton',
|
||||||
|
perform: button.perform || Ember.K
|
||||||
|
};
|
||||||
|
|
||||||
|
if (button.sendAction) {
|
||||||
|
createdButton.sendAction = button.sendAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
const title = I18n.t(button.title || `composer.${button.id}_title`);
|
||||||
|
if (button.shortcut) {
|
||||||
|
const mac = /Mac|iPod|iPhone|iPad/.test(navigator.platform);
|
||||||
|
const mod = mac ? 'Meta' : 'Ctrl';
|
||||||
|
var shortcutTitle = `${mod}+${button.shortcut}`;
|
||||||
|
|
||||||
|
// Mac users are used to glyphs for shortcut keys
|
||||||
|
if (mac) {
|
||||||
|
shortcutTitle = shortcutTitle
|
||||||
|
.replace('Shift', "\u21E7")
|
||||||
|
.replace('Meta', "\u2318")
|
||||||
|
.replace('Alt', "\u2325")
|
||||||
|
.replace(/\+/g, '');
|
||||||
|
} else {
|
||||||
|
shortcutTitle = shortcutTitle
|
||||||
|
.replace('Shift', I18n.t('shortcut_modifier_key.shift'))
|
||||||
|
.replace('Ctrl', I18n.t('shortcut_modifier_key.ctrl'))
|
||||||
|
.replace('Alt', I18n.t('shortcut_modifier_key.alt'));
|
||||||
|
}
|
||||||
|
|
||||||
|
createdButton.title = `${title} (${shortcutTitle})`;
|
||||||
|
|
||||||
|
this.shortcuts[`${mod}+${button.shortcut}`.toLowerCase()] = createdButton;
|
||||||
|
} else {
|
||||||
|
createdButton.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (button.unshift) {
|
||||||
|
g.buttons.unshift(createdButton);
|
||||||
|
} else {
|
||||||
|
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;
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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'),
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -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(){
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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(){
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
});
|
});
|
||||||
|
|
|
@ -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; }
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -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;
|
|
@ -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) {
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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');
|
||||||
|
|
|
@ -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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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"});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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'};
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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");
|
||||||
|
|
Loading…
Reference in New Issue