X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Flist%2Fplugin.js;h=be10d0d54361c6609b0330436799b95c34e653f0;hb=4e70ea24db840898be8cc21c950363a52a2a6aba;hp=0cd962f136f270fa780c3631f915121b4af7dfba;hpb=e371ddf8abcb89013e20e6d0dd746adec344d0e5;p=ckeditor.git
diff --git a/_source/plugins/list/plugin.js b/_source/plugins/list/plugin.js
index 0cd962f..be10d0d 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
*/
@@ -12,6 +12,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
var listNodeNames = { ol : 1, ul : 1 },
emptyTextRegex = /^[\n\r\t ]*$/;
+ var whitespaces = CKEDITOR.dom.walker.whitespaces(),
+ bookmarks = CKEDITOR.dom.walker.bookmark(),
+ nonEmpty = function( node ){ return !( whitespaces( node ) || bookmarks( node ) ); };
+
CKEDITOR.plugins.list = {
/*
* Convert a DOM list tree into a data structure that is easier to
@@ -34,6 +38,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;
@@ -79,57 +87,89 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
currentIndex = baseIndex,
indentLevel = Math.max( listArray[ baseIndex ].indent, 0 ),
currentListItem = null,
+ itemDir,
paragraphName = ( paragraphMode == CKEDITOR.ENTER_P ? 'p' : 'div' );
- while ( true )
+ while ( 1 )
{
var item = listArray[ currentIndex ];
if ( item.indent == indentLevel )
{
if ( !rootNode || listArray[ currentIndex ].parent.getName() != rootNode.getName() )
{
- rootNode = listArray[ currentIndex ].parent.clone( false, true );
+ rootNode = listArray[ currentIndex ].parent.clone( false, 1 );
+ dir && rootNode.setAttribute( 'dir', dir );
retval.append( rootNode );
}
- currentListItem = rootNode.append( item.element.clone( false, true ) );
+ currentListItem = rootNode.append( item.element.clone( 0, 1 ) );
for ( var i = 0 ; i < item.contents.length ; i++ )
- currentListItem.append( item.contents[i].clone( true, true ) );
+ 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 orgDir = item.element.getDirection( 1 ),
+ 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 );
+ itemDir = item.element.getDirection( 1 );
+ item.grandparent.getDirection( 1 ) != itemDir &&
+ currentListItem.setAttribute( 'dir', itemDir );
+ }
else
{
- // Create completely new blocks here, attributes are dropped.
- if ( dir || ( paragraphMode != CKEDITOR.ENTER_BR && item.grandparent.getName() != 'td' ) )
+ // Create completely new blocks here.
+ if ( dir || item.element.hasAttributes() || paragraphMode != CKEDITOR.ENTER_BR )
{
currentListItem = doc.createElement( paragraphName );
- if ( dir )
- currentListItem.setAttribute( 'dir', dir );
+ item.element.copyAttributes( currentListItem, { type:1, value:1 } );
+ itemDir = item.element.getDirection() || dir;
+ itemDir &&
+ currentListItem.setAttribute( 'dir', itemDir );
+
+ // 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,
+ // the current item should be a fragment.
+ if ( !dir && paragraphMode == CKEDITOR.ENTER_BR && !currentListItem.hasAttributes() )
+ currentListItem = new CKEDITOR.dom.documentFragment( doc );
}
else
currentListItem = new CKEDITOR.dom.documentFragment( doc );
}
for ( i = 0 ; i < item.contents.length ; i++ )
- currentListItem.append( item.contents[i].clone( true, true ) );
+ currentListItem.append( item.contents[i].clone( 1, 1 ) );
if ( currentListItem.type == CKEDITOR.NODE_DOCUMENT_FRAGMENT
&& currentIndex != listArray.length - 1 )
{
- if ( currentListItem.getLast()
- && currentListItem.getLast().type == CKEDITOR.NODE_ELEMENT
- && currentListItem.getLast().getAttribute( 'type' ) == '_moz' )
- currentListItem.getLast().remove();
- currentListItem.appendBogus();
+ var last = currentListItem.getLast();
+ if ( last && last.type == CKEDITOR.NODE_ELEMENT
+ && last.getAttribute( 'type' ) == '_moz' )
+ {
+ last.remove();
+ }
+
+ if ( !( last = currentListItem.getLast( nonEmpty )
+ && last.type == CKEDITOR.NODE_ELEMENT
+ && last.getName() in CKEDITOR.dtd.$block ) )
+ {
+ currentListItem.append( doc.createElement( 'br' ) );
+ }
}
if ( currentListItem.type == CKEDITOR.NODE_ELEMENT &&
@@ -176,30 +216,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 )
@@ -268,6 +304,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
for ( var i = 0 ; i < contents.length ; i++ )
commonParent = commonParent.getCommonAncestor( contents[i].getParent() );
+ var useComputedState = editor.config.useComputedState,
+ listDir, explicitDirection;
+
+ useComputedState = useComputedState === undefined || useComputedState;
+
// We want to insert things that are in the same tree level only, so calculate the contents again
// by expanding the selected blocks to the same tree level.
for ( i = 0 ; i < contents.length ; i++ )
@@ -279,6 +320,22 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
if ( parentNode.equals( commonParent ) )
{
listContents.push( contentNode );
+
+ // Determine the lists's direction.
+ if ( !explicitDirection && contentNode.getDirection() )
+ explicitDirection = 1;
+
+ var itemDir = contentNode.getDirection( useComputedState );
+
+ if ( listDir !== null )
+ {
+ // If at least one LI have a different direction than current listDir, we can't have listDir.
+ if ( listDir && listDir != itemDir )
+ listDir = null;
+ else
+ listDir = itemDir;
+ }
+
break;
}
contentNode = parentNode;
@@ -290,39 +347,40 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
// Insert the list to the DOM tree.
var insertAnchor = listContents[ listContents.length - 1 ].getNext(),
- listNode = doc.createElement( this.type ),
- dir;
+ listNode = doc.createElement( this.type );
listsCreated.push( listNode );
+
+ var contentBlock, listItem;
+
while ( listContents.length )
{
- var contentBlock = listContents.shift(),
- listItem = doc.createElement( 'li' );
+ contentBlock = listContents.shift();
+ listItem = doc.createElement( 'li' );
- // Preserve heading structure when converting to list item. (#5271)
- if ( headerTagRegex.test( contentBlock.getName() ) )
+ // Preserve preformat block and heading structure when converting to list item. (#5335) (#5271)
+ if ( contentBlock.is( 'pre' ) || headerTagRegex.test( contentBlock.getName() ) )
contentBlock.appendTo( listItem );
else
{
- if ( contentBlock.hasAttribute( 'dir' ) )
+ // Remove DIR attribute if it was merged into list root.
+ if ( listDir && contentBlock.getDirection() )
{
- dir = dir || contentBlock.getAttribute( 'dir' );
+ contentBlock.removeStyle( 'direction' );
contentBlock.removeAttribute( 'dir' );
}
+
contentBlock.copyAttributes( listItem );
contentBlock.moveChildren( listItem );
contentBlock.remove();
}
listItem.appendTo( listNode );
-
- // Append a bogus BR to force the LI to render at full height
- if ( !CKEDITOR.env.ie )
- listItem.appendBogus();
}
- if ( dir )
- listNode.setAttribute( 'dir', dir );
+ // Apply list root dir only if it has been explicitly declared.
+ if ( listDir && explicitDirection )
+ listNode.setAttribute( 'dir', listDir );
if ( insertAnchor )
listNode.insertBefore( insertAnchor );
@@ -402,9 +460,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
listCommand.prototype = {
exec : function( editor )
{
- editor.focus();
-
var doc = editor.document,
+ config = editor.config,
selection = editor.getSelection(),
ranges = selection && selection.getRanges( true );
@@ -418,21 +475,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.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,
@@ -443,9 +491,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 );
}
}
@@ -487,7 +533,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
pathElements = path.elements,
pathElementsCount = pathElements.length,
listNode = null,
- processedFlag = false,
+ processedFlag = 0,
blockLimit = path.blockLimit,
element;
@@ -513,7 +559,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
listGroups.push( groupObj );
CKEDITOR.dom.element.setMarker( database, element, 'list_group_object', groupObj );
}
- processedFlag = true;
+ processedFlag = 1;
break;
}
}
@@ -566,10 +612,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
{
sibling.remove();
// Move children order by merge direction.(#3820)
- sibling.moveChildren( listNode, rtl ? true : false );
+ sibling.moveChildren( listNode, rtl );
}
} )();
- mergeSibling( true );
+ mergeSibling( 1 );
}
// Clean up, restore selection and update toolbar button states.
@@ -646,10 +692,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',