From 3f405c5c72e32872d446233f44b7721c0d830a20 Mon Sep 17 00:00:00 2001 From: Alan Knowles Date: Thu, 19 Nov 2020 16:36:10 +0800 Subject: [PATCH] Roo/bootstrap/Markdown.js --- Roo/bootstrap/Markdown.js | 82 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 Roo/bootstrap/Markdown.js diff --git a/Roo/bootstrap/Markdown.js b/Roo/bootstrap/Markdown.js new file mode 100644 index 0000000000..d1f23fd806 --- /dev/null +++ b/Roo/bootstrap/Markdown.js @@ -0,0 +1,82 @@ +// 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() + { + 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(val); + if (!this.editing) { + + } + + } + + +}); \ No newline at end of file -- 2.39.2