JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.3.2
[ckeditor.git] / _source / plugins / list / plugin.js
index 3898f2a..4c728fa 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
 For licensing, see LICENSE.html or http://ckeditor.com/license\r
 */\r
 \r
@@ -29,7 +29,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        if ( !baseArray )\r
                                baseArray = [];\r
 \r
-                       // Iterate over all list items to get their contents and look for inner lists.\r
+                       // Iterate over all list items to and look for inner lists.\r
                        for ( var i = 0, count = listNode.getChildCount() ; i < count ; i++ )\r
                        {\r
                                var listItem = listNode.getChild( i );\r
@@ -37,7 +37,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                // It may be a text node or some funny stuff.\r
                                if ( listItem.$.nodeName.toLowerCase() != 'li' )\r
                                        continue;\r
-                               var itemObj = { 'parent' : listNode, indent : baseIndentLevel, contents : [] };\r
+\r
+                               var itemObj = { 'parent' : listNode, indent : baseIndentLevel, element : listItem, contents : [] };\r
                                if ( !grandparentNode )\r
                                {\r
                                        itemObj.grandparent = listNode.getParent();\r
@@ -51,9 +52,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        CKEDITOR.dom.element.setMarker( database, listItem, 'listarray_index', baseArray.length );\r
                                baseArray.push( itemObj );\r
 \r
-                               for ( var j = 0, itemChildCount = listItem.getChildCount() ; j < itemChildCount ; j++ )\r
+                               for ( var j = 0, itemChildCount = listItem.getChildCount(), child; j < itemChildCount ; j++ )\r
                                {\r
-                                       var child = listItem.getChild( j );\r
+                                       child = listItem.getChild( j );\r
                                        if ( child.type == CKEDITOR.NODE_ELEMENT && listNodeNames[ child.getName() ] )\r
                                                // Note the recursion here, it pushes inner list items with\r
                                                // +1 indentation in the correct order.\r
@@ -89,7 +90,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                rootNode = listArray[ currentIndex ].parent.clone( false, true );\r
                                                retval.append( rootNode );\r
                                        }\r
-                                       currentListItem = rootNode.append( doc.createElement( 'li' ) );\r
+                                       currentListItem = rootNode.append( item.element.clone( false, true ) );\r
                                        for ( var i = 0 ; i < item.contents.length ; i++ )\r
                                                currentListItem.append( item.contents[i].clone( true, true ) );\r
                                        currentIndex++;\r
@@ -104,9 +105,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                {\r
                                        currentListItem;\r
                                        if ( listNodeNames[ item.grandparent.getName() ] )\r
-                                               currentListItem = doc.createElement( 'li' );\r
+                                               currentListItem = item.element.clone( false, true );\r
                                        else\r
                                        {\r
+                                               // Create completely new blocks here, attributes are dropped.\r
                                                if ( paragraphMode != CKEDITOR.ENTER_BR && item.grandparent.getName() != 'td' )\r
                                                        currentListItem = doc.createElement( paragraphName );\r
                                                else\r
@@ -216,7 +218,13 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        CKEDITOR.dom.element.setMarker( database, itemNode, 'list_item_processed', true );\r
                }\r
 \r
-               var fakeParent = groupObj.root.getDocument().createElement( this.type );\r
+               var root = groupObj.root,\r
+                       fakeParent = root.getDocument().createElement( this.type );\r
+               // Copy all attributes, except from 'start' and 'type'.\r
+               root.copyAttributes( fakeParent, { start : 1, type : 1 } );\r
+               // The list-style-type property should be ignored.\r
+               fakeParent.removeStyle( 'list-style-type' );\r
+\r
                for ( i = 0 ; i < selectedListItems.length ; i++ )\r
                {\r
                        var listIndex = selectedListItems[i].getCustomData( 'listarray_index' );\r
@@ -232,6 +240,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                newList.listNode.replace( groupObj.root );\r
        }\r
 \r
+       var headerTagRegex = /^h[1-6]$/;\r
+\r
        function createList( editor, groupObj, listsCreated )\r
        {\r
                var contents = groupObj.contents,\r
@@ -283,8 +293,17 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                {\r
                        var contentBlock = listContents.shift(),\r
                                listItem = doc.createElement( 'li' );\r
-                       contentBlock.moveChildren( listItem );\r
-                       contentBlock.remove();\r
+\r
+                       // Preserve heading structure when converting to list item. (#5271)\r
+                       if ( headerTagRegex.test( contentBlock.getName() ) )\r
+                               contentBlock.appendTo( listItem );\r
+                       else\r
+                       {\r
+                               contentBlock.copyAttributes( listItem );\r
+                               contentBlock.moveChildren( listItem );\r
+                               contentBlock.remove();\r
+                       }\r
+\r
                        listItem.appendTo( listNode );\r
 \r
                        // Append a bogus BR to force the LI to render at full height\r
@@ -425,17 +444,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        while ( ranges.length > 0 )\r
                        {\r
                                range = ranges.shift();\r
-\r
-                               var boundaryNodes = range.getBoundaryNodes(),\r
-                                       startNode = boundaryNodes.startNode,\r
-                                       endNode = boundaryNodes.endNode;\r
-\r
-                               if ( startNode.type == CKEDITOR.NODE_ELEMENT && startNode.getName() == 'td' )\r
-                                       range.setStartAt( boundaryNodes.startNode, CKEDITOR.POSITION_AFTER_START );\r
-\r
-                               if ( endNode.type == CKEDITOR.NODE_ELEMENT && endNode.getName() == 'td' )\r
-                                       range.setEndAt( boundaryNodes.endNode, CKEDITOR.POSITION_BEFORE_END );\r
-\r
                                var iterator = range.createIterator(),\r
                                        block;\r
 \r
@@ -570,7 +578,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                nodeBefore = firstNestedList && firstNestedList.previous,\r
                                tailNbspmatch;\r
 \r
-                       if( nodeBefore\r
+                       if ( nodeBefore\r
                                && ( nodeBefore.name && nodeBefore.name == 'br'\r
                                        || nodeBefore.value && ( tailNbspmatch = nodeBefore.value.match( tailNbspRegex ) ) ) )\r
                        {\r
@@ -594,11 +602,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
        }\r
 \r
        var defaultListDataFilterRules = { elements : {} };\r
-       for( var i in dtd.$listItem )\r
+       for ( var i in dtd.$listItem )\r
                defaultListDataFilterRules.elements[ i ] = getExtendNestedListFilter();\r
 \r
        var defaultListHtmlFilterRules = { elements : {} };\r
-       for( i in dtd.$listItem )\r
+       for ( i in dtd.$listItem )\r
                defaultListHtmlFilterRules.elements[ i ] = getExtendNestedListFilter( true );\r
 \r
        CKEDITOR.plugins.add( 'list',\r
@@ -631,7 +639,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                afterInit : function ( editor )\r
                {\r
                        var dataProcessor = editor.dataProcessor;\r
-                       if( dataProcessor )\r
+                       if ( dataProcessor )\r
                        {\r
                                dataProcessor.dataFilter.addRules( defaultListDataFilterRules );\r
                                dataProcessor.htmlFilter.addRules( defaultListHtmlFilterRules );\r