X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Findent%2Fplugin.js;h=c36370c1d56fa5c6126b8b540a8061cd8efaa94f;hb=48b1db88210b4160dce439c6e3e32e14af8c106b;hp=50b13567bb60e2dc9fe3a67ce9c1acf43bf37077;hpb=039a051ccf3901311661022a30afd60fc38130c9;p=ckeditor.git
diff --git a/_source/plugins/indent/plugin.js b/_source/plugins/indent/plugin.js
index 50b1356..c36370c 100644
--- a/_source/plugins/indent/plugin.js
+++ b/_source/plugins/indent/plugin.js
@@ -1,5 +1,5 @@
/*
-Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
+Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/
@@ -9,16 +9,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
(function()
{
- var listNodeNames = { ol : 1, ul : 1 };
-
- var isNotWhitespaces = CKEDITOR.dom.walker.whitespaces( true ),
+ var listNodeNames = { ol : 1, ul : 1 },
+ isNotWhitespaces = CKEDITOR.dom.walker.whitespaces( true ),
isNotBookmark = CKEDITOR.dom.walker.bookmark( false, true );
- function setState( editor, state )
- {
- editor.getCommand( this.name ).setState( state );
- }
-
function onSelectionChange( evt )
{
var editor = evt.editor;
@@ -27,15 +21,15 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
list = elementPath && elementPath.contains( listNodeNames );
if ( list )
- return setState.call( this, editor, CKEDITOR.TRISTATE_OFF );
+ return this.setState( CKEDITOR.TRISTATE_OFF );
if ( !this.useIndentClasses && this.name == 'indent' )
- return setState.call( this, editor, CKEDITOR.TRISTATE_OFF );
+ return this.setState( CKEDITOR.TRISTATE_OFF );
var path = evt.data.path,
firstBlock = path.block || path.blockLimit;
if ( !firstBlock )
- return setState.call( this, editor, CKEDITOR.TRISTATE_DISABLED );
+ return this.setState( CKEDITOR.TRISTATE_DISABLED );
if ( this.useIndentClasses )
{
@@ -48,8 +42,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
}
if ( ( this.name == 'outdent' && !indentStep ) ||
( this.name == 'indent' && indentStep == editor.config.indentClasses.length ) )
- return setState.call( this, editor, CKEDITOR.TRISTATE_DISABLED );
- return setState.call( this, editor, CKEDITOR.TRISTATE_OFF );
+ return this.setState( CKEDITOR.TRISTATE_DISABLED );
+ return this.setState( CKEDITOR.TRISTATE_OFF );
}
else
{
@@ -57,8 +51,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
if ( isNaN( indent ) )
indent = 0;
if ( indent <= 0 )
- return setState.call( this, editor, CKEDITOR.TRISTATE_DISABLED );
- return setState.call( this, editor, CKEDITOR.TRISTATE_OFF );
+ return this.setState( CKEDITOR.TRISTATE_DISABLED );
+ return this.setState( CKEDITOR.TRISTATE_OFF );
}
}
@@ -78,9 +72,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
}
// Returns the CSS property to be used for identing a given element.
- function getIndentCssProperty( element )
+ function getIndentCssProperty( element, dir )
{
- return element.getComputedStyle( 'direction' ) == 'ltr' ? 'margin-left' : 'margin-right';
+ return ( dir || element.getComputedStyle( 'direction' ) ) == 'ltr' ? 'margin-left' : 'margin-right';
}
function isListItem( node )
@@ -157,8 +151,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
// Convert the array back to a DOM forest (yes we might have a few subtrees now).
// And replace the old list with the new forest.
- var newListDir = listNode.getAttribute( 'dir' ) || listNode.getStyle( 'direction' );
- var newList = CKEDITOR.plugins.list.arrayToList( listArray, database, null, editor.config.enterMode, newListDir );
+ var newList = CKEDITOR.plugins.list.arrayToList( listArray, database, null, editor.config.enterMode, listNode.getDirection() );
// Avoid nested
after outdent even they're visually same,
// recording them for later refactoring.(#3982)
@@ -216,11 +209,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
iterator.enforceRealBlocks = true;
iterator.enlargeBr = enterMode != CKEDITOR.ENTER_BR;
var block;
- while ( ( block = iterator.getNextParagraph() ) )
+ while ( ( block = iterator.getNextParagraph( enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) ) )
indentElement( block );
}
- function indentElement( element )
+ function indentElement( element, dir )
{
if ( element.getCustomData( 'indent_processed' ) )
return false;
@@ -248,15 +241,13 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
indentStep = Math.min( indentStep, editor.config.indentClasses.length );
indentStep = Math.max( indentStep, 0 );
- var className = CKEDITOR.tools.ltrim( element.$.className.replace( self.classNameRegex, '' ) );
- if ( indentStep < 1 )
- element.$.className = className;
- else
+ element.$.className = CKEDITOR.tools.ltrim( element.$.className.replace( self.classNameRegex, '' ) );
+ if ( indentStep > 0 )
element.addClass( editor.config.indentClasses[ indentStep - 1 ] );
}
else
{
- var indentCssProperty = getIndentCssProperty( element ),
+ var indentCssProperty = getIndentCssProperty( element, dir ),
currentOffset = parseInt( element.getStyle( indentCssProperty ), 10 );
if ( isNaN( currentOffset ) )
currentOffset = 0;
@@ -328,10 +319,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
if ( nearestListBlock )
{
- var firstListItem = nearestListBlock.getFirst( function( node )
- {
- return node.type == CKEDITOR.NODE_ELEMENT && node.is( 'li' );
- }),
+ var firstListItem = nearestListBlock.getFirst( isListItem ),
+ hasMultipleItems = !!firstListItem.getNext( isListItem ),
rangeStart = range.startContainer,
indentWholeList = firstListItem.equals( rangeStart ) || firstListItem.contains( rangeStart );
@@ -339,7 +328,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
// Only do that for indenting or when using indent classes or when there is something to outdent. (#6141)
if ( !( indentWholeList &&
( self.name == 'indent' || self.useIndentClasses || parseInt( nearestListBlock.getStyle( getIndentCssProperty( nearestListBlock ) ), 10 ) ) &&
- indentElement( nearestListBlock ) ) )
+ indentElement( nearestListBlock, !hasMultipleItems && firstListItem.getDirection() ) ) )
indentList( nearestListBlock );
}
else
@@ -359,10 +348,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
init : function( editor )
{
// Register commands.
- var indent = new indentCommand( editor, 'indent' ),
- outdent = new indentCommand( editor, 'outdent' );
- editor.addCommand( 'indent', indent );
- editor.addCommand( 'outdent', outdent );
+ var indent = editor.addCommand( 'indent', new indentCommand( editor, 'indent' ) ),
+ outdent = editor.addCommand( 'outdent', new indentCommand( editor, 'outdent' ) );
// Register the toolbar buttons.
editor.ui.addButton( 'Indent',
@@ -395,8 +382,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
editor.on( 'dirChanged', function( e )
{
var range = new CKEDITOR.dom.range( editor.document );
- range.setStartBefore( e.data );
- range.setEndAfter( e.data );
+ range.setStartBefore( e.data.node );
+ range.setEndAfter( e.data.node );
var walker = new CKEDITOR.dom.walker( range ),
node;
@@ -406,13 +393,28 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
if ( node.type == CKEDITOR.NODE_ELEMENT )
{
// A child with the defined dir is to be ignored.
- if ( !node.equals( e.data ) && node.getDirection() )
+ if ( !node.equals( e.data.node ) && node.getDirection() )
{
range.setStartAfter( node );
walker = new CKEDITOR.dom.walker( range );
continue;
}
+ // Switch alignment classes.
+ var classes = editor.config.indentClasses;
+ if ( classes )
+ {
+ var suffix = ( e.data.dir == 'ltr' ) ? [ '_rtl', '' ] : [ '', '_rtl' ];
+ for ( var i = 0; i < classes.length; i++ )
+ {
+ if ( node.hasClass( classes[ i ] + suffix[ 0 ] ) )
+ {
+ node.removeClass( classes[ i ] + suffix[ 0 ] );
+ node.addClass( classes[ i ] + suffix[ 1 ] );
+ }
+ }
+ }
+
// Switch the margins.
var marginLeft = node.getStyle( 'margin-right' ),
marginRight = node.getStyle( 'margin-left' );
@@ -430,6 +432,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
/**
* Size of each indentation step
+ * @name CKEDITOR.config.indentOffset
* @type Number
* @default 40
* @example
@@ -438,6 +441,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
/**
* Unit for the indentation style
+ * @name CKEDITOR.config.indentUnit
* @type String
* @default 'px'
* @example
@@ -447,6 +451,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
/**
* List of classes to use for indenting the contents. If it's null, no classes will be used
* and instead the {@link #indentUnit} and {@link #indentOffset} properties will be used.
+ * @name CKEDITOR.config.indentClasses
* @type Array
* default null
* @example