X-Git-Url: http://git.roojs.org/?p=roojs1;a=blobdiff_plain;f=Roo%2Fbootstrap%2FMarkdown.js;fp=Roo%2Fbootstrap%2FMarkdown.js;h=678451406dfea00b8b2cdf4e019cc6b6175377f6;hp=0000000000000000000000000000000000000000;hb=267f6bc0ecf0897515863c3c91a8eea23388e273;hpb=4806a3a6a72a6fc861a138965a6b1b5df60d0c87 diff --git a/Roo/bootstrap/Markdown.js b/Roo/bootstrap/Markdown.js new file mode 100644 index 0000000000..678451406d --- /dev/null +++ b/Roo/bootstrap/Markdown.js @@ -0,0 +1,85 @@ +// Roo.ux.Showdown.toHtml(Roo.util.Format.htmlEncode(this.getValue()))) + + +/* + * - LGPL + */ + +/** + * @class Roo.bootstrap.Showdown + * @extends Roo.bootstrap.TextArea + * Bootstrap Showdown editable area + * @cfg {string} content + * + * @constructor + * Create a new Showdown + */ + +Roo.bootstrap.Markdown = function(config){ + Roo.bootstrap.Markdown.superclass.constructor.call(this, config); + +}; + +Roo.extend(Roo.bootstrap.Markdown, Roo.bootstrap.TextArea, { + + editing :false, + + initEvents : function() + { + + Roo.bootstrap.TextArea.prototype.initEvents.call(this); + this.markdownEl = this.el.createChild({ + cls : 'roo-markdown-area' + }); + this.inputEl().addClass('d-none'); + this.markdownEl.dom.innerHTML = Roo.Markdown.toHtml(Roo.util.Format.htmlEncode(this.getValue())); + this.markdownEl.on('click', this.toggleTextEdit, this); + this.on('blur', this.toggleTextEdit, this); + this.on('specialkey', this.resizeTextArea, this); + }, + + toggleTextEdit : function() + { + var sh = this.markdownEl.getHeight(); + this.inputEl().addClass('d-none'); + this.markdownEl.addClass('d-none'); + if (!this.editing) { + // show editor? + this.inputEl().setHeight(Math.min(500, Math.max(sh,(this.getValue().split("\n").length+1) * 30))); + this.inputEl().removeClass('d-none'); + this.inputEl().focus(); + this.editing = true; + return; + } + // show showdown... + this.updateMarkdown(); + this.markdownEl.removeClass('d-none'); + this.editing = false; + return; + }, + updateMarkdown : function() + { + if (this.getValue() == '') { + this.markdownEl.dom.innerHTML = String.format('{0}', this.placeholder); + return; + } + this.markdownEl.dom.innerHTML = Roo.Markdown.toHtml(Roo.util.Format.htmlEncode(this.getValue())); + }, + + resizeTextArea: function () { + + var sh = 100; + Roo.log([sh, this.getValue().split("\n").length * 30]); + this.inputEl().setHeight(Math.min(500, Math.max(sh, (this.getValue().split("\n").length +1) * 30))); + }, + setValue : function(val) + { + Roo.bootstrap.TextArea.prototype.setValue.call(this,val); + if (!this.editing) { + this.updateMarkdown(); + } + + } + + +}); \ No newline at end of file