X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Flist%2Fplugin.js;h=ad791533b8b823cc3830b0fbf4a984eff5e3269e;hb=refs%2Ftags%2Fv3.6.2;hp=3a47c55824b7970e89d8be9504abd27e52e2094c;hpb=614511639979907ceb0da3614122a4d8eb963ad4;p=ckeditor.git
diff --git a/_source/plugins/list/plugin.js b/_source/plugins/list/plugin.js
index 3a47c55..ad79153 100644
--- a/_source/plugins/list/plugin.js
+++ b/_source/plugins/list/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
*/
@@ -16,6 +16,20 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
bookmarks = CKEDITOR.dom.walker.bookmark(),
nonEmpty = function( node ){ return !( whitespaces( node ) || bookmarks( node ) ); };
+ function cleanUpDirection( element )
+ {
+ var dir, parent, parentDir;
+ if ( ( dir = element.getDirection() ) )
+ {
+ parent = element.getParent();
+ while ( parent && !( parentDir = parent.getDirection() ) )
+ parent = parent.getParent();
+
+ if ( dir == parentDir )
+ element.removeAttribute( 'dir' );
+ }
+ }
+
CKEDITOR.plugins.list = {
/*
* Convert a DOM list tree into a data structure that is easier to
@@ -38,6 +52,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
{
var listItem = listNode.getChild( i );
+ // Fixing malformed nested lists by moving it into a previous list item. (#6236)
+ if( listItem.type == CKEDITOR.NODE_ELEMENT && listItem.getName() in CKEDITOR.dtd.$list )
+ CKEDITOR.plugins.list.listToArray( listItem, database, baseArray, baseIndentLevel + 1 );
+
// It may be a text node or some funny stuff.
if ( listItem.$.nodeName.toLowerCase() != 'li' )
continue;
@@ -83,10 +101,14 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
currentIndex = baseIndex,
indentLevel = Math.max( listArray[ baseIndex ].indent, 0 ),
currentListItem = null,
+ orgDir,
paragraphName = ( paragraphMode == CKEDITOR.ENTER_P ? 'p' : 'div' );
while ( 1 )
{
var item = listArray[ currentIndex ];
+
+ orgDir = item.element.getDirection( 1 );
+
if ( item.indent == indentLevel )
{
if ( !rootNode || listArray[ currentIndex ].parent.getName() != rootNode.getName() )
@@ -96,30 +118,40 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
retval.append( rootNode );
}
currentListItem = rootNode.append( item.element.clone( 0, 1 ) );
+
+ if ( orgDir != rootNode.getDirection( 1 ) )
+ currentListItem.setAttribute( 'dir', orgDir );
+
for ( var i = 0 ; i < item.contents.length ; i++ )
currentListItem.append( item.contents[i].clone( 1, 1 ) );
currentIndex++;
}
else if ( item.indent == Math.max( indentLevel, 0 ) + 1 )
{
- var listData = CKEDITOR.plugins.list.arrayToList( listArray, null, currentIndex, paragraphMode );
+ // Maintain original direction (#6861).
+ var currDir = listArray[ currentIndex - 1 ].element.getDirection( 1 ),
+ listData = CKEDITOR.plugins.list.arrayToList( listArray, null, currentIndex, paragraphMode,
+ currDir != orgDir ? orgDir: null );
+
+ // If the next block is an
with another list tree as the first
+ // child, we'll need to append a filler (
/NBSP) or the list item
+ // wouldn't be editable. (#6724)
+ if ( !currentListItem.getChildCount() && CKEDITOR.env.ie && !( doc.$.documentMode > 7 ))
+ currentListItem.append( doc.createText( '\xa0' ) );
currentListItem.append( listData.listNode );
currentIndex = listData.nextIndex;
}
else if ( item.indent == -1 && !baseIndex && item.grandparent )
{
- currentListItem;
if ( listNodeNames[ item.grandparent.getName() ] )
currentListItem = item.element.clone( false, true );
else
{
// Create completely new blocks here.
- if ( dir || item.element.hasAttributes() ||
- ( paragraphMode != CKEDITOR.ENTER_BR && item.grandparent.getName() != 'td' ) )
+ if ( dir || item.element.hasAttributes() || paragraphMode != CKEDITOR.ENTER_BR )
{
currentListItem = doc.createElement( paragraphName );
item.element.copyAttributes( currentListItem, { type:1, value:1 } );
- dir && currentListItem.setAttribute( 'dir', dir );
// There might be a case where there are no attributes in the element after all
// (i.e. when "type" or "value" are the only attributes set). In this case, if enterMode = BR,
@@ -131,6 +163,12 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
currentListItem = new CKEDITOR.dom.documentFragment( doc );
}
+ if ( currentListItem.type == CKEDITOR.NODE_ELEMENT )
+ {
+ if ( item.grandparent.getDirection( 1 ) != orgDir )
+ currentListItem.setAttribute( 'dir', orgDir );
+ }
+
for ( i = 0 ; i < item.contents.length ; i++ )
currentListItem.append( item.contents[i].clone( 1, 1 ) );
@@ -180,14 +218,23 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
break;
}
- // Clear marker attributes for the new list tree made of cloned nodes, if any.
if ( database )
{
- var currentNode = retval.getFirst();
+ var currentNode = retval.getFirst(),
+ listRoot = listArray[ 0 ].parent;
+
while ( currentNode )
{
if ( currentNode.type == CKEDITOR.NODE_ELEMENT )
+ {
+ // Clear marker attributes for the new list tree made of cloned nodes, if any.
CKEDITOR.dom.element.clearMarkers( database, currentNode );
+
+ // Clear redundant direction attribute specified on list items.
+ if ( currentNode.getName() in CKEDITOR.dtd.$listItem )
+ cleanUpDirection( currentNode );
+ }
+
currentNode = currentNode.getNextSourceNode();
}
}
@@ -196,30 +243,26 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
}
};
- function setState( editor, state )
- {
- editor.getCommand( this.name ).setState( state );
- }
-
function onSelectionChange( evt )
{
+ if ( evt.editor.readOnly )
+ return null;
+
var path = evt.data.path,
blockLimit = path.blockLimit,
elements = path.elements,
- element;
+ element,
+ i;
// Grouping should only happen under blockLimit.(#3940).
- for ( var i = 0 ; i < elements.length && ( element = elements[ i ] )
+ for ( i = 0 ; i < elements.length && ( element = elements[ i ] )
&& !element.equals( blockLimit ); i++ )
{
- if ( listNodeNames[ elements[i].getName() ] )
- {
- return setState.call( this, evt.editor,
- this.type == elements[i].getName() ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF );
- }
+ if ( listNodeNames[ elements[ i ].getName() ] )
+ return this.setState( this.type == elements[ i ].getName() ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF );
}
- return setState.call( this, evt.editor, CKEDITOR.TRISTATE_OFF );
+ return this.setState( CKEDITOR.TRISTATE_OFF );
}
function changeListType( editor, groupObj, database, listsCreated )
@@ -347,14 +390,13 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
contentBlock.appendTo( listItem );
else
{
- // Remove DIR attribute if it was merged into list root.
+ contentBlock.copyAttributes( listItem );
+ // Remove direction attribute after it was merged into list root. (#7657)
if ( listDir && contentBlock.getDirection() )
{
- contentBlock.removeStyle( 'direction' );
- contentBlock.removeAttribute( 'dir' );
+ listItem.removeStyle( 'direction' );
+ listItem.removeAttribute( 'dir' );
}
-
- contentBlock.copyAttributes( listItem );
contentBlock.moveChildren( listItem );
contentBlock.remove();
}
@@ -441,12 +483,27 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
this.type = type;
}
+ // Move direction attribute from root to list items.
+ function dirToListItems( list )
+ {
+ var dir = list.getDirection();
+ if ( dir )
+ {
+ for ( var i = 0, children = list.getChildren(), child; child = children.getItem( i ), i < children.count(); i++ )
+ {
+ if ( child.type == CKEDITOR.NODE_ELEMENT && child.is( 'li' ) && !child.getDirection() )
+ child.setAttribute( 'dir', dir );
+ }
+
+ list.removeAttribute( 'dir' );
+ }
+ }
+
listCommand.prototype = {
exec : function( editor )
{
- editor.focus();
-
var doc = editor.document,
+ config = editor.config,
selection = editor.getSelection(),
ranges = selection && selection.getRanges( true );
@@ -460,21 +517,12 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
if ( this.state == CKEDITOR.TRISTATE_OFF )
{
var body = doc.getBody();
- body.trim();
- if ( !body.getFirst() )
+ if ( !body.getFirst( nonEmpty ) )
{
- var paragraph = doc.createElement( editor.config.enterMode == CKEDITOR.ENTER_P ? 'p' :
- ( editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'br' ) );
- paragraph.appendTo( body );
- ranges = new CKEDITOR.dom.rangeList( [ new CKEDITOR.dom.range( doc ) ] );
- // IE exception on inserting anything when anchor inside
.
- if ( paragraph.is( 'br' ) )
- {
- ranges[ 0 ].setStartBefore( paragraph );
- ranges[ 0 ].setEndAfter( paragraph );
- }
- else
- ranges[ 0 ].selectNodeContents( paragraph );
+ config.enterMode == CKEDITOR.ENTER_BR ?
+ body.appendBogus() :
+ ranges[ 0 ].fixBlock( 1, config.enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' );
+
selection.selectRanges( ranges );
}
// Maybe a single range there enclosing the whole list,
@@ -485,7 +533,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
enclosedNode = range && range.getEnclosedNode();
if ( enclosedNode && enclosedNode.is
&& this.type == enclosedNode.getName() )
- setState.call( this, editor, CKEDITOR.TRISTATE_ON );
+ this.setState( CKEDITOR.TRISTATE_ON );
}
}
@@ -604,6 +652,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
if ( sibling && sibling.getName &&
sibling.getName() == listCommand.type )
{
+
+ // In case to be merged lists have difference directions. (#7448)
+ if ( sibling.getDirection( 1 ) != listNode.getDirection( 1 ) )
+ dirToListItems( listNode.getDirection() ? listNode : sibling );
+
sibling.remove();
// Move children order by merge direction.(#3820)
sibling.moveChildren( listNode, rtl );
@@ -686,10 +739,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
init : function( editor )
{
// Register commands.
- var numberedListCommand = new listCommand( 'numberedlist', 'ol' ),
- bulletedListCommand = new listCommand( 'bulletedlist', 'ul' );
- editor.addCommand( 'numberedlist', numberedListCommand );
- editor.addCommand( 'bulletedlist', bulletedListCommand );
+ var numberedListCommand = editor.addCommand( 'numberedlist', new listCommand( 'numberedlist', 'ol' ) ),
+ bulletedListCommand = editor.addCommand( 'bulletedlist', new listCommand( 'bulletedlist', 'ul' ) );
// Register the toolbar button.
editor.ui.addButton( 'NumberedList',