2014-12-20 14:26:46 +08:00
|
|
|
import Ember from 'ember';
|
|
|
|
|
2015-02-02 14:27:59 +08:00
|
|
|
import ActionButton from '../components/ui/controls/action-button';
|
|
|
|
import TaggedArray from '../utils/tagged-array';
|
|
|
|
|
|
|
|
export default Ember.View.extend(Ember.Evented, {
|
2014-12-20 14:26:46 +08:00
|
|
|
|
|
|
|
classNames: ['composer'],
|
|
|
|
|
2015-02-02 14:27:59 +08:00
|
|
|
classNameBindings: [
|
|
|
|
'controller.showing:showing',
|
|
|
|
'controller.minimized:minimized',
|
|
|
|
'controller.fullScreen:fullscreen',
|
|
|
|
'active'
|
|
|
|
],
|
|
|
|
|
|
|
|
computedHeight: function() {
|
|
|
|
if (this.get('controller.minimized') || this.get('controller.fullScreen')) {
|
|
|
|
return '';
|
|
|
|
} else {
|
|
|
|
return Math.max(200, Math.min(this.get('height'), $(window).height() - $('#header').outerHeight()));
|
|
|
|
}
|
|
|
|
}.property('height', 'controller.minimized', 'controller.fullScreen'),
|
|
|
|
|
|
|
|
updateHeight: function() {
|
|
|
|
if (! this.$()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var view = this;
|
|
|
|
Ember.run.scheduleOnce('afterRender', function() {
|
|
|
|
view.$().height(view.get('computedHeight'));
|
|
|
|
view.updateTextareaHeight();
|
|
|
|
// view.updateBottomPadding();
|
|
|
|
});
|
|
|
|
}.observes('computedHeight'),
|
2015-01-30 09:52:19 +08:00
|
|
|
|
|
|
|
showingChanged: function() {
|
|
|
|
if (! this.$()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var view = this;
|
2015-02-02 14:27:59 +08:00
|
|
|
if (view.get('controller.showing')) {
|
|
|
|
view.$().show();
|
|
|
|
}
|
2015-01-30 09:52:19 +08:00
|
|
|
Ember.run.scheduleOnce('afterRender', function() {
|
|
|
|
view.$().css('bottom', view.get('controller.showing') ? -view.$().outerHeight() : 0);
|
|
|
|
view.$().animate({bottom: view.get('controller.showing') ? 0 : -view.$().outerHeight()}, 'fast', function() {
|
|
|
|
if (view.get('controller.showing')) {
|
2015-02-02 14:27:59 +08:00
|
|
|
view.focus();
|
|
|
|
} else {
|
|
|
|
view.$().hide();
|
2015-01-30 09:52:19 +08:00
|
|
|
}
|
|
|
|
});
|
2015-02-02 14:27:59 +08:00
|
|
|
view.updateBottomPadding(true);
|
2015-01-30 09:52:19 +08:00
|
|
|
});
|
|
|
|
}.observes('controller.showing'),
|
|
|
|
|
|
|
|
minimizedChanged: function() {
|
|
|
|
if (! this.$() || ! this.get('controller.showing')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var view = this;
|
|
|
|
var oldHeight = this.$().height();
|
|
|
|
Ember.run.scheduleOnce('afterRender', function() {
|
|
|
|
var newHeight = view.$().height();
|
2015-02-02 14:27:59 +08:00
|
|
|
view.updateBottomPadding(true);
|
2015-01-30 09:52:19 +08:00
|
|
|
view.$().css('height', oldHeight).animate({height: newHeight}, 'fast', function() {
|
|
|
|
if (! view.get('controller.minimized')) {
|
2015-02-02 14:27:59 +08:00
|
|
|
view.focus();
|
2015-01-30 09:52:19 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}.observes('controller.minimized'),
|
2014-12-20 14:26:46 +08:00
|
|
|
|
2015-02-02 14:27:59 +08:00
|
|
|
fullScreenChanged: function() {
|
|
|
|
if (! this.$()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var view = this;
|
|
|
|
Ember.run.scheduleOnce('afterRender', function() {
|
|
|
|
view.updateTextareaHeight();
|
|
|
|
});
|
|
|
|
}.observes('controller.fullScreen'),
|
|
|
|
|
2014-12-20 14:26:46 +08:00
|
|
|
didInsertElement: function() {
|
2015-02-02 14:27:59 +08:00
|
|
|
this.$().hide();
|
2015-01-30 09:52:19 +08:00
|
|
|
|
|
|
|
var controller = this.get('controller');
|
|
|
|
this.$('.composer-content').click(function() {
|
|
|
|
if (controller.get('minimized')) {
|
|
|
|
controller.send('show');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var view = this;
|
2015-02-02 14:27:59 +08:00
|
|
|
this.$().on('focus', ':input', function() {
|
2015-01-30 09:52:19 +08:00
|
|
|
view.set('active', true);
|
2015-02-02 14:27:59 +08:00
|
|
|
}).on('blur', ':input', function() {
|
2015-01-30 09:52:19 +08:00
|
|
|
view.set('active', false);
|
|
|
|
});
|
2015-02-02 14:27:59 +08:00
|
|
|
|
|
|
|
this.set('height', this.$().height());
|
|
|
|
|
|
|
|
controller.on('focus', this, this.focus);
|
|
|
|
|
|
|
|
$(window).on('resize', {view: this}, this.windowWasResized).resize();
|
|
|
|
|
|
|
|
var dragData = {view: this};
|
|
|
|
this.$('.composer-handle').css('cursor', 'row-resize')
|
|
|
|
.mousedown(function(e) {
|
|
|
|
dragData.mouseStart = e.clientY;
|
|
|
|
dragData.heightStart = view.$().height();
|
|
|
|
dragData.handle = $(this);
|
|
|
|
$('body').css('cursor', 'row-resize');
|
|
|
|
}).bind('dragstart mousedown', function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
|
|
|
$(document)
|
|
|
|
.on('mousemove', dragData, this.mouseWasMoved)
|
|
|
|
.on('mouseup', dragData, this.mouseWasReleased);
|
|
|
|
},
|
|
|
|
|
|
|
|
willDestroyElement: function() {
|
|
|
|
$(window)
|
|
|
|
.off('resize', this.windowWasResized);
|
|
|
|
|
|
|
|
$(document)
|
|
|
|
.off('mousemove', this.mouseWasMoved)
|
|
|
|
.off('mouseup', this.mouseWasReleased);
|
|
|
|
},
|
|
|
|
|
|
|
|
windowWasResized: function(event) {
|
|
|
|
var view = event.data.view;
|
|
|
|
view.notifyPropertyChange('computedHeight');
|
|
|
|
},
|
|
|
|
|
|
|
|
mouseWasMoved: function(event) {
|
|
|
|
if (! event.data.handle) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var view = event.data.view;
|
|
|
|
|
|
|
|
var deltaPixels = event.data.mouseStart - event.clientY;
|
|
|
|
view.set('height', event.data.heightStart + deltaPixels);
|
|
|
|
view.updateTextareaHeight();
|
|
|
|
view.updateBottomPadding();
|
|
|
|
},
|
|
|
|
|
|
|
|
mouseWasReleased: function(event) {
|
|
|
|
if (! event.data.handle) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
event.data.handle = null;
|
|
|
|
$('body').css('cursor', '');
|
|
|
|
},
|
|
|
|
|
|
|
|
refreshControls: function() {
|
|
|
|
var controlItems = TaggedArray.create();
|
|
|
|
this.trigger('populateControls', controlItems);
|
|
|
|
this.set('controlItems', controlItems);
|
|
|
|
}.observes('controller.minimized', 'controller.fullScreen'),
|
|
|
|
|
|
|
|
populateControls: function(controls) {
|
|
|
|
var controller = this.get('controller');
|
|
|
|
|
|
|
|
if (controller.get('fullScreen')) {
|
|
|
|
var exit = ActionButton.create({
|
|
|
|
icon: 'compress',
|
|
|
|
title: 'Exit Full Screen',
|
|
|
|
className: 'btn btn-icon btn-link',
|
|
|
|
action: function() {
|
|
|
|
controller.send('exitFullScreen');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
controls.pushObjectWithTag(exit, 'exit');
|
|
|
|
} else {
|
|
|
|
if (! controller.get('minimized')) {
|
|
|
|
var minimize = ActionButton.create({
|
|
|
|
icon: 'minus',
|
|
|
|
title: 'Minimize',
|
|
|
|
className: 'btn btn-icon btn-link btn-minimize',
|
|
|
|
action: function() {
|
|
|
|
controller.send('minimize');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
controls.pushObjectWithTag(minimize, 'minimize');
|
|
|
|
|
|
|
|
var fullScreen = ActionButton.create({
|
|
|
|
icon: 'expand',
|
|
|
|
title: 'Full Screen',
|
|
|
|
className: 'btn btn-icon btn-link',
|
|
|
|
action: function() {
|
|
|
|
controller.send('fullScreen');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
controls.pushObjectWithTag(fullScreen, 'fullScreen');
|
|
|
|
}
|
|
|
|
|
|
|
|
var close = ActionButton.create({
|
|
|
|
icon: 'times',
|
|
|
|
title: 'Close',
|
|
|
|
className: 'btn btn-icon btn-link',
|
|
|
|
action: function() {
|
|
|
|
controller.send('close');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
controls.pushObjectWithTag(close, 'close');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
focus: function() {
|
|
|
|
this.$().find(':input:enabled:visible:first').focus();
|
|
|
|
},
|
|
|
|
|
|
|
|
updateBottomPadding: function(animate) {
|
|
|
|
var top = $(document).height() - $(window).height();
|
|
|
|
var isBottom = $(window).scrollTop() >= top;
|
|
|
|
|
|
|
|
$('#main')[animate ? 'animate' : 'css']({paddingBottom: this.get('controller.showing') ? this.$().outerHeight() - Ember.$('#footer').outerHeight(true) : 0}, 'fast');
|
|
|
|
|
|
|
|
if (isBottom) {
|
|
|
|
if (animate) {
|
|
|
|
$('html, body').animate({scrollTop: $(document).height()}, 'fast');
|
|
|
|
} else {
|
|
|
|
$('html, body').scrollTop($(document).height());
|
|
|
|
}
|
|
|
|
}
|
2015-01-30 09:52:19 +08:00
|
|
|
},
|
|
|
|
|
2015-02-02 14:27:59 +08:00
|
|
|
updateTextareaHeight: function() {
|
|
|
|
var content = this.$('.composer-content');
|
|
|
|
this.$('textarea').height((this.get('computedHeight') || this.$().height())
|
|
|
|
- parseInt(content.css('padding-top'))
|
|
|
|
- parseInt(content.css('padding-bottom'))
|
|
|
|
- this.$('.composer-header').outerHeight(true)
|
|
|
|
- this.$('.text-editor-controls').outerHeight(true));
|
2014-12-20 14:26:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|