Topic: If you have troubles placing the cursor after the last table...
If you have problems placing cursor after a table at the very end of the document, create this plugin and add it to the configuration.
TinyMCE expects two files: editor_plugin_src.js and editor_plugin.js.
The first is the source code in "readable" format, the second is expected to be the first with all whitespaces and comments stripped out.
If you don't like to "compress" the file too often (just as I do), you may just create a symbolic link or copy *_src.js to *.js.
tinyMCE.init({
plugins : "trailing",
});plugins/trailing/editor_plugin_src.js:
/**
* $Id$
*
* Add trailing element while editing, to enable placing the cursor at the end of the body.
*
* The original code and idea comes from EditorEnhancements plugin by tan@enonic.com
* https://sourceforge.net/tracker/index.php?func=detail&aid=2005530&group_id=103281&atid=738747
* http://www.enonic.com
*
* Author: Mariusz P?kala (Arsen7) <skoot@qi.pl>
*/
(function() {
tinymce.create('tinymce.plugins.Trailing', {
init : function(ed, url) {
var t = this;
ed.onSetContent.add( function(ed,o) {
t._insertTrailingElement(ed);
});
ed.onNodeChange.add( function(ed, cm, e) {
t._insertTrailingElement(ed);
});
ed.onBeforeGetContent.add( function(ed, o) {
t._removeTrailingElement(ed);
});
},
getInfo : function() {
return {
longname : 'Trailing Element Fix (based on EditorEnhancements by tan@enonic.com)',
author : 'm.pekala@idelfi.com',
authorurl : 'http://idelfi.com',
infourl : 'http://idelfi.com/tiny_mce/trailing_plugin.html',
version : '1.0'
};
},
/* Private methods */
_insertTrailingElement : function(ed) {
var body = ed.getBody();
var lc = body && body.lastChild;
var fc = body && body.firstChild;
if(!body || !lc || !fc)
return;
try {
if( lc.nodeType == 1 && lc.nodeName.toLowerCase() != 'p' && (!lc.innerHTML.match(/^(\s|<br\s*\/?>| )*$/i) || !lc.firstChild) ) {
body.appendChild( ed.dom.create('p',{},'<br/>') );
}
if( fc.nodeType == 1 && fc.nodeName.toLowerCase() != 'p' && (!fc.innerHTML.match(/^(\s|<br\s*\/?>| )*$/i) || !fc.firstChild) ) {
body.insertBefore( ed.dom.create('p',{},'<br/>') , fc);
}
} catch(err) {
if( typeof(console) == 'object' && console.error )
console.error("TrailingPlugin._insertTrailingElement (ignored) : " + err);
}
},
_removeTrailingElement : function(ed) {
var body = ed.getBody();
if(!body)
return;
var last, limit_l = 1, first, limit_f = 1;
try {
while( (last = body.lastChild) && last.nodeType == 1 && last.nodeName.toLowerCase() == 'p' &&
last.innerHTML.match(/^(\s|<br\s*\/?>| )*$/i) ) {
body.removeChild(last);
if(limit_l-- < 1)
break;
}
while( (first = body.firstChild) && first.nodeType == 1 && first.nodeName.toLowerCase() == 'p' &&
first.innerHTML.match(/^(\s|<br\s*\/?>| )*$/i) ) {
body.removeChild(first);
if(limit_f-- < 1)
break;
}
} catch(err) {
if( typeof(console) == 'object' && console.error )
console.error("TrailingPlugin._removeTrailingElement (ignored) : " + err);
}
}
});
tinymce.PluginManager.add('trailing', tinymce.plugins.Trailing);
})();
// vim: ts=8 sw=8 sts=8 expandtabLast edited by Arsen7 (2009-06-16 11:03:18)