This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/components/d-editor-modal.js.es6
Robin Ward 94b60e62a2 FEATURE: New markdown editor re-written in Ember
Note this commit leaves out the biggest occurrence of the editor
which is the post/topic composer.

To avoid major breakage, this replaces it everywhere else it was
used:

* User preferences (About Me)
* Admin Customizations > Text Content
* Category Templates
* Editing Queued Posts

A future commit will replace the main composer with this editor
and will remove the unused pagedown code.
2015-10-19 11:01:20 -04:00

53 lines
1.2 KiB
JavaScript

import { observes, on } from 'ember-addons/ember-computed-decorators';
export default Ember.Component.extend({
classNameBindings: [':d-editor-modal', 'hidden'],
@observes('hidden')
_hiddenChanged() {
if (!this.get('hidden')) {
Ember.run.scheduleOnce('afterRender', () => {
const $modal = this.$();
const $parent = this.$().closest('.d-editor');
const w = $parent.width();
const h = $parent.height();
$modal.css({ left: (w / 2) - ($modal.outerWidth() / 2) });
parent.$('.d-editor-overlay').removeClass('hidden').css({ width: w, height: h});
this.$('input').focus();
});
} else {
parent.$('.d-editor-overlay').addClass('hidden');
}
},
@on('didInsertElement')
_listenKeys() {
this.$().on('keydown.d-modal', key => {
if (this.get('hidden')) { return; }
if (key.keyCode === 27) {
this.send('cancel');
}
if (key.keyCode === 13) {
this.send('ok');
}
});
},
@on('willDestoryElement')
_stopListening() {
this.$().off('keydown.d-modal');
},
actions: {
ok() {
this.set('hidden', true);
this.sendAction('okAction');
},
cancel() {
this.set('hidden', true);
}
}
});