2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
7 * @file Insert and remove numbered and bulleted lists.
12 var listNodeNames = { ol : 1, ul : 1 },
13 emptyTextRegex = /^[\n\r\t ]*$/;
15 var whitespaces = CKEDITOR.dom.walker.whitespaces(),
16 bookmarks = CKEDITOR.dom.walker.bookmark(),
17 nonEmpty = function( node ){ return !( whitespaces( node ) || bookmarks( node ) ); };
19 function cleanUpDirection( element )
21 var dir, parent, parentDir;
22 if ( ( dir = element.getDirection() ) )
24 parent = element.getParent();
25 while ( parent && !( parentDir = parent.getDirection() ) )
26 parent = parent.getParent();
28 if ( dir == parentDir )
29 element.removeAttribute( 'dir' );
33 CKEDITOR.plugins.list = {
35 * Convert a DOM list tree into a data structure that is easier to
36 * manipulate. This operation should be non-intrusive in the sense that it
37 * does not change the DOM tree, with the exception that it may add some
38 * markers to the list item nodes when database is specified.
40 listToArray : function( listNode, database, baseArray, baseIndentLevel, grandparentNode )
42 if ( !listNodeNames[ listNode.getName() ] )
45 if ( !baseIndentLevel )
50 // Iterate over all list items to and look for inner lists.
51 for ( var i = 0, count = listNode.getChildCount() ; i < count ; i++ )
53 var listItem = listNode.getChild( i );
55 // Fixing malformed nested lists by moving it into a previous list item. (#6236)
56 if( listItem.type == CKEDITOR.NODE_ELEMENT && listItem.getName() in CKEDITOR.dtd.$list )
57 CKEDITOR.plugins.list.listToArray( listItem, database, baseArray, baseIndentLevel + 1 );
59 // It may be a text node or some funny stuff.
60 if ( listItem.$.nodeName.toLowerCase() != 'li' )
63 var itemObj = { 'parent' : listNode, indent : baseIndentLevel, element : listItem, contents : [] };
64 if ( !grandparentNode )
66 itemObj.grandparent = listNode.getParent();
67 if ( itemObj.grandparent && itemObj.grandparent.$.nodeName.toLowerCase() == 'li' )
68 itemObj.grandparent = itemObj.grandparent.getParent();
71 itemObj.grandparent = grandparentNode;
74 CKEDITOR.dom.element.setMarker( database, listItem, 'listarray_index', baseArray.length );
75 baseArray.push( itemObj );
77 for ( var j = 0, itemChildCount = listItem.getChildCount(), child; j < itemChildCount ; j++ )
79 child = listItem.getChild( j );
80 if ( child.type == CKEDITOR.NODE_ELEMENT && listNodeNames[ child.getName() ] )
81 // Note the recursion here, it pushes inner list items with
82 // +1 indentation in the correct order.
83 CKEDITOR.plugins.list.listToArray( child, database, baseArray, baseIndentLevel + 1, itemObj.grandparent );
85 itemObj.contents.push( child );
91 // Convert our internal representation of a list back to a DOM forest.
92 arrayToList : function( listArray, database, baseIndex, paragraphMode, dir )
96 if ( !listArray || listArray.length < baseIndex + 1 )
98 var doc = listArray[ baseIndex ].parent.getDocument(),
99 retval = new CKEDITOR.dom.documentFragment( doc ),
101 currentIndex = baseIndex,
102 indentLevel = Math.max( listArray[ baseIndex ].indent, 0 ),
103 currentListItem = null,
105 paragraphName = ( paragraphMode == CKEDITOR.ENTER_P ? 'p' : 'div' );
108 var item = listArray[ currentIndex ];
110 orgDir = item.element.getDirection( 1 );
112 if ( item.indent == indentLevel )
114 if ( !rootNode || listArray[ currentIndex ].parent.getName() != rootNode.getName() )
116 rootNode = listArray[ currentIndex ].parent.clone( false, 1 );
117 dir && rootNode.setAttribute( 'dir', dir );
118 retval.append( rootNode );
120 currentListItem = rootNode.append( item.element.clone( 0, 1 ) );
122 if ( orgDir != rootNode.getDirection( 1 ) )
123 currentListItem.setAttribute( 'dir', orgDir );
125 for ( var i = 0 ; i < item.contents.length ; i++ )
126 currentListItem.append( item.contents[i].clone( 1, 1 ) );
129 else if ( item.indent == Math.max( indentLevel, 0 ) + 1 )
131 // Maintain original direction (#6861).
132 var currDir = listArray[ currentIndex - 1 ].element.getDirection( 1 ),
133 listData = CKEDITOR.plugins.list.arrayToList( listArray, null, currentIndex, paragraphMode,
134 currDir != orgDir ? orgDir: null );
136 // If the next block is an <li> with another list tree as the first
137 // child, we'll need to append a filler (<br>/NBSP) or the list item
138 // wouldn't be editable. (#6724)
139 if ( !currentListItem.getChildCount() && CKEDITOR.env.ie && !( doc.$.documentMode > 7 ))
140 currentListItem.append( doc.createText( '\xa0' ) );
141 currentListItem.append( listData.listNode );
142 currentIndex = listData.nextIndex;
144 else if ( item.indent == -1 && !baseIndex && item.grandparent )
146 if ( listNodeNames[ item.grandparent.getName() ] )
147 currentListItem = item.element.clone( false, true );
150 // Create completely new blocks here.
151 if ( dir || item.element.hasAttributes() || paragraphMode != CKEDITOR.ENTER_BR )
153 currentListItem = doc.createElement( paragraphName );
154 item.element.copyAttributes( currentListItem, { type:1, value:1 } );
156 // There might be a case where there are no attributes in the element after all
157 // (i.e. when "type" or "value" are the only attributes set). In this case, if enterMode = BR,
158 // the current item should be a fragment.
159 if ( !dir && paragraphMode == CKEDITOR.ENTER_BR && !currentListItem.hasAttributes() )
160 currentListItem = new CKEDITOR.dom.documentFragment( doc );
163 currentListItem = new CKEDITOR.dom.documentFragment( doc );
166 if ( currentListItem.type == CKEDITOR.NODE_ELEMENT )
168 if ( item.grandparent.getDirection( 1 ) != orgDir )
169 currentListItem.setAttribute( 'dir', orgDir );
172 for ( i = 0 ; i < item.contents.length ; i++ )
173 currentListItem.append( item.contents[i].clone( 1, 1 ) );
175 if ( currentListItem.type == CKEDITOR.NODE_DOCUMENT_FRAGMENT
176 && currentIndex != listArray.length - 1 )
178 var last = currentListItem.getLast();
179 if ( last && last.type == CKEDITOR.NODE_ELEMENT
180 && last.getAttribute( 'type' ) == '_moz' )
185 if ( !( last = currentListItem.getLast( nonEmpty )
186 && last.type == CKEDITOR.NODE_ELEMENT
187 && last.getName() in CKEDITOR.dtd.$block ) )
189 currentListItem.append( doc.createElement( 'br' ) );
193 if ( currentListItem.type == CKEDITOR.NODE_ELEMENT &&
194 currentListItem.getName() == paragraphName &&
195 currentListItem.$.firstChild )
197 currentListItem.trim();
198 var firstChild = currentListItem.getFirst();
199 if ( firstChild.type == CKEDITOR.NODE_ELEMENT && firstChild.isBlockBoundary() )
201 var tmp = new CKEDITOR.dom.documentFragment( doc );
202 currentListItem.moveChildren( tmp );
203 currentListItem = tmp;
207 var currentListItemName = currentListItem.$.nodeName.toLowerCase();
208 if ( !CKEDITOR.env.ie && ( currentListItemName == 'div' || currentListItemName == 'p' ) )
209 currentListItem.appendBogus();
210 retval.append( currentListItem );
217 if ( listArray.length <= currentIndex || Math.max( listArray[ currentIndex ].indent, 0 ) < indentLevel )
223 var currentNode = retval.getFirst(),
224 listRoot = listArray[ 0 ].parent;
226 while ( currentNode )
228 if ( currentNode.type == CKEDITOR.NODE_ELEMENT )
230 // Clear marker attributes for the new list tree made of cloned nodes, if any.
231 CKEDITOR.dom.element.clearMarkers( database, currentNode );
233 // Clear redundant direction attribute specified on list items.
234 if ( currentNode.getName() in CKEDITOR.dtd.$listItem )
235 cleanUpDirection( currentNode );
238 currentNode = currentNode.getNextSourceNode();
242 return { listNode : retval, nextIndex : currentIndex };
246 function onSelectionChange( evt )
248 if ( evt.editor.readOnly )
251 var path = evt.data.path,
252 blockLimit = path.blockLimit,
253 elements = path.elements,
257 // Grouping should only happen under blockLimit.(#3940).
258 for ( i = 0 ; i < elements.length && ( element = elements[ i ] )
259 && !element.equals( blockLimit ); i++ )
261 if ( listNodeNames[ elements[ i ].getName() ] )
262 return this.setState( this.type == elements[ i ].getName() ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF );
265 return this.setState( CKEDITOR.TRISTATE_OFF );
268 function changeListType( editor, groupObj, database, listsCreated )
270 // This case is easy...
271 // 1. Convert the whole list into a one-dimensional array.
272 // 2. Change the list type by modifying the array.
273 // 3. Recreate the whole list by converting the array to a list.
274 // 4. Replace the original list with the recreated list.
275 var listArray = CKEDITOR.plugins.list.listToArray( groupObj.root, database ),
276 selectedListItems = [];
278 for ( var i = 0 ; i < groupObj.contents.length ; i++ )
280 var itemNode = groupObj.contents[i];
281 itemNode = itemNode.getAscendant( 'li', true );
282 if ( !itemNode || itemNode.getCustomData( 'list_item_processed' ) )
284 selectedListItems.push( itemNode );
285 CKEDITOR.dom.element.setMarker( database, itemNode, 'list_item_processed', true );
288 var root = groupObj.root,
289 fakeParent = root.getDocument().createElement( this.type );
290 // Copy all attributes, except from 'start' and 'type'.
291 root.copyAttributes( fakeParent, { start : 1, type : 1 } );
292 // The list-style-type property should be ignored.
293 fakeParent.removeStyle( 'list-style-type' );
295 for ( i = 0 ; i < selectedListItems.length ; i++ )
297 var listIndex = selectedListItems[i].getCustomData( 'listarray_index' );
298 listArray[listIndex].parent = fakeParent;
300 var newList = CKEDITOR.plugins.list.arrayToList( listArray, database, null, editor.config.enterMode );
301 var child, length = newList.listNode.getChildCount();
302 for ( i = 0 ; i < length && ( child = newList.listNode.getChild( i ) ) ; i++ )
304 if ( child.getName() == this.type )
305 listsCreated.push( child );
307 newList.listNode.replace( groupObj.root );
310 var headerTagRegex = /^h[1-6]$/;
312 function createList( editor, groupObj, listsCreated )
314 var contents = groupObj.contents,
315 doc = groupObj.root.getDocument(),
318 // It is possible to have the contents returned by DomRangeIterator to be the same as the root.
319 // e.g. when we're running into table cells.
320 // In such a case, enclose the childNodes of contents[0] into a <div>.
321 if ( contents.length == 1 && contents[0].equals( groupObj.root ) )
323 var divBlock = doc.createElement( 'div' );
324 contents[0].moveChildren && contents[0].moveChildren( divBlock );
325 contents[0].append( divBlock );
326 contents[0] = divBlock;
329 // Calculate the common parent node of all content blocks.
330 var commonParent = groupObj.contents[0].getParent();
331 for ( var i = 0 ; i < contents.length ; i++ )
332 commonParent = commonParent.getCommonAncestor( contents[i].getParent() );
334 var useComputedState = editor.config.useComputedState,
335 listDir, explicitDirection;
337 useComputedState = useComputedState === undefined || useComputedState;
339 // We want to insert things that are in the same tree level only, so calculate the contents again
340 // by expanding the selected blocks to the same tree level.
341 for ( i = 0 ; i < contents.length ; i++ )
343 var contentNode = contents[i],
345 while ( ( parentNode = contentNode.getParent() ) )
347 if ( parentNode.equals( commonParent ) )
349 listContents.push( contentNode );
351 // Determine the lists's direction.
352 if ( !explicitDirection && contentNode.getDirection() )
353 explicitDirection = 1;
355 var itemDir = contentNode.getDirection( useComputedState );
357 if ( listDir !== null )
359 // If at least one LI have a different direction than current listDir, we can't have listDir.
360 if ( listDir && listDir != itemDir )
368 contentNode = parentNode;
372 if ( listContents.length < 1 )
375 // Insert the list to the DOM tree.
376 var insertAnchor = listContents[ listContents.length - 1 ].getNext(),
377 listNode = doc.createElement( this.type );
379 listsCreated.push( listNode );
381 var contentBlock, listItem;
383 while ( listContents.length )
385 contentBlock = listContents.shift();
386 listItem = doc.createElement( 'li' );
388 // Preserve preformat block and heading structure when converting to list item. (#5335) (#5271)
389 if ( contentBlock.is( 'pre' ) || headerTagRegex.test( contentBlock.getName() ) )
390 contentBlock.appendTo( listItem );
393 contentBlock.copyAttributes( listItem );
394 // Remove direction attribute after it was merged into list root. (#7657)
395 if ( listDir && contentBlock.getDirection() )
397 listItem.removeStyle( 'direction' );
398 listItem.removeAttribute( 'dir' );
400 contentBlock.moveChildren( listItem );
401 contentBlock.remove();
404 listItem.appendTo( listNode );
407 // Apply list root dir only if it has been explicitly declared.
408 if ( listDir && explicitDirection )
409 listNode.setAttribute( 'dir', listDir );
412 listNode.insertBefore( insertAnchor );
414 listNode.appendTo( commonParent );
417 function removeList( editor, groupObj, database )
419 // This is very much like the change list type operation.
420 // Except that we're changing the selected items' indent to -1 in the list array.
421 var listArray = CKEDITOR.plugins.list.listToArray( groupObj.root, database ),
422 selectedListItems = [];
424 for ( var i = 0 ; i < groupObj.contents.length ; i++ )
426 var itemNode = groupObj.contents[i];
427 itemNode = itemNode.getAscendant( 'li', true );
428 if ( !itemNode || itemNode.getCustomData( 'list_item_processed' ) )
430 selectedListItems.push( itemNode );
431 CKEDITOR.dom.element.setMarker( database, itemNode, 'list_item_processed', true );
434 var lastListIndex = null;
435 for ( i = 0 ; i < selectedListItems.length ; i++ )
437 var listIndex = selectedListItems[i].getCustomData( 'listarray_index' );
438 listArray[listIndex].indent = -1;
439 lastListIndex = listIndex;
442 // After cutting parts of the list out with indent=-1, we still have to maintain the array list
443 // model's nextItem.indent <= currentItem.indent + 1 invariant. Otherwise the array model of the
444 // list cannot be converted back to a real DOM list.
445 for ( i = lastListIndex + 1 ; i < listArray.length ; i++ )
447 if ( listArray[i].indent > listArray[i-1].indent + 1 )
449 var indentOffset = listArray[i-1].indent + 1 - listArray[i].indent;
450 var oldIndent = listArray[i].indent;
451 while ( listArray[i] && listArray[i].indent >= oldIndent )
453 listArray[i].indent += indentOffset;
460 var newList = CKEDITOR.plugins.list.arrayToList( listArray, database, null, editor.config.enterMode,
461 groupObj.root.getAttribute( 'dir' ) );
463 // Compensate <br> before/after the list node if the surrounds are non-blocks.(#3836)
464 var docFragment = newList.listNode, boundaryNode, siblingNode;
465 function compensateBrs( isStart )
467 if ( ( boundaryNode = docFragment[ isStart ? 'getFirst' : 'getLast' ]() )
468 && !( boundaryNode.is && boundaryNode.isBlockBoundary() )
469 && ( siblingNode = groupObj.root[ isStart ? 'getPrevious' : 'getNext' ]
470 ( CKEDITOR.dom.walker.whitespaces( true ) ) )
471 && !( siblingNode.is && siblingNode.isBlockBoundary( { br : 1 } ) ) )
472 editor.document.createElement( 'br' )[ isStart ? 'insertBefore' : 'insertAfter' ]( boundaryNode );
474 compensateBrs( true );
477 docFragment.replace( groupObj.root );
480 function listCommand( name, type )
486 // Move direction attribute from root to list items.
487 function dirToListItems( list )
489 var dir = list.getDirection();
492 for ( var i = 0, children = list.getChildren(), child; child = children.getItem( i ), i < children.count(); i++ )
494 if ( child.type == CKEDITOR.NODE_ELEMENT && child.is( 'li' ) && !child.getDirection() )
495 child.setAttribute( 'dir', dir );
498 list.removeAttribute( 'dir' );
502 listCommand.prototype = {
503 exec : function( editor )
505 var doc = editor.document,
506 config = editor.config,
507 selection = editor.getSelection(),
508 ranges = selection && selection.getRanges( true );
510 // There should be at least one selected range.
511 if ( !ranges || ranges.length < 1 )
514 // Midas lists rule #1 says we can create a list even in an empty document.
515 // But DOM iterator wouldn't run if the document is really empty.
516 // So create a paragraph if the document is empty and we're going to create a list.
517 if ( this.state == CKEDITOR.TRISTATE_OFF )
519 var body = doc.getBody();
520 if ( !body.getFirst( nonEmpty ) )
522 config.enterMode == CKEDITOR.ENTER_BR ?
524 ranges[ 0 ].fixBlock( 1, config.enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' );
526 selection.selectRanges( ranges );
528 // Maybe a single range there enclosing the whole list,
529 // turn on the list state manually(#4129).
532 var range = ranges.length == 1 && ranges[ 0 ],
533 enclosedNode = range && range.getEnclosedNode();
534 if ( enclosedNode && enclosedNode.is
535 && this.type == enclosedNode.getName() )
536 this.setState( CKEDITOR.TRISTATE_ON );
540 var bookmarks = selection.createBookmarks( true );
542 // Group the blocks up because there are many cases where multiple lists have to be created,
543 // or multiple lists have to be cancelled.
546 rangeIterator = ranges.createIterator(),
549 while ( ( range = rangeIterator.getNextRange() ) && ++index )
551 var boundaryNodes = range.getBoundaryNodes(),
552 startNode = boundaryNodes.startNode,
553 endNode = boundaryNodes.endNode;
555 if ( startNode.type == CKEDITOR.NODE_ELEMENT && startNode.getName() == 'td' )
556 range.setStartAt( boundaryNodes.startNode, CKEDITOR.POSITION_AFTER_START );
558 if ( endNode.type == CKEDITOR.NODE_ELEMENT && endNode.getName() == 'td' )
559 range.setEndAt( boundaryNodes.endNode, CKEDITOR.POSITION_BEFORE_END );
561 var iterator = range.createIterator(),
564 iterator.forceBrBreak = ( this.state == CKEDITOR.TRISTATE_OFF );
566 while ( ( block = iterator.getNextParagraph() ) )
568 // Avoid duplicate blocks get processed across ranges.
569 if( block.getCustomData( 'list_block' ) )
572 CKEDITOR.dom.element.setMarker( database, block, 'list_block', 1 );
574 var path = new CKEDITOR.dom.elementPath( block ),
575 pathElements = path.elements,
576 pathElementsCount = pathElements.length,
579 blockLimit = path.blockLimit,
582 // First, try to group by a list ancestor.
583 for ( var i = pathElementsCount - 1; i >= 0 && ( element = pathElements[ i ] ); i-- )
585 if ( listNodeNames[ element.getName() ]
586 && blockLimit.contains( element ) ) // Don't leak outside block limit (#3940).
588 // If we've encountered a list inside a block limit
589 // The last group object of the block limit element should
590 // no longer be valid. Since paragraphs after the list
591 // should belong to a different group of paragraphs before
592 // the list. (Bug #1309)
593 blockLimit.removeCustomData( 'list_group_object_' + index );
595 var groupObj = element.getCustomData( 'list_group_object' );
597 groupObj.contents.push( block );
600 groupObj = { root : element, contents : [ block ] };
601 listGroups.push( groupObj );
602 CKEDITOR.dom.element.setMarker( database, element, 'list_group_object', groupObj );
612 // No list ancestor? Group by block limit, but don't mix contents from different ranges.
613 var root = blockLimit;
614 if ( root.getCustomData( 'list_group_object_' + index ) )
615 root.getCustomData( 'list_group_object_' + index ).contents.push( block );
618 groupObj = { root : root, contents : [ block ] };
619 CKEDITOR.dom.element.setMarker( database, root, 'list_group_object_' + index, groupObj );
620 listGroups.push( groupObj );
625 // Now we have two kinds of list groups, groups rooted at a list, and groups rooted at a block limit element.
626 // We either have to build lists or remove lists, for removing a list does not makes sense when we are looking
627 // at the group that's not rooted at lists. So we have three cases to handle.
628 var listsCreated = [];
629 while ( listGroups.length > 0 )
631 groupObj = listGroups.shift();
632 if ( this.state == CKEDITOR.TRISTATE_OFF )
634 if ( listNodeNames[ groupObj.root.getName() ] )
635 changeListType.call( this, editor, groupObj, database, listsCreated );
637 createList.call( this, editor, groupObj, listsCreated );
639 else if ( this.state == CKEDITOR.TRISTATE_ON && listNodeNames[ groupObj.root.getName() ] )
640 removeList.call( this, editor, groupObj, database );
643 // For all new lists created, merge adjacent, same type lists.
644 for ( i = 0 ; i < listsCreated.length ; i++ )
646 listNode = listsCreated[i];
647 var mergeSibling, listCommand = this;
648 ( mergeSibling = function( rtl ){
650 var sibling = listNode[ rtl ?
651 'getPrevious' : 'getNext' ]( CKEDITOR.dom.walker.whitespaces( true ) );
652 if ( sibling && sibling.getName &&
653 sibling.getName() == listCommand.type )
656 // In case to be merged lists have difference directions. (#7448)
657 if ( sibling.getDirection( 1 ) != listNode.getDirection( 1 ) )
658 dirToListItems( listNode.getDirection() ? listNode : sibling );
661 // Move children order by merge direction.(#3820)
662 sibling.moveChildren( listNode, rtl );
668 // Clean up, restore selection and update toolbar button states.
669 CKEDITOR.dom.element.clearAllMarkers( database );
670 selection.selectBookmarks( bookmarks );
675 var dtd = CKEDITOR.dtd;
676 var tailNbspRegex = /[\t\r\n ]*(?: |\xa0)$/;
678 function indexOfFirstChildElement( element, tagNameList )
681 children = element.children,
682 length = children.length;
684 for ( var i = 0 ; i < length ; i++ )
686 child = children[ i ];
687 if ( child.name && ( child.name in tagNameList ) )
694 function getExtendNestedListFilter( isHtmlFilter )
696 // An element filter function that corrects nested list start in an empty
697 // list item for better displaying/outputting. (#3165)
698 return function( listItem )
700 var children = listItem.children,
701 firstNestedListIndex = indexOfFirstChildElement( listItem, dtd.$list ),
702 firstNestedList = children[ firstNestedListIndex ],
703 nodeBefore = firstNestedList && firstNestedList.previous,
707 && ( nodeBefore.name && nodeBefore.name == 'br'
708 || nodeBefore.value && ( tailNbspmatch = nodeBefore.value.match( tailNbspRegex ) ) ) )
710 var fillerNode = nodeBefore;
712 // Always use 'nbsp' as filler node if we found a nested list appear
713 // in front of a list item.
714 if ( !( tailNbspmatch && tailNbspmatch.index ) && fillerNode == children[ 0 ] )
715 children[ 0 ] = ( isHtmlFilter || CKEDITOR.env.ie ) ?
716 new CKEDITOR.htmlParser.text( '\xa0' ) :
717 new CKEDITOR.htmlParser.element( 'br', {} );
719 // Otherwise the filler is not needed anymore.
720 else if ( fillerNode.name == 'br' )
721 children.splice( firstNestedListIndex - 1, 1 );
723 fillerNode.value = fillerNode.value.replace( tailNbspRegex, '' );
729 var defaultListDataFilterRules = { elements : {} };
730 for ( var i in dtd.$listItem )
731 defaultListDataFilterRules.elements[ i ] = getExtendNestedListFilter();
733 var defaultListHtmlFilterRules = { elements : {} };
734 for ( i in dtd.$listItem )
735 defaultListHtmlFilterRules.elements[ i ] = getExtendNestedListFilter( true );
737 CKEDITOR.plugins.add( 'list',
739 init : function( editor )
741 // Register commands.
742 var numberedListCommand = editor.addCommand( 'numberedlist', new listCommand( 'numberedlist', 'ol' ) ),
743 bulletedListCommand = editor.addCommand( 'bulletedlist', new listCommand( 'bulletedlist', 'ul' ) );
745 // Register the toolbar button.
746 editor.ui.addButton( 'NumberedList',
748 label : editor.lang.numberedlist,
749 command : 'numberedlist'
751 editor.ui.addButton( 'BulletedList',
753 label : editor.lang.bulletedlist,
754 command : 'bulletedlist'
757 // Register the state changing handlers.
758 editor.on( 'selectionChange', CKEDITOR.tools.bind( onSelectionChange, numberedListCommand ) );
759 editor.on( 'selectionChange', CKEDITOR.tools.bind( onSelectionChange, bulletedListCommand ) );
762 afterInit : function ( editor )
764 var dataProcessor = editor.dataProcessor;
767 dataProcessor.dataFilter.addRules( defaultListDataFilterRules );
768 dataProcessor.htmlFilter.addRules( defaultListHtmlFilterRules );
772 requires : [ 'domiterator' ]