Yeshua Rodas Yeshua Rodas - 1 year ago 148
Javascript Question

How get works scroll container with SimpleMDE and Qooxdoo?

I will really appreciate your help, you see: I'm trying to get a qooxdoo widget that build an SimpleMDE Editor. You can check my test code at playground:

qx.Class.define("MdEditor", {
extend: qx.ui.core.Widget,

construct: function() {
this.addListenerOnce("appear", this.__appearRenderer, this);

members: {
__appearRenderer: function() {'');

var dynLoader = new qx.util.DynamicScriptLoader (

dynLoader.addListenerOnce("ready", function(e) {
this.debug("Simple MDE editor loaded");

var contentEl = this.getContentElement();

var editor = new SimpleMDE({
element: contentEl.getDomElement(),
spellChocker: false

}, this);


_createContentElement: function() {
return new qx.html.Input("textarea");

var win = new qx.ui.window.Window("Simple MDE");
win.setLayout(new qx.ui.layout.Grow());

var compo = new qx.ui.container.Scroll();
compo.add(new MdEditor());


this.getRoot().add(win, {left:20, top:20});;

Actually the instance is created and shown, but when you write text beyond the visible space the «expected» scrollbars are not show, and at console I got this error
Error in property scrollY of class qx.ui.core.scroll.ScrollPane in method setScrollY with incoming value '131': Is invalid!

I was try to shown the native scrollbars of
but not success. Now, I want show scrollbars managed by qooxdoo, but cannot figure out how to archive that.

Answer Source

The SimpleMDE editor, which is a wrapped up CodeMirror editor, does the same as other editor like CKEditor do: it places it's own div as a child of the parent div of a given textarea element.

To make this work and have the div as a child of a qooxdoo widgets content element, you have to create a div as a content element and the textarea as a child of that div:

_createContentElement: function() {
  // create a div content element which will be the parent for
  // the editor div
  var ce = new qx.html.Element("div");

  // and add a textarea as a child to the former div
  // as the editor only sets the textarea to display:none
  this.__textareaContentElement = new qx.html.Input("textarea");


  return ce;

The second thing is that you have to actively set the height of the editor manually, as it has no API for that, by retrieving the top div and the scroller div of the editor, which can be done with

this.__cm = q(".CodeMirror", content_element)[0];
this.__cmscroll = q(".CodeMirror-scroll", content_element)[0];

where content_element is the (well) content element of our wrapper widget. Now you can set the height of the CodeMirror and CodeMirror-scroll initially and within a resize listener of the wrapper so that it fits.

var hint = this.getBounds();
var height = (hint.height-83-22-22-12)+"px"; = height; = height; = height;

Please note, that the "magic" calculations of the height should be optimized by retrieving the real height of the toolbar and the status bar of the editor. I've extended those calculations in the playground example below to calculate the real heights of the elements and added a listener for the resize of the toolbar, which may change it's height depending on how many icons can be shown in one or multiple lines.

Please have a look into this playground example which works, but should be refined:


Also note that SimpleMDE and codemirror seem to be limited in API by means of having methods to set the height of the editor parts/elements.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download