FIX: allow for more than 1 markdown editor instances

This commit is contained in:
Régis Hanol 2015-09-29 20:21:47 +02:00
parent 3cd23b45af
commit 321d1bd0a9
4 changed files with 16 additions and 14 deletions

View File

@ -1,21 +1,23 @@
import { observes, on } from 'ember-addons/ember-computed-decorators';
import loadScript from 'discourse/lib/load-script';
export default Ember.Component.extend({
classNameBindings: [':pagedown-editor'],
_initializeWmd: function() {
const self = this;
loadScript('defer/html-sanitizer-bundle').then(function() {
self.$('.wmd-input').data('init', true);
self._editor = Discourse.Markdown.createEditor({ containerElement: self.element });
self._editor.run();
Ember.run.scheduleOnce('afterRender', self, self._refreshPreview);
@on("didInsertElement")
_initializeWmd() {
loadScript('defer/html-sanitizer-bundle').then(() => {
this.$('.wmd-input').data('init', true);
this._editor = Discourse.Markdown.createEditor({ containerElement: this.element });
this._editor.run();
Ember.run.scheduleOnce('afterRender', this, this._refreshPreview);
});
}.on('didInsertElement'),
},
observeValue: function() {
@observes("value")
observeValue() {
Ember.run.scheduleOnce('afterRender', this, this._refreshPreview);
}.observes('value'),
},
_refreshPreview() {
this._editor.refreshPreview();

View File

@ -306,7 +306,8 @@
// end of Chunks
function firstByClass(doc, containerElement, className) {
var elements = doc.getElementsByClassName(className);
var container = containerElement || doc;
var elements = container.getElementsByClassName(className);
if (elements && elements.length) {
return elements[0];
}

View File

@ -1,4 +1,3 @@
<div class='wmd-button-bar'></div>
{{textarea value=value class="wmd-input"}}
<div class="wmd-preview preview {{unless value 'hidden'}}">
</div>
<div class="wmd-preview preview {{unless value 'hidden'}}"></div>

View File

@ -246,7 +246,7 @@ const ComposerView = Ember.View.extend(Ember.Evented, {
});
const options ={
const options = {
containerElement: this.element,
lookupAvatarByPostNumber(postNumber, topicId) {
const posts = controller.get('controllers.topic.model.postStream.posts');