2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
7 * @file Insert and remove numbered and bulleted lists.
\r
12 var listNodeNames = { ol : 1, ul : 1 },
\r
13 emptyTextRegex = /^[\n\r\t ]*$/;
\r
15 var whitespaces = CKEDITOR.dom.walker.whitespaces(),
\r
16 bookmarks = CKEDITOR.dom.walker.bookmark(),
\r
17 nonEmpty = function( node ){ return !( whitespaces( node ) || bookmarks( node ) ); };
\r
19 CKEDITOR.plugins.list = {
\r
21 * Convert a DOM list tree into a data structure that is easier to
\r
22 * manipulate. This operation should be non-intrusive in the sense that it
\r
23 * does not change the DOM tree, with the exception that it may add some
\r
24 * markers to the list item nodes when database is specified.
\r
26 listToArray : function( listNode, database, baseArray, baseIndentLevel, grandparentNode )
\r
28 if ( !listNodeNames[ listNode.getName() ] )
\r
31 if ( !baseIndentLevel )
\r
32 baseIndentLevel = 0;
\r
36 // Iterate over all list items to and look for inner lists.
\r
37 for ( var i = 0, count = listNode.getChildCount() ; i < count ; i++ )
\r
39 var listItem = listNode.getChild( i );
\r
41 // It may be a text node or some funny stuff.
\r
42 if ( listItem.$.nodeName.toLowerCase() != 'li' )
\r
45 var itemObj = { 'parent' : listNode, indent : baseIndentLevel, element : listItem, contents : [] };
\r
46 if ( !grandparentNode )
\r
48 itemObj.grandparent = listNode.getParent();
\r
49 if ( itemObj.grandparent && itemObj.grandparent.$.nodeName.toLowerCase() == 'li' )
\r
50 itemObj.grandparent = itemObj.grandparent.getParent();
\r
53 itemObj.grandparent = grandparentNode;
\r
56 CKEDITOR.dom.element.setMarker( database, listItem, 'listarray_index', baseArray.length );
\r
57 baseArray.push( itemObj );
\r
59 for ( var j = 0, itemChildCount = listItem.getChildCount(), child; j < itemChildCount ; j++ )
\r
61 child = listItem.getChild( j );
\r
62 if ( child.type == CKEDITOR.NODE_ELEMENT && listNodeNames[ child.getName() ] )
\r
63 // Note the recursion here, it pushes inner list items with
\r
64 // +1 indentation in the correct order.
\r
65 CKEDITOR.plugins.list.listToArray( child, database, baseArray, baseIndentLevel + 1, itemObj.grandparent );
\r
67 itemObj.contents.push( child );
\r
73 // Convert our internal representation of a list back to a DOM forest.
\r
74 arrayToList : function( listArray, database, baseIndex, paragraphMode, dir )
\r
78 if ( !listArray || listArray.length < baseIndex + 1 )
\r
80 var doc = listArray[ baseIndex ].parent.getDocument(),
\r
81 retval = new CKEDITOR.dom.documentFragment( doc ),
\r
83 currentIndex = baseIndex,
\r
84 indentLevel = Math.max( listArray[ baseIndex ].indent, 0 ),
\r
85 currentListItem = null,
\r
86 paragraphName = ( paragraphMode == CKEDITOR.ENTER_P ? 'p' : 'div' );
\r
89 var item = listArray[ currentIndex ];
\r
90 if ( item.indent == indentLevel )
\r
92 if ( !rootNode || listArray[ currentIndex ].parent.getName() != rootNode.getName() )
\r
94 rootNode = listArray[ currentIndex ].parent.clone( false, 1 );
\r
95 dir && rootNode.setAttribute( 'dir', dir );
\r
96 retval.append( rootNode );
\r
98 currentListItem = rootNode.append( item.element.clone( 0, 1 ) );
\r
99 for ( var i = 0 ; i < item.contents.length ; i++ )
\r
100 currentListItem.append( item.contents[i].clone( 1, 1 ) );
\r
103 else if ( item.indent == Math.max( indentLevel, 0 ) + 1 )
\r
105 var listData = CKEDITOR.plugins.list.arrayToList( listArray, null, currentIndex, paragraphMode );
\r
106 currentListItem.append( listData.listNode );
\r
107 currentIndex = listData.nextIndex;
\r
109 else if ( item.indent == -1 && !baseIndex && item.grandparent )
\r
112 if ( listNodeNames[ item.grandparent.getName() ] )
\r
113 currentListItem = item.element.clone( false, true );
\r
116 // Create completely new blocks here.
\r
117 if ( dir || item.element.hasAttributes() ||
\r
118 ( paragraphMode != CKEDITOR.ENTER_BR && item.grandparent.getName() != 'td' ) )
\r
120 currentListItem = doc.createElement( paragraphName );
\r
121 item.element.copyAttributes( currentListItem, { type:1, value:1 } );
\r
122 dir && currentListItem.setAttribute( 'dir', dir );
\r
124 // There might be a case where there are no attributes in the element after all
\r
125 // (i.e. when "type" or "value" are the only attributes set). In this case, if enterMode = BR,
\r
126 // the current item should be a fragment.
\r
127 if ( !dir && paragraphMode == CKEDITOR.ENTER_BR && !currentListItem.hasAttributes() )
\r
128 currentListItem = new CKEDITOR.dom.documentFragment( doc );
\r
131 currentListItem = new CKEDITOR.dom.documentFragment( doc );
\r
134 for ( i = 0 ; i < item.contents.length ; i++ )
\r
135 currentListItem.append( item.contents[i].clone( 1, 1 ) );
\r
137 if ( currentListItem.type == CKEDITOR.NODE_DOCUMENT_FRAGMENT
\r
138 && currentIndex != listArray.length - 1 )
\r
140 var last = currentListItem.getLast();
\r
141 if ( last && last.type == CKEDITOR.NODE_ELEMENT
\r
142 && last.getAttribute( 'type' ) == '_moz' )
\r
147 if ( !( last = currentListItem.getLast( nonEmpty )
\r
148 && last.type == CKEDITOR.NODE_ELEMENT
\r
149 && last.getName() in CKEDITOR.dtd.$block ) )
\r
151 currentListItem.append( doc.createElement( 'br' ) );
\r
155 if ( currentListItem.type == CKEDITOR.NODE_ELEMENT &&
\r
156 currentListItem.getName() == paragraphName &&
\r
157 currentListItem.$.firstChild )
\r
159 currentListItem.trim();
\r
160 var firstChild = currentListItem.getFirst();
\r
161 if ( firstChild.type == CKEDITOR.NODE_ELEMENT && firstChild.isBlockBoundary() )
\r
163 var tmp = new CKEDITOR.dom.documentFragment( doc );
\r
164 currentListItem.moveChildren( tmp );
\r
165 currentListItem = tmp;
\r
169 var currentListItemName = currentListItem.$.nodeName.toLowerCase();
\r
170 if ( !CKEDITOR.env.ie && ( currentListItemName == 'div' || currentListItemName == 'p' ) )
\r
171 currentListItem.appendBogus();
\r
172 retval.append( currentListItem );
\r
179 if ( listArray.length <= currentIndex || Math.max( listArray[ currentIndex ].indent, 0 ) < indentLevel )
\r
183 // Clear marker attributes for the new list tree made of cloned nodes, if any.
\r
186 var currentNode = retval.getFirst();
\r
187 while ( currentNode )
\r
189 if ( currentNode.type == CKEDITOR.NODE_ELEMENT )
\r
190 CKEDITOR.dom.element.clearMarkers( database, currentNode );
\r
191 currentNode = currentNode.getNextSourceNode();
\r
195 return { listNode : retval, nextIndex : currentIndex };
\r
199 function setState( editor, state )
\r
201 editor.getCommand( this.name ).setState( state );
\r
204 function onSelectionChange( evt )
\r
206 var path = evt.data.path,
\r
207 blockLimit = path.blockLimit,
\r
208 elements = path.elements,
\r
211 // Grouping should only happen under blockLimit.(#3940).
\r
212 for ( var i = 0 ; i < elements.length && ( element = elements[ i ] )
\r
213 && !element.equals( blockLimit ); i++ )
\r
215 if ( listNodeNames[ elements[i].getName() ] )
\r
217 return setState.call( this, evt.editor,
\r
218 this.type == elements[i].getName() ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF );
\r
222 return setState.call( this, evt.editor, CKEDITOR.TRISTATE_OFF );
\r
225 function changeListType( editor, groupObj, database, listsCreated )
\r
227 // This case is easy...
\r
228 // 1. Convert the whole list into a one-dimensional array.
\r
229 // 2. Change the list type by modifying the array.
\r
230 // 3. Recreate the whole list by converting the array to a list.
\r
231 // 4. Replace the original list with the recreated list.
\r
232 var listArray = CKEDITOR.plugins.list.listToArray( groupObj.root, database ),
\r
233 selectedListItems = [];
\r
235 for ( var i = 0 ; i < groupObj.contents.length ; i++ )
\r
237 var itemNode = groupObj.contents[i];
\r
238 itemNode = itemNode.getAscendant( 'li', true );
\r
239 if ( !itemNode || itemNode.getCustomData( 'list_item_processed' ) )
\r
241 selectedListItems.push( itemNode );
\r
242 CKEDITOR.dom.element.setMarker( database, itemNode, 'list_item_processed', true );
\r
245 var root = groupObj.root,
\r
246 fakeParent = root.getDocument().createElement( this.type );
\r
247 // Copy all attributes, except from 'start' and 'type'.
\r
248 root.copyAttributes( fakeParent, { start : 1, type : 1 } );
\r
249 // The list-style-type property should be ignored.
\r
250 fakeParent.removeStyle( 'list-style-type' );
\r
252 for ( i = 0 ; i < selectedListItems.length ; i++ )
\r
254 var listIndex = selectedListItems[i].getCustomData( 'listarray_index' );
\r
255 listArray[listIndex].parent = fakeParent;
\r
257 var newList = CKEDITOR.plugins.list.arrayToList( listArray, database, null, editor.config.enterMode );
\r
258 var child, length = newList.listNode.getChildCount();
\r
259 for ( i = 0 ; i < length && ( child = newList.listNode.getChild( i ) ) ; i++ )
\r
261 if ( child.getName() == this.type )
\r
262 listsCreated.push( child );
\r
264 newList.listNode.replace( groupObj.root );
\r
267 var headerTagRegex = /^h[1-6]$/;
\r
269 function createList( editor, groupObj, listsCreated )
\r
271 var contents = groupObj.contents,
\r
272 doc = groupObj.root.getDocument(),
\r
275 // It is possible to have the contents returned by DomRangeIterator to be the same as the root.
\r
276 // e.g. when we're running into table cells.
\r
277 // In such a case, enclose the childNodes of contents[0] into a <div>.
\r
278 if ( contents.length == 1 && contents[0].equals( groupObj.root ) )
\r
280 var divBlock = doc.createElement( 'div' );
\r
281 contents[0].moveChildren && contents[0].moveChildren( divBlock );
\r
282 contents[0].append( divBlock );
\r
283 contents[0] = divBlock;
\r
286 // Calculate the common parent node of all content blocks.
\r
287 var commonParent = groupObj.contents[0].getParent();
\r
288 for ( var i = 0 ; i < contents.length ; i++ )
\r
289 commonParent = commonParent.getCommonAncestor( contents[i].getParent() );
\r
291 var useComputedState = editor.config.useComputedState,
\r
292 listDir, explicitDirection;
\r
294 useComputedState = useComputedState === undefined || useComputedState;
\r
296 // We want to insert things that are in the same tree level only, so calculate the contents again
\r
297 // by expanding the selected blocks to the same tree level.
\r
298 for ( i = 0 ; i < contents.length ; i++ )
\r
300 var contentNode = contents[i],
\r
302 while ( ( parentNode = contentNode.getParent() ) )
\r
304 if ( parentNode.equals( commonParent ) )
\r
306 listContents.push( contentNode );
\r
308 // Determine the lists's direction.
\r
309 if ( !explicitDirection && contentNode.getDirection() )
\r
310 explicitDirection = 1;
\r
312 var itemDir = contentNode.getDirection( useComputedState );
\r
314 if ( listDir !== null )
\r
316 // If at least one LI have a different direction than current listDir, we can't have listDir.
\r
317 if ( listDir && listDir != itemDir )
\r
325 contentNode = parentNode;
\r
329 if ( listContents.length < 1 )
\r
332 // Insert the list to the DOM tree.
\r
333 var insertAnchor = listContents[ listContents.length - 1 ].getNext(),
\r
334 listNode = doc.createElement( this.type );
\r
336 listsCreated.push( listNode );
\r
338 var contentBlock, listItem;
\r
340 while ( listContents.length )
\r
342 contentBlock = listContents.shift();
\r
343 listItem = doc.createElement( 'li' );
\r
345 // Preserve preformat block and heading structure when converting to list item. (#5335) (#5271)
\r
346 if ( contentBlock.is( 'pre' ) || headerTagRegex.test( contentBlock.getName() ) )
\r
347 contentBlock.appendTo( listItem );
\r
350 // Remove DIR attribute if it was merged into list root.
\r
351 if ( listDir && contentBlock.getDirection() )
\r
353 contentBlock.removeStyle( 'direction' );
\r
354 contentBlock.removeAttribute( 'dir' );
\r
357 contentBlock.copyAttributes( listItem );
\r
358 contentBlock.moveChildren( listItem );
\r
359 contentBlock.remove();
\r
362 listItem.appendTo( listNode );
\r
365 // Apply list root dir only if it has been explicitly declared.
\r
366 if ( listDir && explicitDirection )
\r
367 listNode.setAttribute( 'dir', listDir );
\r
369 if ( insertAnchor )
\r
370 listNode.insertBefore( insertAnchor );
\r
372 listNode.appendTo( commonParent );
\r
375 function removeList( editor, groupObj, database )
\r
377 // This is very much like the change list type operation.
\r
378 // Except that we're changing the selected items' indent to -1 in the list array.
\r
379 var listArray = CKEDITOR.plugins.list.listToArray( groupObj.root, database ),
\r
380 selectedListItems = [];
\r
382 for ( var i = 0 ; i < groupObj.contents.length ; i++ )
\r
384 var itemNode = groupObj.contents[i];
\r
385 itemNode = itemNode.getAscendant( 'li', true );
\r
386 if ( !itemNode || itemNode.getCustomData( 'list_item_processed' ) )
\r
388 selectedListItems.push( itemNode );
\r
389 CKEDITOR.dom.element.setMarker( database, itemNode, 'list_item_processed', true );
\r
392 var lastListIndex = null;
\r
393 for ( i = 0 ; i < selectedListItems.length ; i++ )
\r
395 var listIndex = selectedListItems[i].getCustomData( 'listarray_index' );
\r
396 listArray[listIndex].indent = -1;
\r
397 lastListIndex = listIndex;
\r
400 // After cutting parts of the list out with indent=-1, we still have to maintain the array list
\r
401 // model's nextItem.indent <= currentItem.indent + 1 invariant. Otherwise the array model of the
\r
402 // list cannot be converted back to a real DOM list.
\r
403 for ( i = lastListIndex + 1 ; i < listArray.length ; i++ )
\r
405 if ( listArray[i].indent > listArray[i-1].indent + 1 )
\r
407 var indentOffset = listArray[i-1].indent + 1 - listArray[i].indent;
\r
408 var oldIndent = listArray[i].indent;
\r
409 while ( listArray[i] && listArray[i].indent >= oldIndent )
\r
411 listArray[i].indent += indentOffset;
\r
418 var newList = CKEDITOR.plugins.list.arrayToList( listArray, database, null, editor.config.enterMode,
\r
419 groupObj.root.getAttribute( 'dir' ) );
\r
421 // Compensate <br> before/after the list node if the surrounds are non-blocks.(#3836)
\r
422 var docFragment = newList.listNode, boundaryNode, siblingNode;
\r
423 function compensateBrs( isStart )
\r
425 if ( ( boundaryNode = docFragment[ isStart ? 'getFirst' : 'getLast' ]() )
\r
426 && !( boundaryNode.is && boundaryNode.isBlockBoundary() )
\r
427 && ( siblingNode = groupObj.root[ isStart ? 'getPrevious' : 'getNext' ]
\r
428 ( CKEDITOR.dom.walker.whitespaces( true ) ) )
\r
429 && !( siblingNode.is && siblingNode.isBlockBoundary( { br : 1 } ) ) )
\r
430 editor.document.createElement( 'br' )[ isStart ? 'insertBefore' : 'insertAfter' ]( boundaryNode );
\r
432 compensateBrs( true );
\r
435 docFragment.replace( groupObj.root );
\r
438 function listCommand( name, type )
\r
444 listCommand.prototype = {
\r
445 exec : function( editor )
\r
449 var doc = editor.document,
\r
450 selection = editor.getSelection(),
\r
451 ranges = selection && selection.getRanges( true );
\r
453 // There should be at least one selected range.
\r
454 if ( !ranges || ranges.length < 1 )
\r
457 // Midas lists rule #1 says we can create a list even in an empty document.
\r
458 // But DOM iterator wouldn't run if the document is really empty.
\r
459 // So create a paragraph if the document is empty and we're going to create a list.
\r
460 if ( this.state == CKEDITOR.TRISTATE_OFF )
\r
462 var body = doc.getBody();
\r
464 if ( !body.getFirst() )
\r
466 var paragraph = doc.createElement( editor.config.enterMode == CKEDITOR.ENTER_P ? 'p' :
\r
467 ( editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'br' ) );
\r
468 paragraph.appendTo( body );
\r
469 ranges = new CKEDITOR.dom.rangeList( [ new CKEDITOR.dom.range( doc ) ] );
\r
470 // IE exception on inserting anything when anchor inside <br>.
\r
471 if ( paragraph.is( 'br' ) )
\r
473 ranges[ 0 ].setStartBefore( paragraph );
\r
474 ranges[ 0 ].setEndAfter( paragraph );
\r
477 ranges[ 0 ].selectNodeContents( paragraph );
\r
478 selection.selectRanges( ranges );
\r
480 // Maybe a single range there enclosing the whole list,
\r
481 // turn on the list state manually(#4129).
\r
484 var range = ranges.length == 1 && ranges[ 0 ],
\r
485 enclosedNode = range && range.getEnclosedNode();
\r
486 if ( enclosedNode && enclosedNode.is
\r
487 && this.type == enclosedNode.getName() )
\r
488 setState.call( this, editor, CKEDITOR.TRISTATE_ON );
\r
492 var bookmarks = selection.createBookmarks( true );
\r
494 // Group the blocks up because there are many cases where multiple lists have to be created,
\r
495 // or multiple lists have to be cancelled.
\r
496 var listGroups = [],
\r
498 rangeIterator = ranges.createIterator(),
\r
501 while ( ( range = rangeIterator.getNextRange() ) && ++index )
\r
503 var boundaryNodes = range.getBoundaryNodes(),
\r
504 startNode = boundaryNodes.startNode,
\r
505 endNode = boundaryNodes.endNode;
\r
507 if ( startNode.type == CKEDITOR.NODE_ELEMENT && startNode.getName() == 'td' )
\r
508 range.setStartAt( boundaryNodes.startNode, CKEDITOR.POSITION_AFTER_START );
\r
510 if ( endNode.type == CKEDITOR.NODE_ELEMENT && endNode.getName() == 'td' )
\r
511 range.setEndAt( boundaryNodes.endNode, CKEDITOR.POSITION_BEFORE_END );
\r
513 var iterator = range.createIterator(),
\r
516 iterator.forceBrBreak = ( this.state == CKEDITOR.TRISTATE_OFF );
\r
518 while ( ( block = iterator.getNextParagraph() ) )
\r
520 // Avoid duplicate blocks get processed across ranges.
\r
521 if( block.getCustomData( 'list_block' ) )
\r
524 CKEDITOR.dom.element.setMarker( database, block, 'list_block', 1 );
\r
526 var path = new CKEDITOR.dom.elementPath( block ),
\r
527 pathElements = path.elements,
\r
528 pathElementsCount = pathElements.length,
\r
531 blockLimit = path.blockLimit,
\r
534 // First, try to group by a list ancestor.
\r
535 for ( var i = pathElementsCount - 1; i >= 0 && ( element = pathElements[ i ] ); i-- )
\r
537 if ( listNodeNames[ element.getName() ]
\r
538 && blockLimit.contains( element ) ) // Don't leak outside block limit (#3940).
\r
540 // If we've encountered a list inside a block limit
\r
541 // The last group object of the block limit element should
\r
542 // no longer be valid. Since paragraphs after the list
\r
543 // should belong to a different group of paragraphs before
\r
544 // the list. (Bug #1309)
\r
545 blockLimit.removeCustomData( 'list_group_object_' + index );
\r
547 var groupObj = element.getCustomData( 'list_group_object' );
\r
549 groupObj.contents.push( block );
\r
552 groupObj = { root : element, contents : [ block ] };
\r
553 listGroups.push( groupObj );
\r
554 CKEDITOR.dom.element.setMarker( database, element, 'list_group_object', groupObj );
\r
561 if ( processedFlag )
\r
564 // No list ancestor? Group by block limit, but don't mix contents from different ranges.
\r
565 var root = blockLimit;
\r
566 if ( root.getCustomData( 'list_group_object_' + index ) )
\r
567 root.getCustomData( 'list_group_object_' + index ).contents.push( block );
\r
570 groupObj = { root : root, contents : [ block ] };
\r
571 CKEDITOR.dom.element.setMarker( database, root, 'list_group_object_' + index, groupObj );
\r
572 listGroups.push( groupObj );
\r
577 // Now we have two kinds of list groups, groups rooted at a list, and groups rooted at a block limit element.
\r
578 // We either have to build lists or remove lists, for removing a list does not makes sense when we are looking
\r
579 // at the group that's not rooted at lists. So we have three cases to handle.
\r
580 var listsCreated = [];
\r
581 while ( listGroups.length > 0 )
\r
583 groupObj = listGroups.shift();
\r
584 if ( this.state == CKEDITOR.TRISTATE_OFF )
\r
586 if ( listNodeNames[ groupObj.root.getName() ] )
\r
587 changeListType.call( this, editor, groupObj, database, listsCreated );
\r
589 createList.call( this, editor, groupObj, listsCreated );
\r
591 else if ( this.state == CKEDITOR.TRISTATE_ON && listNodeNames[ groupObj.root.getName() ] )
\r
592 removeList.call( this, editor, groupObj, database );
\r
595 // For all new lists created, merge adjacent, same type lists.
\r
596 for ( i = 0 ; i < listsCreated.length ; i++ )
\r
598 listNode = listsCreated[i];
\r
599 var mergeSibling, listCommand = this;
\r
600 ( mergeSibling = function( rtl ){
\r
602 var sibling = listNode[ rtl ?
\r
603 'getPrevious' : 'getNext' ]( CKEDITOR.dom.walker.whitespaces( true ) );
\r
604 if ( sibling && sibling.getName &&
\r
605 sibling.getName() == listCommand.type )
\r
608 // Move children order by merge direction.(#3820)
\r
609 sibling.moveChildren( listNode, rtl );
\r
615 // Clean up, restore selection and update toolbar button states.
\r
616 CKEDITOR.dom.element.clearAllMarkers( database );
\r
617 selection.selectBookmarks( bookmarks );
\r
622 var dtd = CKEDITOR.dtd;
\r
623 var tailNbspRegex = /[\t\r\n ]*(?: |\xa0)$/;
\r
625 function indexOfFirstChildElement( element, tagNameList )
\r
628 children = element.children,
\r
629 length = children.length;
\r
631 for ( var i = 0 ; i < length ; i++ )
\r
633 child = children[ i ];
\r
634 if ( child.name && ( child.name in tagNameList ) )
\r
641 function getExtendNestedListFilter( isHtmlFilter )
\r
643 // An element filter function that corrects nested list start in an empty
\r
644 // list item for better displaying/outputting. (#3165)
\r
645 return function( listItem )
\r
647 var children = listItem.children,
\r
648 firstNestedListIndex = indexOfFirstChildElement( listItem, dtd.$list ),
\r
649 firstNestedList = children[ firstNestedListIndex ],
\r
650 nodeBefore = firstNestedList && firstNestedList.previous,
\r
654 && ( nodeBefore.name && nodeBefore.name == 'br'
\r
655 || nodeBefore.value && ( tailNbspmatch = nodeBefore.value.match( tailNbspRegex ) ) ) )
\r
657 var fillerNode = nodeBefore;
\r
659 // Always use 'nbsp' as filler node if we found a nested list appear
\r
660 // in front of a list item.
\r
661 if ( !( tailNbspmatch && tailNbspmatch.index ) && fillerNode == children[ 0 ] )
\r
662 children[ 0 ] = ( isHtmlFilter || CKEDITOR.env.ie ) ?
\r
663 new CKEDITOR.htmlParser.text( '\xa0' ) :
\r
664 new CKEDITOR.htmlParser.element( 'br', {} );
\r
666 // Otherwise the filler is not needed anymore.
\r
667 else if ( fillerNode.name == 'br' )
\r
668 children.splice( firstNestedListIndex - 1, 1 );
\r
670 fillerNode.value = fillerNode.value.replace( tailNbspRegex, '' );
\r
676 var defaultListDataFilterRules = { elements : {} };
\r
677 for ( var i in dtd.$listItem )
\r
678 defaultListDataFilterRules.elements[ i ] = getExtendNestedListFilter();
\r
680 var defaultListHtmlFilterRules = { elements : {} };
\r
681 for ( i in dtd.$listItem )
\r
682 defaultListHtmlFilterRules.elements[ i ] = getExtendNestedListFilter( true );
\r
684 CKEDITOR.plugins.add( 'list',
\r
686 init : function( editor )
\r
688 // Register commands.
\r
689 var numberedListCommand = new listCommand( 'numberedlist', 'ol' ),
\r
690 bulletedListCommand = new listCommand( 'bulletedlist', 'ul' );
\r
691 editor.addCommand( 'numberedlist', numberedListCommand );
\r
692 editor.addCommand( 'bulletedlist', bulletedListCommand );
\r
694 // Register the toolbar button.
\r
695 editor.ui.addButton( 'NumberedList',
\r
697 label : editor.lang.numberedlist,
\r
698 command : 'numberedlist'
\r
700 editor.ui.addButton( 'BulletedList',
\r
702 label : editor.lang.bulletedlist,
\r
703 command : 'bulletedlist'
\r
706 // Register the state changing handlers.
\r
707 editor.on( 'selectionChange', CKEDITOR.tools.bind( onSelectionChange, numberedListCommand ) );
\r
708 editor.on( 'selectionChange', CKEDITOR.tools.bind( onSelectionChange, bulletedListCommand ) );
\r
711 afterInit : function ( editor )
\r
713 var dataProcessor = editor.dataProcessor;
\r
714 if ( dataProcessor )
\r
716 dataProcessor.dataFilter.addRules( defaultListDataFilterRules );
\r
717 dataProcessor.htmlFilter.addRules( defaultListHtmlFilterRules );
\r
721 requires : [ 'domiterator' ]
\r