diff --git a/app/assets/javascripts/discourse/components/composer-editor.js.es6 b/app/assets/javascripts/discourse/components/composer-editor.js.es6 index 50572c40e59..f80f94231a7 100644 --- a/app/assets/javascripts/discourse/components/composer-editor.js.es6 +++ b/app/assets/javascripts/discourse/components/composer-editor.js.es6 @@ -23,6 +23,11 @@ export default Ember.Component.extend({ this.set('showPreview', val === 'true'); }, + @computed('site.mobileView', 'showPreview') + forcePreview(mobileView, showPreview) { + return mobileView && showPreview; + }, + @computed('showPreview') toggleText: function(showPreview) { return showPreview ? I18n.t('composer.hide_preview') : I18n.t('composer.show_preview'); @@ -431,6 +436,16 @@ export default Ember.Component.extend({ sendAction: 'showOptions' }); } + + if (this.site.mobileView) { + toolbar.addButton({ + id: 'preview', + group: 'mobileExtras', + icon: 'television', + title: 'composer.show_preview', + sendAction: 'togglePreview' + }); + } }, previewUpdated($preview) { diff --git a/app/assets/javascripts/discourse/components/d-editor.js.es6 b/app/assets/javascripts/discourse/components/d-editor.js.es6 index 0c0b9c43315..08fc9a55210 100644 --- a/app/assets/javascripts/discourse/components/d-editor.js.es6 +++ b/app/assets/javascripts/discourse/components/d-editor.js.es6 @@ -102,14 +102,6 @@ class Toolbar { 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() - }); } this.groups[this.groups.length-1].lastGroup = true; @@ -181,7 +173,6 @@ export function onToolbarCreate(func) { export default Ember.Component.extend({ classNames: ['d-editor'], ready: false, - forcePreview: false, insertLinkHidden: true, linkUrl: '', linkText: '', @@ -487,10 +478,6 @@ export default Ember.Component.extend({ Ember.run.scheduleOnce("afterRender", () => this.$("textarea.d-editor-input").focus()); }, - _togglePreview() { - this.toggleProperty('forcePreview'); - }, - actions: { toolbarButton(button) { const selected = this._getSelected(button.trimLeading); @@ -500,7 +487,6 @@ export default Ember.Component.extend({ applySurround: (head, tail, exampleKey) => this._applySurround(selected, head, tail, exampleKey), applyList: (head, exampleKey) => this._applyList(selected, head, exampleKey), addText: text => this._addText(selected, text), - preview: () => this._togglePreview() }; if (button.sendAction) { @@ -510,10 +496,6 @@ export default Ember.Component.extend({ } }, - hidePreview() { - this.set('forcePreview', false); - }, - showLinkModal() { this._lastSel = this._getSelected(); this.set('insertLinkHidden', false); diff --git a/app/assets/javascripts/discourse/templates/components/composer-editor.hbs b/app/assets/javascripts/discourse/templates/components/composer-editor.hbs index 001ff761de2..e4ebb29c5db 100644 --- a/app/assets/javascripts/discourse/templates/components/composer-editor.hbs +++ b/app/assets/javascripts/discourse/templates/components/composer-editor.hbs @@ -7,16 +7,23 @@ importQuote="importQuote" showOptions="showOptions" showUploadModal="showUploadModal" + togglePreview="togglePreview" validation=validation - loading=composer.loading}} + loading=composer.loading + forcePreview=forcePreview}}