Remove coupling of a composer feature to d editor.

This commit is contained in:
Guo Xiang Tan 2016-07-04 16:15:36 +08:00
parent 0ffe8402a9
commit c5a66d4b50
No known key found for this signature in database
GPG Key ID: 19C321C8952B0F72
5 changed files with 30 additions and 29 deletions

View File

@ -23,6 +23,11 @@ export default Ember.Component.extend({
this.set('showPreview', val === 'true'); this.set('showPreview', val === 'true');
}, },
@computed('site.mobileView', 'showPreview')
forcePreview(mobileView, showPreview) {
return mobileView && showPreview;
},
@computed('showPreview') @computed('showPreview')
toggleText: function(showPreview) { toggleText: function(showPreview) {
return showPreview ? I18n.t('composer.hide_preview') : I18n.t('composer.show_preview'); return showPreview ? I18n.t('composer.hide_preview') : I18n.t('composer.show_preview');
@ -431,6 +436,16 @@ export default Ember.Component.extend({
sendAction: 'showOptions' sendAction: 'showOptions'
}); });
} }
if (this.site.mobileView) {
toolbar.addButton({
id: 'preview',
group: 'mobileExtras',
icon: 'television',
title: 'composer.show_preview',
sendAction: 'togglePreview'
});
}
}, },
previewUpdated($preview) { previewUpdated($preview) {

View File

@ -102,14 +102,6 @@ class Toolbar {
if (site.mobileView) { if (site.mobileView) {
this.groups.push({group: 'mobileExtras', buttons: []}); 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; this.groups[this.groups.length-1].lastGroup = true;
@ -181,7 +173,6 @@ export function onToolbarCreate(func) {
export default Ember.Component.extend({ export default Ember.Component.extend({
classNames: ['d-editor'], classNames: ['d-editor'],
ready: false, ready: false,
forcePreview: false,
insertLinkHidden: true, insertLinkHidden: true,
linkUrl: '', linkUrl: '',
linkText: '', linkText: '',
@ -487,10 +478,6 @@ export default Ember.Component.extend({
Ember.run.scheduleOnce("afterRender", () => this.$("textarea.d-editor-input").focus()); Ember.run.scheduleOnce("afterRender", () => this.$("textarea.d-editor-input").focus());
}, },
_togglePreview() {
this.toggleProperty('forcePreview');
},
actions: { actions: {
toolbarButton(button) { toolbarButton(button) {
const selected = this._getSelected(button.trimLeading); 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), applySurround: (head, tail, exampleKey) => this._applySurround(selected, head, tail, exampleKey),
applyList: (head, exampleKey) => this._applyList(selected, head, exampleKey), applyList: (head, exampleKey) => this._applyList(selected, head, exampleKey),
addText: text => this._addText(selected, text), addText: text => this._addText(selected, text),
preview: () => this._togglePreview()
}; };
if (button.sendAction) { if (button.sendAction) {
@ -510,10 +496,6 @@ export default Ember.Component.extend({
} }
}, },
hidePreview() {
this.set('forcePreview', false);
},
showLinkModal() { showLinkModal() {
this._lastSel = this._getSelected(); this._lastSel = this._getSelected();
this.set('insertLinkHidden', false); this.set('insertLinkHidden', false);

View File

@ -7,16 +7,23 @@
importQuote="importQuote" importQuote="importQuote"
showOptions="showOptions" showOptions="showOptions"
showUploadModal="showUploadModal" showUploadModal="showUploadModal"
togglePreview="togglePreview"
validation=validation validation=validation
loading=composer.loading}} loading=composer.loading
forcePreview=forcePreview}}
<div class="composer-bottom-right"> <div class="composer-bottom-right">
{{#if site.mobileView}} {{#if site.mobileView}}
<input type="file" id="mobile-uploader" multiple /> <input type="file" id="mobile-uploader" multiple />
<a class="mobile-file-upload {{if isUploading 'hidden'}}">{{i18n 'upload'}}</a> <a class="mobile-file-upload {{if isUploading 'hidden'}}">{{i18n 'upload'}}</a>
{{#if showPreview}}
{{d-button action='togglePreview' class='hide-preview' label='composer.hide_preview'}}
{{/if}}
{{else}} {{else}}
<a href {{action "togglePreview"}} class='toggle-preview'>{{{toggleText}}}</a> <a href {{action "togglePreview"}} class='toggle-preview'>{{{toggleText}}}</a>
{{/if}} {{/if}}
{{#if isUploading}} {{#if isUploading}}
<div id="file-uploading"> <div id="file-uploading">
{{loading-spinner size="small"}} {{i18n 'upload_selector.uploading'}} {{loading-spinner size="small"}} {{i18n 'upload_selector.uploading'}}

View File

@ -30,8 +30,5 @@
<div class="d-editor-preview"> <div class="d-editor-preview">
{{{preview}}} {{{preview}}}
</div> </div>
{{#if site.mobileView}}
{{d-button action='hidePreview' class='hide-preview' label='composer.hide_preview'}}
{{/if}}
</div> </div>
</div> </div>

View File

@ -252,6 +252,13 @@ input {
display: none; display: none;
} }
.btn.hide-preview {
position: fixed;
right: 5px;
bottom: 5px;
z-index: 1000001;
}
.d-editor-preview-wrapper.force-preview { .d-editor-preview-wrapper.force-preview {
display: block; display: block;
position: fixed; position: fixed;
@ -268,13 +275,6 @@ input {
border: 0; border: 0;
overflow: auto; overflow: auto;
} }
.hide-preview {
position: fixed;
right: 5px;
bottom: 5px;
z-index: 1000001;
}
} }
.d-editor-textarea-wrapper { .d-editor-textarea-wrapper {
position: relative; position: relative;