7 * @class Roo.bootstrap.Markdown
8 * @extends Roo.bootstrap.TextArea
9 * Bootstrap Showdown editable area
10 * @cfg {string} content
13 * Create a new Showdown
16 Roo.bootstrap.Markdown = function(config){
17 Roo.bootstrap.Markdown.superclass.constructor.call(this, config);
21 Roo.extend(Roo.bootstrap.Markdown, Roo.bootstrap.TextArea, {
25 initEvents : function()
28 Roo.bootstrap.TextArea.prototype.initEvents.call(this);
29 this.markdownEl = this.el.createChild({
30 cls : 'roo-markdown-area'
32 this.inputEl().addClass('d-none');
33 var v = this.getValue();
37 this.markdownEl.dom.innerHTML = Roo.Markdown.toHtml(Roo.util.Format.htmlEncode(v));
38 this.markdownEl.on('click', this.toggleTextEdit, this);
39 this.on('blur', this.toggleTextEdit, this);
40 this.on('specialkey', this.resizeTextArea, this);
43 toggleTextEdit : function()
45 var sh = this.markdownEl.getHeight();
46 this.inputEl().addClass('d-none');
47 this.markdownEl.addClass('d-none');
50 this.inputEl().setHeight(Math.min(500, Math.max(sh,(this.getValue().split("\n").length+1) * 30)));
51 this.inputEl().removeClass('d-none');
52 this.inputEl().focus();
57 this.updateMarkdown();
58 this.markdownEl.removeClass('d-none');
62 updateMarkdown : function()
64 if (this.getValue() == '') {
65 this.markdownEl.dom.innerHTML = String.format('<span class="roo-placeholder">{0}</span>', this.placeholder || '');
69 this.markdownEl.dom.innerHTML = Roo.Markdown.toHtml(Roo.util.Format.htmlEncode(this.getValue()));
72 resizeTextArea: function () {
75 Roo.log([sh, this.getValue().split("\n").length * 30]);
76 this.inputEl().setHeight(Math.min(500, Math.max(sh, (this.getValue().split("\n").length +1) * 30)));
78 setValue : function(val)
80 Roo.bootstrap.TextArea.prototype.setValue.call(this,val);
82 this.updateMarkdown();
89 this.toggleTextEdit();