/*\r
-Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
For licensing, see LICENSE.html or http://ckeditor.com/license\r
*/\r
\r
var listNodeNames = { ol : 1, ul : 1 },\r
emptyTextRegex = /^[\n\r\t ]*$/;\r
\r
+ var whitespaces = CKEDITOR.dom.walker.whitespaces(),\r
+ bookmarks = CKEDITOR.dom.walker.bookmark(),\r
+ nonEmpty = function( node ){ return !( whitespaces( node ) || bookmarks( node ) ); };\r
+\r
CKEDITOR.plugins.list = {\r
/*\r
* Convert a DOM list tree into a data structure that is easier to\r
if ( !rootNode || listArray[ currentIndex ].parent.getName() != rootNode.getName() )\r
{\r
rootNode = listArray[ currentIndex ].parent.clone( false, 1 );\r
+ dir && rootNode.setAttribute( 'dir', dir );\r
retval.append( rootNode );\r
}\r
currentListItem = rootNode.append( item.element.clone( 0, 1 ) );\r
else if ( item.indent == Math.max( indentLevel, 0 ) + 1 )\r
{\r
var listData = CKEDITOR.plugins.list.arrayToList( listArray, null, currentIndex, paragraphMode );\r
+\r
+ // If the next block is an <li> with another list tree as the first\r
+ // child, we'll need to append a filler (<br>/NBSP) or the list item\r
+ // wouldn't be editable. (#6724)\r
+ if ( !currentListItem.getChildCount() && CKEDITOR.env.ie && !( doc.$.documentMode > 7 ))\r
+ currentListItem.append( doc.createText( '\xa0' ) );\r
currentListItem.append( listData.listNode );\r
currentIndex = listData.nextIndex;\r
}\r
else\r
{\r
// Create completely new blocks here.\r
- if ( dir || item.element.hasAttributes() ||\r
- ( paragraphMode != CKEDITOR.ENTER_BR && item.grandparent.getName() != 'td' ) )\r
+ if ( dir || item.element.hasAttributes() || paragraphMode != CKEDITOR.ENTER_BR )\r
{\r
currentListItem = doc.createElement( paragraphName );\r
item.element.copyAttributes( currentListItem, { type:1, value:1 } );\r
- dir && currentListItem.setAttribute( 'dir', dir );\r
+ var itemDir = item.element.getDirection() || dir;\r
+ itemDir &&\r
+ currentListItem.setAttribute( 'dir', itemDir );\r
\r
// There might be a case where there are no attributes in the element after all\r
// (i.e. when "type" or "value" are the only attributes set). In this case, if enterMode = BR,\r
if ( currentListItem.type == CKEDITOR.NODE_DOCUMENT_FRAGMENT\r
&& currentIndex != listArray.length - 1 )\r
{\r
- if ( currentListItem.getLast()\r
- && currentListItem.getLast().type == CKEDITOR.NODE_ELEMENT\r
- && currentListItem.getLast().getAttribute( 'type' ) == '_moz' )\r
- currentListItem.getLast().remove();\r
- currentListItem.appendBogus();\r
+ var last = currentListItem.getLast();\r
+ if ( last && last.type == CKEDITOR.NODE_ELEMENT\r
+ && last.getAttribute( 'type' ) == '_moz' )\r
+ {\r
+ last.remove();\r
+ }\r
+\r
+ if ( !( last = currentListItem.getLast( nonEmpty )\r
+ && last.type == CKEDITOR.NODE_ELEMENT\r
+ && last.getName() in CKEDITOR.dtd.$block ) )\r
+ {\r
+ currentListItem.append( doc.createElement( 'br' ) );\r
+ }\r
}\r
\r
if ( currentListItem.type == CKEDITOR.NODE_ELEMENT &&\r
}\r
};\r
\r
- function setState( editor, state )\r
- {\r
- editor.getCommand( this.name ).setState( state );\r
- }\r
-\r
function onSelectionChange( evt )\r
{\r
var path = evt.data.path,\r
blockLimit = path.blockLimit,\r
elements = path.elements,\r
- element;\r
+ element,\r
+ i;\r
\r
// Grouping should only happen under blockLimit.(#3940).\r
- for ( var i = 0 ; i < elements.length && ( element = elements[ i ] )\r
+ for ( i = 0 ; i < elements.length && ( element = elements[ i ] )\r
&& !element.equals( blockLimit ); i++ )\r
{\r
if ( listNodeNames[ elements[i].getName() ] )\r
- {\r
- return setState.call( this, evt.editor,\r
- this.type == elements[i].getName() ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF );\r
- }\r
+ return this.setState( this.type == elements[i].getName() ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF );\r
}\r
\r
- return setState.call( this, evt.editor, CKEDITOR.TRISTATE_OFF );\r
+ return this.setState( CKEDITOR.TRISTATE_OFF );\r
}\r
\r
function changeListType( editor, groupObj, database, listsCreated )\r
enclosedNode = range && range.getEnclosedNode();\r
if ( enclosedNode && enclosedNode.is\r
&& this.type == enclosedNode.getName() )\r
- setState.call( this, editor, CKEDITOR.TRISTATE_ON );\r
+ this.setState( CKEDITOR.TRISTATE_ON );\r
}\r
}\r
\r
init : function( editor )\r
{\r
// Register commands.\r
- var numberedListCommand = new listCommand( 'numberedlist', 'ol' ),\r
- bulletedListCommand = new listCommand( 'bulletedlist', 'ul' );\r
- editor.addCommand( 'numberedlist', numberedListCommand );\r
- editor.addCommand( 'bulletedlist', bulletedListCommand );\r
+ var numberedListCommand = editor.addCommand( 'numberedlist', new listCommand( 'numberedlist', 'ol' ) ),\r
+ bulletedListCommand = editor.addCommand( 'bulletedlist', new listCommand( 'bulletedlist', 'ul' ) );\r
\r
// Register the toolbar button.\r
editor.ui.addButton( 'NumberedList',\r