plugin.cs中具体的代码如下:(function()
{
function onSelectionChange( evt )
{
if ( evt.editor.readOnly )
return null;
var elementPath = evt.data.path,
firstBlock = elementPath.block || elementPath.blockLimit;
if ( !firstBlock )
return this.setState( CKEDITOR.TRISTATE_DISABLED );
var indent = parseInt( firstBlock.getStyle( this.name ), 10 );
if ( isNaN( indent ) )
indent = 0;
if ( indent <= 0 ){
return this.setState( CKEDITOR.TRISTATE_DISABLED );
}
return this.setState( CKEDITOR.TRISTATE_OFF );
}
function pindentCommand( editor, name, value )
{
this.editor = editor;
this.name = name;
this.value = value;
}
pindentCommand.prototype = {
exec : function( editor )
{
var selection = editor.getSelection(),//检索范围内的可编辑元素的编辑选择 做一个范围出来
enterMode = editor.config.enterMode;//设置输入键的行为 p br div
if ( !selection )//如果这个范围是空的
return;//就直接跳出
var books = selection.createBooks(),//给这个范围做一个便签 避免干扰的别的元素
ranges = selection.getRanges( true );//得到当前的选择 得到当前的范围????
var iterator,//迭代器
block;//终止
var useComputedState = editor.config.useComputedState;//用户计算机的状态
useComputedState = useComputedState === undefined || useComputedState;//不懂
for ( var i = ranges.length - 1 ; i >= 0 ; i-- )
{
iterator = ranges[ i ].createIterator();//创建一个迭代器
iterator.enlargeBr = enterMode != CKEDITOR.ENTER_BR;
while ( ( block = iterator.getNextParagraph( enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) ) )
{
var currentOffset = parseInt( block.getStyle( this.name ), 10 );
if ( isNaN( currentOffset ) )
currentOffset = 0;
var indentOffset = currentOffset + parseInt(this.value,10);
//var apply =
//( this.state == CKEDITOR.TRISTATE_OFF ) &&
//( !useComputedState || ( getTextIndent( block, true ) != this.value ) );
//if ( apply ){
block.setStyle( this.name, indentOffset + "px" );
//}
}
}
editor.focus();
editor.forceNextSelectionCheck();
selection.selectBooks( books );
}
};
CKEDITOR.plugins.add( 'pindent',
{
init : function( editor )
{
var pindentTopPlus = new pindentCommand( editor, 'margin-top', '5' );
//var pindentTopDec = new pindentCommand( editor, 'margin-top', '-5' );
//var pindentBottomPlus = new pindentCommand( editor, 'margin-bottom', '5' );
//var pindentBottomDec = new pindentCommand( editor, 'margin-bottom', '-5' );
editor.addCommand( 'pindentTopPlus', pindentTopPlus );
//editor.addCommand( 'pindentTopDec', pindentTopDec );
//editor.addCommand( 'pindentBottomPlus', pindentBottomPlus );
//editor.addCommand( 'pindentBottomDec', pindentBottomDec );
editor.ui.addButton( 'PIndentTopPlus',
{
label : '增加段前距',
command : 'pindentTopPlus',
icon: this.path + 'images/pindent1.gif'
} );
/*
editor.ui.addButton( 'PIndentTopDec',
{
label : '减少段前距',
command : 'pindentTopDec',
 icon: this.path + 'images/pindent2.gif'
} );
editor.ui.addButton( 'PIndentBottomPlus',
{
label : '增加段后距',
command : 'pindentBottomPlus',
 icon: this.path + 'images/pindent3.gif'
} );
editor.ui.addButton( 'PIndentBottomDec',
{
label : '减少段后距',
command : 'pindentBottomDec',
 icon: this.path + 'images/pindent4.gif'
} );
*/
//editor.on( 'selectionChange', CKEDITOR.tools.bind( onSelectionChange, pindentTopPlus ) );
//editor.on( 'selectionChange', CKEDITOR.tools.bind( onSelectionChange, pindentTopDec ) );
//editor.on( 'selectionChange', CKEDITOR.tools.bind( onSelectionChange, pindentBottomPlus ) );
//editor.on( 'selectionChange', CKEDITOR.tools.bind( onSelectionChange, pindentBottomDec ) );
},
requires : [ 'domiterator' ] //DOM迭代器
});
})();
PS:注释都是我自己乱写的 不对..我理解错误的请指出来 谢谢
另求大神 能帮我都注释一下 谢谢啦ckeditor二次开发javascript插件