/
composer.js.es6
109 lines (88 loc) · 3.27 KB
/
composer.js.es6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import afterTransition from 'discourse/lib/after-transition';
import positioningWorkaround from 'discourse/lib/safari-hacks';
import { headerHeight } from 'discourse/views/header';
import { default as computed, on, observes } from 'ember-addons/ember-computed-decorators';
import Composer from 'discourse/models/composer';
const ComposerView = Ember.View.extend(Ember.Evented, {
_lastKeyTimeout: null,
elementId: 'reply-control',
classNameBindings: ['composer.creatingPrivateMessage:private-message',
'composeState',
'composer.loading',
'composer.canEditTitle:edit-title',
'composer.createdPost:created-post',
'composer.creatingTopic:topic'],
composer: Em.computed.alias('controller.model'),
@computed('composer.composeState')
composeState(composeState) {
return composeState || Composer.CLOSED;
},
movePanels() {
// Do we need these anymore? causes issues on iPad. Reply sometimes does not
// show composer due to bottom padding.
// $('#main-outlet').css('padding-bottom', sizePx);
// $('.composer-popup').css('bottom', sizePx);
// signal the progress bar it should move!
this.appEvents.trigger("composer:resized");
},
@observes('composeState', 'composer.action')
resize() {
Ember.run.scheduleOnce('afterRender', () => {
const h = $('#reply-control').height() || 0;
this.movePanels(h + "px");
// Figure out the size of the fields
const $fields = this.$('.composer-fields');
const fieldPos = $fields.position();
if (fieldPos) {
this.$('.wmd-controls').css('top', $fields.height() + fieldPos.top + 5);
}
// get the submit panel height
const submitPos = this.$('.submit-panel').position();
if (submitPos) {
this.$('.wmd-controls').css('bottom', h - submitPos.top + 7);
}
});
},
keyUp() {
const controller = this.get('controller');
controller.checkReplyLength();
this.get('composer').typing();
const lastKeyUp = new Date();
this._lastKeyUp = lastKeyUp;
// One second from now, check to see if the last key was hit when
// we recorded it. If it was, the user paused typing.
Ember.run.cancel(this._lastKeyTimeout);
this._lastKeyTimeout = Ember.run.later(() => {
if (lastKeyUp !== this._lastKeyUp) { return; }
// Search for similar topics if the user pauses typing
controller.findSimilarTopics();
}, 1000);
},
keyDown(e) {
if (e.which === 27) {
this.get('controller').send('hitEsc');
return false;
} else if (e.which === 13 && (e.ctrlKey || e.metaKey)) {
// CTRL+ENTER or CMD+ENTER
this.get('controller').send('save');
return false;
}
},
@on('didInsertElement')
_enableResizing() {
const $replyControl = $('#reply-control');
const resize = () => Ember.run(() => this.resize());
$replyControl.DivResizer({
resize,
maxHeight: winHeight => winHeight - headerHeight(),
onDrag: sizePx => this.movePanels(sizePx)
});
afterTransition($replyControl, resize);
positioningWorkaround(this.$());
},
click() {
this.get('controller').send('openIfDraft');
}
});
RSVP.EventTarget.mixin(ComposerView);
export default ComposerView;