Quantcast
Viewing all articles
Browse latest Browse all 295549

Use CKEditor 4.2's new onChange event rather than our temporary work-around

Because CKEditor did not yet have a "change" event built in, we had to fake that on a best-effort basis:

  onChange: function (element, callback) {
    var editor = CKEDITOR.dom.element.get(element).getEditor();
    if (editor) {
      var changed = function () {
        window.setTimeout(function () {
          callback(editor.getData());
        }, 0);
      };
      // @todo Make this more elegant once http://dev.ckeditor.com/ticket/9794
      // is fixed.
      editor.on('key', changed);
      editor.on('paste', changed);
      editor.on('afterCommandExec', changed);
    }
    return !!editor;
  },

It was blocked on http://dev.ckeditor.com/ticket/9794. But, earlier today the solution for this was merged with CKEditor's dev branch, and consequently it will be available in CKEditor 4.2.

Hence the above code will need to be changed to:

  onChange: function (element, callback) {
    var editor = CKEDITOR.dom.element.get(element).getEditor();
    if (editor) {
      editor.on('change', function () {
        callback(editor.getData());
      });
    }
    return !!editor;
  },

Viewing all articles
Browse latest Browse all 295549


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>