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 if (this.getValue() == '') {
34 this.markdownEl.dom.innerHTML = String.format('<span class="roo-placeholder">{0}</span>', this.placeholder || '');
37 this.markdownEl.dom.innerHTML = Roo.Markdown.toHtml(Roo.util.Format.htmlEncode(this.getValue()));
39 this.markdownEl.on('click', this.toggleTextEdit, this);
40 this.on('blur', this.toggleTextEdit, this);
41 this.on('specialkey', this.resizeTextArea, this);
44 toggleTextEdit : function()
46 var sh = this.markdownEl.getHeight();
47 this.inputEl().addClass('d-none');
48 this.markdownEl.addClass('d-none');
51 this.inputEl().setHeight(Math.min(500, Math.max(sh,(this.getValue().split("\n").length+1) * 30)));
52 this.inputEl().removeClass('d-none');
53 this.inputEl().focus();
58 this.updateMarkdown();
59 this.markdownEl.removeClass('d-none');
63 updateMarkdown : function()
65 if (this.getValue() == '') {
66 this.markdownEl.dom.innerHTML = String.format('<span class="roo-placeholder">{0}</span>', this.placeholder || '');
70 this.markdownEl.dom.innerHTML = Roo.Markdown.toHtml(Roo.util.Format.htmlEncode(this.getValue()));
73 resizeTextArea: function () {
76 Roo.log([sh, this.getValue().split("\n").length * 30]);
77 this.inputEl().setHeight(Math.min(500, Math.max(sh, (this.getValue().split("\n").length +1) * 30)));
79 setValue : function(val)
81 Roo.bootstrap.TextArea.prototype.setValue.call(this,val);
83 this.updateMarkdown();
90 this.toggleTextEdit();