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');
34 this.markdownEl.dom.innerHTML = Roo.Markdown.toHtml(Roo.util.Format.htmlEncode(this.getValue()));
35 this.markdownEl.on('click', this.toggleTextEdit, this);
36 this.on('blur', this.toggleTextEdit, this);
37 this.on('specialkey', this.resizeTextArea, this);
40 toggleTextEdit : function()
42 var sh = this.markdownEl.getHeight();
43 this.inputEl().addClass('d-none');
44 this.markdownEl.addClass('d-none');
47 this.inputEl().setHeight(Math.min(500, Math.max(sh,(this.getValue().split("\n").length+1) * 30)));
48 this.inputEl().removeClass('d-none');
49 this.inputEl().focus();
54 this.updateMarkdown();
55 this.markdownEl.removeClass('d-none');
59 updateMarkdown : function()
61 if (this.getValue() == '') {
62 this.markdownEl.dom.innerHTML = String.format('<span class="roo-placeholder">{0}</span>', this.placeholder || '');
66 this.markdownEl.dom.innerHTML = Roo.Markdown.toHtml(Roo.util.Format.htmlEncode(this.getValue()));
69 resizeTextArea: function () {
72 Roo.log([sh, this.getValue().split("\n").length * 30]);
73 this.inputEl().setHeight(Math.min(500, Math.max(sh, (this.getValue().split("\n").length +1) * 30)));
75 setValue : function(val)
77 Roo.bootstrap.TextArea.prototype.setValue.call(this,val);
79 this.updateMarkdown();
86 this.toggleTextEdit();