Integration"

This website contains links to software which is either no longer maintained or will be supported only until the end of 2019 (CKFinder 2). For the latest documentation about current CKSource projects, including software like CKEditor 4/CKEditor 5, CKFinder 3, Cloud Services, Letters, Accessibility Checker, please visit the new documentation website.

If you look for an information about very old versions of CKEditor, FCKeditor and CKFinder check also the CKEditor forum, which was closed in 2015. If not, please head to StackOverflow for support.

(Javascript API)
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
=Script Name=
 +
 +
If you do not use "ckeditor.js" in your install, either because you roll this into a larger script or because you use a different suffix like ".var", you will need to set the global varaible "CKEDITOR_BASEPATH" to the path to the CKEditor install -- otherwise CKEditor will fail to auto-detect the base path and various things like the language libraries will not load.  Note that this global JavaScript variable must be set before you include the ckeditor script.
 +
 +
> I've added this information to the page. --[[User:Fredck|FredCK]] 08:42, 12 October 2009 (UTC)
 +
 
=Javascript API=
 
=Javascript API=
  
Line 8: Line 14:
 
I wanted to see which functions are available for me and show that in... the editor itself. I did the following.
 
I wanted to see which functions are available for me and show that in... the editor itself. I did the following.
 
<pre>
 
<pre>
var objEditor=CKEDITOR.instances["id_of_textarea"];
+
var objEditor = CKEDITOR.instances["id_of_textarea"];
var str="";
+
var str = "";
 
for (var item in objEditor) {
 
for (var item in objEditor) {
   str+="<strong>"+item+"</strong>="+objEditor[item].toString().str_replace("\n", "<br>").str_replace(";", ";<br>&nbsp;&nbsp;").str_replace("{", "{<br>&nbsp;&nbsp;").str_replace("}", "}<br>").str_replace(";<br>&nbsp;&nbsp;}", ";<br>}")+"<br>";
+
   str += "<strong>" + item + "</strong>=" + objEditor[item].toString().str_replace("\n", "<br>").str_replace(";", ";<br>&nbsp;&nbsp;").str_replace("{", "{<br>&nbsp;&nbsp;").str_replace("}", "}<br>").str_replace(";<br>&nbsp;&nbsp;}", ";<br>}") + "<br>";
 
}
 
}
 
objEditor.setData(str);
 
objEditor.setData(str);
Line 19: Line 25:
  
 
<pre>
 
<pre>
getThemeSpace=function(l){
+
getThemeSpace = function(l) {
   var m='cke_'+l,n=this._[m]||(this._[m]=a.document.getById(m+'_'+this.name));
+
   var m = 'cke_' + l,
 +
  n = this._[m] || (this._[m] = a.document.getById(m + '_' + this.name));
 
   return n;
 
   return n;
 
}
 
}
  
focus=function(){
+
focus = function() {
   var n=l(this);
+
   var n = l(this);
   if(n)n.focus();
+
   if (n) n.focus();
 
}
 
}
  
setMode=function(n){
+
setMode = function(n) {
   var o,p=this.getThemeSpace('contents'),q=this.checkDirty();
+
   var o, p = this.getThemeSpace('contents'),
   if(this.mode){
+
  q = this.checkDirty();
  if(n==this.mode)return;
+
   if (this.mode) {
  var r=l(this);
+
    if (n == this.mode) return;
  o=r.getData();
+
    var r = l(this);
  r.unload(p);
+
    o = r.getData();
  this.mode='';
+
    r.unload(p);
}
+
    this.mode = '';
p.setHtml('');
+
  }
   var s=l(this,n);
+
  p.setHtml('');
   if(!s)throw '[CKEDITOR.editor.setMode] Unknown mode "'+n+'".';
+
   var s = l(this, n);
   if(!q)this.on('mode',
+
   if (!s) throw '[CKEDITOR.editor.setMode] Unknown mode "' + n + '".';
    function(){
+
   if (!q) this.on('mode',
      this.resetDirty();
+
  function() {
      this.removeListener('mode',arguments.callee);
+
    this.resetDirty();
    }
+
    this.removeListener('mode', arguments.callee);
  );
+
  });
   s.load(p,typeof o!='string'?this.getData():o);
+
   s.load(p, typeof o != 'string' ? this.getData() : o);
 
}
 
}
  
addMode=function(n,o){
+
addMode = function(n, o) {
   o.name=n;
+
   o.name = n;
   (this._.modes||(this._.modes={}))[n]=o;
+
   (this._.modes || (this._.modes = {}))[n] = o;
 
}
 
}
  
mode=openDialog=function(l){
+
mode = openDialog = function(l) {
   var m=a.dialog._.dialogDefinitions[l];
+
   var m = a.dialog._.dialogDefinitions[l];
   if(typeof m=='function'){
+
   if (typeof m == 'function') {
     var n=this._.storedDialogs||(this._.storedDialogs={}), o=n[l]||(n[l]=new a.dialog(this,l));
+
     var n = this._.storedDialogs || (this._.storedDialogs = {}),
 +
    o = n[l] || (n[l] = new a.dialog(this, l));
 
     o.show();
 
     o.show();
 
     return o;
 
     return o;
 
   }
 
   }
   var p=a.document.getBody(),q=p.$.style.cursor,r=this;
+
   var p = a.document.getBody(),
   p.setStyle('cursor','wait');
+
  q = p.$.style.cursor,
 +
  r = this;
 +
   p.setStyle('cursor', 'wait');
 
   a.scriptLoader.load(a.getUrl(m),
 
   a.scriptLoader.load(a.getUrl(m),
    function(){
+
  function() {
      r.openDialog(l);
+
    r.openDialog(l);
      p.setStyle('cursor',q);
+
    p.setStyle('cursor', q);
    }
+
  });
  );
 
 
   return null;
 
   return null;
 
}
 
}
  
restoreRealElement=function(l){
+
restoreRealElement = function(l) {
   var m=decodeURIComponent(l.getAttribute('_cke_realelement'));
+
   var m = decodeURIComponent(l.getAttribute('_cke_realelement'));
   return g.createFromHtml(m,this.document);
+
   return g.createFromHtml(m, this.document);
 
}
 
}
  
createFakeParserElement=function(l,m,n,o){
+
createFakeParserElement = function(l, m, n, o) {
   var p=new a.htmlParser.basicWriter();
+
   var p = new a.htmlParser.basicWriter();
 
   l.writeHtml(p);
 
   l.writeHtml(p);
   var q=p.getHtml(),r={'class':m,src:a.getUrl('images/spacer.gif'),_cke_realelement:encodeURIComponent(q)};
+
   var q = p.getHtml(),
   if(n)r._cke_real_element_type=n;
+
  r = {
   if(o)r._cke_resizable=o;
+
    'class': m,
   return new a.htmlParser.element('img',r);
+
    src: a.getUrl('images/spacer.gif'),
 +
    _cke_realelement: encodeURIComponent(q)
 +
  };
 +
   if (n) r._cke_real_element_type = n;
 +
   if (o) r._cke_resizable = o;
 +
   return new a.htmlParser.element('img', r);
 
}
 
}
  
createFakeElement=function(l,m,n,o){
+
createFakeElement = function(l, m, n, o) {
   var p={'class':m,src:a.getUrl('images/spacer.gif'),_cke_realelement:encodeURIComponent(l.getOuterHtml())};
+
   var p = {
 
+
    'class': m,
   if(n)p._cke_real_element_type=n;
+
    src: a.getUrl('images/spacer.gif'),
   if(o)p._cke_resizable=o;
+
    _cke_realelement: encodeURIComponent(l.getOuterHtml())
   return this.document.createElement('img',{attributes:p});
+
  };
 +
 
 +
   if (n) p._cke_real_element_type = n;
 +
   if (o) p._cke_resizable = o;
 +
   return this.document.createElement('img', {
 +
    attributes: p
 +
  });
 
}
 
}
  
forceNextSelectionCheck=function(){
+
forceNextSelectionCheck = function() {
 
   delete this._.selectionPreviousPath;
 
   delete this._.selectionPreviousPath;
 
}
 
}
  
getSelection=function(){
+
getSelection = function() {
   var u=this;
+
   var u = this;
   var s=u.document?u.document.getSelection():null;
+
   var s = u.document ? u.document.getSelection() : null;
   if(s&&c){
+
   if (s && c) {
     var t=s.getNative().createRange();
+
     var t = s.getNative().createRange();
     if(!t)return null;
+
     if (!t) return null;
     else if(t.item)return t.item(0).ownerDocument==u.document.$?s:null;
+
     else if (t.item) return t.item(0).ownerDocument == u.document.$ ? s: null;
     else return t.parentElement().ownerDocument==u.document.$?s:null;
+
     else return t.parentElement().ownerDocument == u.document.$ ? s: null;
 
   }
 
   }
 
   return s;
 
   return s;
 
}
 
}
  
getMenuItem=function(l){
+
getMenuItem = function(l) {
 
   return this._.menuItems[l];
 
   return this._.menuItems[l];
 
}
 
}
  
addMenuItems=function(l){
+
addMenuItems = function(l) {
   for(var m in l)this.addMenuItem(m,l[m]);
+
   for (var m in l) this.addMenuItem(m, l[m]);
 
}
 
}
  
addMenuItem=function(l,m){
+
addMenuItem = function(l, m) {
   if(this._.menuGroups[m.group])this._.menuItems[l]=new a.menuItem(this,l,m);
+
   if (this._.menuGroups[m.group]) this._.menuItems[l] = new a.menuItem(this, l, m);
 
}
 
}
  
attachStyleStateChange=function(l,m){
+
attachStyleStateChange = function(l, m) {
   var n=this._.styleStateChangeCallbacks;
+
   var n = this._.styleStateChangeCallbacks;
   if(!n){
+
   if (!n) {
     n=this._.styleStateChangeCallbacks=[];
+
     n = this._.styleStateChangeCallbacks = [];
 
     this.on('selectionChange',
 
     this.on('selectionChange',
      function(o){
+
    function(o) {
        for(var p=0;p p++){
+
      for (var p = 0; p p++) {
          var q=n[p],r=q.style.checkActive(o.data.path)?1:2;
+
        var q = n[p],
          if(q.state!==r){
+
        r = q.style.checkActive(o.data.path) ? 1 : 2;
            q.fn.call(this,r);
+
        if (q.state !== r) {
            q.state!==r;
+
          q.fn.call(this, r);
          }
+
          q.state !== r;
 
         }
 
         }
 
       }
 
       }
     );
+
     });
 
   }
 
   }
   n.push({style:l,fn:m});
+
   n.push({
 +
    style: l,
 +
    fn: m
 +
  });
 
}
 
}
  
insertText=function(l){
+
insertText = function(l) {
   l=e.htmlEncode(l);
+
   l = e.htmlEncode(l);
   l=l.replace(/(?:\r\n)|\n|\r/g,'
+
   l = l.replace(/(?:\r\n)|\n|\r/g, '
 
');
 
');
 
   this.insertHtml(l);
 
   this.insertHtml(l);
 
}
 
}
  
updateElement=function(){
+
updateElement = function() {
   var m=this;
+
   var m = this;
   var l=m.element;
+
   var l = m.element;
   if(l&&m.elementMode==1)if(l.is('textarea'))l.setValue(m.getData());
+
   if (l && m.elementMode == 1) if (l.is('textarea')) l.setValue(m.getData());
 
   else l.setHtml(m.getData());
 
   else l.setHtml(m.getData());
 
}
 
}
  
resetDirty=function(){
+
resetDirty = function() {
   if(this.mayBeDirty)this._.previousValue=this.getSnapshot();
+
   if (this.mayBeDirty) this._.previousValue = this.getSnapshot();
 
}
 
}
  
checkDirty=function(){
+
checkDirty = function() {
   return this.mayBeDirty&&this._.previousValue!==this.getSnapshot();
+
   return this.mayBeDirty && this._.previousValue !== this.getSnapshot();
 
}
 
}
  
insertElement=function(l){
+
insertElement = function(l) {
   this.fire('insertElement',l);
+
   this.fire('insertElement', l);
 
}
 
}
  
insertHtml=function(l){
+
insertHtml = function(l) {
   this.fire('insertHtml',l);
+
   this.fire('insertHtml', l);
 
}
 
}
  
setData=function(l){
+
setData = function(l) {
   var m={dataValue:l};
+
   var m = {
   this.fire('setData',m);
+
    dataValue: l
   this._.data=m.dataValue;
+
  };
   this.fire('afterSetData',m);
+
   this.fire('setData', m);
 +
   this._.data = m.dataValue;
 +
   this.fire('afterSetData', m);
 
}
 
}
  
loadSnapshot=function(l){
+
loadSnapshot = function(l) {
   this.fire('loadSnapshot',l);
+
   this.fire('loadSnapshot', l);
 
}
 
}
  
getSnapshot=function(){
+
getSnapshot = function() {
   var l=this.fire('getSnapshot');
+
   var l = this.fire('getSnapshot');
   if(typeof l!='string'){
+
   if (typeof l != 'string') {
     var m=this.element;
+
     var m = this.element;
     if(m&&this.elementMode==1)l=m.is('textarea')?m.getValue():m.getHtml();
+
     if (m && this.elementMode == 1) l = m.is('textarea') ? m.getValue() : m.getHtml();
 
   }
 
   }
 
   return l;
 
   return l;
 
}
 
}
  
getData=function(){
+
getData = function() {
   var n=this;
+
   var n = this;
 
   n.fire('beforeGetData');
 
   n.fire('beforeGetData');
   var l=n._.data;
+
   var l = n._.data;
   if(typeof l!='string'){
+
   if (typeof l != 'string') {
     var m=n.element;
+
     var m = n.element;
     if(m&&n.elementMode==1)l=m.is('textarea')?m.getValue():m.getHtml();
+
     if (m && n.elementMode == 1) l = m.is('textarea') ? m.getValue() : m.getHtml();
     else l='';
+
     else l = '';
 
   }
 
   }
   l={dataValue:l};
+
   l = {
   n.fire('getData',l);
+
    dataValue: l
 +
  };
 +
   n.fire('getData', l);
 
   return l.dataValue;
 
   return l.dataValue;
 
}
 
}
  
getCommand=function(l){
+
getCommand = function(l) {
 
   return this._.commands[l];
 
   return this._.commands[l];
 
}
 
}
  
execCommand=function(l,m){
+
execCommand = function(l, m) {
   var n=this.getCommand(l),o={name:l,commandData:m,command:n};
+
   var n = this.getCommand(l),
   if(n&&n.state!=0)if(this.fire('beforeCommandExec',o)!==true){
+
  o = {
     o.returnValue=n.exec(o.commandData);
+
    name: l,
     if(this.fire('afterCommandExec',o)!==true)return o.returnValue;
+
    commandData: m,
 +
    command: n
 +
  };
 +
   if (n && n.state != 0) if (this.fire('beforeCommandExec', o) !== true) {
 +
     o.returnValue = n.exec(o.commandData);
 +
     if (this.fire('afterCommandExec', o) !== true) return o.returnValue;
 
   }
 
   }
 
   return false;
 
   return false;
 
}
 
}
  
destroy=function(l){
+
destroy = function(l) {
   var m=this;
+
   var m = this;
   if(!l)m.updateElement();
+
   if (!l) m.updateElement();
 
   m.theme.destroy(m);
 
   m.theme.destroy(m);
 
   a.remove(m);
 
   a.remove(m);
 
}
 
}
  
addCss=function(l){
+
addCss = function(l) {
 
   this._.styles.push(l);
 
   this._.styles.push(l);
 
}
 
}
  
addCommand=function(l,m){
+
addCommand = function(l, m) {
   return this._.commands[l]=new a.command(this,m);
+
   return this._.commands[l] = new a.command(this, m);
 
}
 
}
  
hasListeners=function(){
+
hasListeners = function() {
   var f=this;
+
   var f = this;
   if(!(f._&&f._.events))a.event.call(f);
+
   if (! (f._ && f._.events)) a.event.call(f);
   (f[e]=a.event.prototype[e]).apply(f,arguments);
+
   (f[e] = a.event.prototype[e]).apply(f, arguments);
 
}
 
}
  
removeListener=function(){
+
removeListener = function() {
   var f=this;
+
   var f = this;
   if(!(f._&&f._.events))a.event.call(f);
+
   if (! (f._ && f._.events)) a.event.call(f);
   (f[e]=a.event.prototype[e]).apply(f,arguments);
+
   (f[e] = a.event.prototype[e]).apply(f, arguments);
 
}
 
}
  
fireOnce=function(b,c){
+
fireOnce = function(b, c) {
   return a.event.prototype.fireOnce.call(this,b,c,this);
+
   return a.event.prototype.fireOnce.call(this, b, c, this);
 
}
 
}
  
fire=function(b,c){
+
fire = function(b, c) {
   return a.event.prototype.fire.call(this,b,c,this);
+
   return a.event.prototype.fire.call(this, b, c, this);
 
}
 
}
  
_=[object Object]
+
_ = [object Object]
elementMode=1
+
elementMode = 1
_init=function(){
+
_init = function() {
   var z=this;
+
   var z = this;
   var x=g.get(z._.element),y=z._.instanceConfig;
+
   var x = g.get(z._.element),
 +
  y = z._.instanceConfig;
 
   delete z._.element;
 
   delete z._.element;
 
   delete z._.instanceConfig;
 
   delete z._.instanceConfig;
   z._.commands={};
+
   z._.commands = {};
   z._.styles=[];
+
   z._.styles = [];
   z.element=x;
+
   z.element = x;
   z.name=x&&z.elementMode==1&&(x.getId()||x.getNameAtt())||m();
+
   z.name = x && z.elementMode == 1 && (x.getId() || x.getNameAtt()) || m();
   z.config=e.prototypedCopy(i);
+
   z.config = e.prototypedCopy(i);
   z.ui=new k(z);
+
   z.ui = new k(z);
   z.focusManager=new a.focusManager(z);
+
   z.focusManager = new a.focusManager(z);
   a.fire('instanceCreated',null,z);
+
   a.fire('instanceCreated', null, z);
   z.on('mode',w);
+
   z.on('mode', w);
   p(z,y);
+
   p(z, y);
 
}
 
}
  
element=[object Object]
+
element = [object Object]
name=input_memo
+
name = input_memo
config=[object Object]
+
config = [object Object]
ui=[object Object]
+
ui = [object Object]
focusManager=[object Object]
+
focusManager = [object Object]
on=function(c,d,e,f,g){
+
on = function(c, d, e, f, g) {
   var h=this._.events[c]||(this._.events[c]=new b(c));
+
   var h = this._.events[c] || (this._.events[c] = new b(c));
   if(h.getListenerIndex(d)<0){
+
   if (h.getListenerIndex(d) < 0) {
     var i=h.listeners;
+
     var i = h.listeners;
     if(!e)e=this;
+
     if (!e) e = this;
     if(isNaN(g))g=10;
+
     if (isNaN(g)) g = 10;
     var j=this,k=function(m,n,o,p){
+
     var j = this,
    var q={name:c,sender:this,editor:m,data:n,listenerData:f,stop:o,cancel:p,
+
    k = function(m, n, o, p) {
      removeListener:function(){
+
      var q = {
        j.removeListener(c,d);
+
        name: c,
       }
+
        sender: this,
 +
        editor: m,
 +
        data: n,
 +
        listenerData: f,
 +
        stop: o,
 +
        cancel: p,
 +
        removeListener: function() {
 +
          j.removeListener(c, d);
 +
        }
 +
       };
 +
      d.call(e, q);
 +
      return q.data;
 
     };
 
     };
  d.call(e,q);
 
  return q.data;
 
};
 
  
k.fn=d;
+
    k.fn = d;
k.priority=g;
+
    k.priority = g;
for(var l=i.length-1;l>=0;l--)
+
    for (var l = i.length - 1; l >= 0; l--)
  if(i[l].priority<=g){
+
    if (i[l].priority <= g) {
    i.splice(l+1,0,k);
+
      i.splice(l + 1, 0, k);
     return;
+
      return;
 +
     }
 +
    i.unshift(k);
 +
 
 
   }
 
   }
i.unshift(k);
 
 
 
}
 
}
}
 
 
 
</pre>
 
</pre>
  
Line 311: Line 351:
  
 
If you find yourself able to use any of these functions, please create your account here on the wiki and document it. The developers of CKeditor are working crazily on coding CKEditor v3.
 
If you find yourself able to use any of these functions, please create your account here on the wiki and document it. The developers of CKeditor are working crazily on coding CKEditor v3.
 +
 +
== getting the CKeditor focus using the API ==
 +
 +
<br>
 +
 +
 +
 +
To respond to the focus event of the editor:
 +
 +
 +
 +
<pre>var my_id='your_editor_id'; //this is the same as the id of the replaced text field
 +
var the_ed=CKEDITOR.instances[my_id]
 +
//respond to focus event
 +
the_ed.on( 'focus', function()
 +
 +
  //show the editor data as example
 +
  alert(this.getData());
 +
});</pre>

Latest revision as of 09:42, 12 October 2009

Script Name

If you do not use "ckeditor.js" in your install, either because you roll this into a larger script or because you use a different suffix like ".var", you will need to set the global varaible "CKEDITOR_BASEPATH" to the path to the CKEditor install -- otherwise CKEditor will fail to auto-detect the base path and various things like the language libraries will not load. Note that this global JavaScript variable must be set before you include the ckeditor script.

> I've added this information to the page. --FredCK 08:42, 12 October 2009 (UTC)

Javascript API

I couldn't find documentation on how to talk to the javascript API. I figured that through CKEDITOR.instances.id_of_textarea.setData(string); I could update the contents or get it with getData();

First thing I learned I can also access an instance of an editor through: CKEDITOR.instances["id_of_textarea"].setData(string); //This is more usefull in generic code.

I wanted to see which functions are available for me and show that in... the editor itself. I did the following.

var objEditor = CKEDITOR.instances["id_of_textarea"];
var str = "";
for (var item in objEditor) {
  str += "<strong>" + item + "</strong>=" + objEditor[item].toString().str_replace("\n", "<br>").str_replace(";", ";<br>  ").str_replace("{", "{<br>  ").str_replace("}", "}<br>").str_replace(";<br>  }", ";<br>}") + "<br>";
}
objEditor.setData(str);

With this output (I aligned the code a bit for readibility):

getThemeSpace = function(l) {
  var m = 'cke_' + l,
  n = this._[m] || (this._[m] = a.document.getById(m + '_' + this.name));
  return n;
}

focus = function() {
  var n = l(this);
  if (n) n.focus();
}

setMode = function(n) {
  var o, p = this.getThemeSpace('contents'),
  q = this.checkDirty();
  if (this.mode) {
    if (n == this.mode) return;
    var r = l(this);
    o = r.getData();
    r.unload(p);
    this.mode = '';
  }
  p.setHtml('');
  var s = l(this, n);
  if (!s) throw '[CKEDITOR.editor.setMode] Unknown mode "' + n + '".';
  if (!q) this.on('mode',
  function() {
    this.resetDirty();
    this.removeListener('mode', arguments.callee);
  });
  s.load(p, typeof o != 'string' ? this.getData() : o);
}

addMode = function(n, o) {
  o.name = n;
  (this._.modes || (this._.modes = {}))[n] = o;
}

mode = openDialog = function(l) {
  var m = a.dialog._.dialogDefinitions[l];
  if (typeof m == 'function') {
    var n = this._.storedDialogs || (this._.storedDialogs = {}),
    o = n[l] || (n[l] = new a.dialog(this, l));
    o.show();
    return o;
  }
  var p = a.document.getBody(),
  q = p.$.style.cursor,
  r = this;
  p.setStyle('cursor', 'wait');
  a.scriptLoader.load(a.getUrl(m),
  function() {
    r.openDialog(l);
    p.setStyle('cursor', q);
  });
  return null;
}

restoreRealElement = function(l) {
  var m = decodeURIComponent(l.getAttribute('_cke_realelement'));
  return g.createFromHtml(m, this.document);
}

createFakeParserElement = function(l, m, n, o) {
  var p = new a.htmlParser.basicWriter();
  l.writeHtml(p);
  var q = p.getHtml(),
  r = {
    'class': m,
    src: a.getUrl('images/spacer.gif'),
    _cke_realelement: encodeURIComponent(q)
  };
  if (n) r._cke_real_element_type = n;
  if (o) r._cke_resizable = o;
  return new a.htmlParser.element('img', r);
}

createFakeElement = function(l, m, n, o) {
  var p = {
    'class': m,
    src: a.getUrl('images/spacer.gif'),
    _cke_realelement: encodeURIComponent(l.getOuterHtml())
  };

  if (n) p._cke_real_element_type = n;
  if (o) p._cke_resizable = o;
  return this.document.createElement('img', {
    attributes: p
  });
}

forceNextSelectionCheck = function() {
  delete this._.selectionPreviousPath;
}

getSelection = function() {
  var u = this;
  var s = u.document ? u.document.getSelection() : null;
  if (s && c) {
    var t = s.getNative().createRange();
    if (!t) return null;
    else if (t.item) return t.item(0).ownerDocument == u.document.$ ? s: null;
    else return t.parentElement().ownerDocument == u.document.$ ? s: null;
  }
  return s;
}

getMenuItem = function(l) {
  return this._.menuItems[l];
}

addMenuItems = function(l) {
  for (var m in l) this.addMenuItem(m, l[m]);
}

addMenuItem = function(l, m) {
  if (this._.menuGroups[m.group]) this._.menuItems[l] = new a.menuItem(this, l, m);
}

attachStyleStateChange = function(l, m) {
  var n = this._.styleStateChangeCallbacks;
  if (!n) {
    n = this._.styleStateChangeCallbacks = [];
    this.on('selectionChange',
    function(o) {
      for (var p = 0; p p++) {
        var q = n[p],
        r = q.style.checkActive(o.data.path) ? 1 : 2;
        if (q.state !== r) {
          q.fn.call(this, r);
          q.state !== r;
        }
      }
    });
  }
  n.push({
    style: l,
    fn: m
  });
}

insertText = function(l) {
  l = e.htmlEncode(l);
  l = l.replace(/(?:\r\n)|\n|\r/g, '
');
  this.insertHtml(l);
}

updateElement = function() {
  var m = this;
  var l = m.element;
  if (l && m.elementMode == 1) if (l.is('textarea')) l.setValue(m.getData());
  else l.setHtml(m.getData());
}

resetDirty = function() {
  if (this.mayBeDirty) this._.previousValue = this.getSnapshot();
}

checkDirty = function() {
  return this.mayBeDirty && this._.previousValue !== this.getSnapshot();
}

insertElement = function(l) {
  this.fire('insertElement', l);
}

insertHtml = function(l) {
  this.fire('insertHtml', l);
}

setData = function(l) {
  var m = {
    dataValue: l
  };
  this.fire('setData', m);
  this._.data = m.dataValue;
  this.fire('afterSetData', m);
}

loadSnapshot = function(l) {
  this.fire('loadSnapshot', l);
}

getSnapshot = function() {
  var l = this.fire('getSnapshot');
  if (typeof l != 'string') {
    var m = this.element;
    if (m && this.elementMode == 1) l = m.is('textarea') ? m.getValue() : m.getHtml();
  }
  return l;
}

getData = function() {
  var n = this;
  n.fire('beforeGetData');
  var l = n._.data;
  if (typeof l != 'string') {
    var m = n.element;
    if (m && n.elementMode == 1) l = m.is('textarea') ? m.getValue() : m.getHtml();
    else l = '';
  }
  l = {
    dataValue: l
  };
  n.fire('getData', l);
  return l.dataValue;
}

getCommand = function(l) {
  return this._.commands[l];
}

execCommand = function(l, m) {
  var n = this.getCommand(l),
  o = {
    name: l,
    commandData: m,
    command: n
  };
  if (n && n.state != 0) if (this.fire('beforeCommandExec', o) !== true) {
    o.returnValue = n.exec(o.commandData);
    if (this.fire('afterCommandExec', o) !== true) return o.returnValue;
  }
  return false;
}

destroy = function(l) {
  var m = this;
  if (!l) m.updateElement();
  m.theme.destroy(m);
  a.remove(m);
}

addCss = function(l) {
  this._.styles.push(l);
}

addCommand = function(l, m) {
  return this._.commands[l] = new a.command(this, m);
}

hasListeners = function() {
  var f = this;
  if (! (f._ && f._.events)) a.event.call(f);
  (f[e] = a.event.prototype[e]).apply(f, arguments);
}

removeListener = function() {
  var f = this;
  if (! (f._ && f._.events)) a.event.call(f);
  (f[e] = a.event.prototype[e]).apply(f, arguments);
}

fireOnce = function(b, c) {
  return a.event.prototype.fireOnce.call(this, b, c, this);
}

fire = function(b, c) {
  return a.event.prototype.fire.call(this, b, c, this);
}

_ = [object Object]
elementMode = 1
_init = function() {
  var z = this;
  var x = g.get(z._.element),
  y = z._.instanceConfig;
  delete z._.element;
  delete z._.instanceConfig;
  z._.commands = {};
  z._.styles = [];
  z.element = x;
  z.name = x && z.elementMode == 1 && (x.getId() || x.getNameAtt()) || m();
  z.config = e.prototypedCopy(i);
  z.ui = new k(z);
  z.focusManager = new a.focusManager(z);
  a.fire('instanceCreated', null, z);
  z.on('mode', w);
  p(z, y);
}

element = [object Object]
name = input_memo
config = [object Object]
ui = [object Object]
focusManager = [object Object]
on = function(c, d, e, f, g) {
  var h = this._.events[c] || (this._.events[c] = new b(c));
  if (h.getListenerIndex(d) < 0) {
    var i = h.listeners;
    if (!e) e = this;
    if (isNaN(g)) g = 10;
    var j = this,
    k = function(m, n, o, p) {
      var q = {
        name: c,
        sender: this,
        editor: m,
        data: n,
        listenerData: f,
        stop: o,
        cancel: p,
        removeListener: function() {
          j.removeListener(c, d);
        }
      };
      d.call(e, q);
      return q.data;
    };

    k.fn = d;
    k.priority = g;
    for (var l = i.length - 1; l >= 0; l--)
    if (i[l].priority <= g) {
      i.splice(l + 1, 0, k);
      return;
    }
    i.unshift(k);

  }
}

Anybody who wishes to talk to an instance of the CKeditor through the javascript API, now has a starting point and is able to see which functions are available for an instance of an CKeditor.

If you find yourself able to use any of these functions, please create your account here on the wiki and document it. The developers of CKeditor are working crazily on coding CKEditor v3.

getting the CKeditor focus using the API



To respond to the focus event of the editor:


var my_id='your_editor_id'; //this is the same as the id of the replaced text field
var the_ed=CKEDITOR.instances[my_id]
//respond to focus event
the_ed.on( 'focus', function()

  //show the editor data as example
  alert(this.getData());
});
This page was last edited on 12 October 2009, at 09:42.