JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.6.2
[ckeditor.git] / _source / plugins / list / plugin.js
index bc28e51..ad79153 100644 (file)
@@ -16,6 +16,20 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                bookmarks = CKEDITOR.dom.walker.bookmark(),\r
                nonEmpty = function( node ){ return !( whitespaces( node ) || bookmarks( node ) ); };\r
 \r
+       function cleanUpDirection( element )\r
+       {\r
+               var dir, parent, parentDir;\r
+               if ( ( dir = element.getDirection() ) )\r
+               {\r
+                       parent = element.getParent();\r
+                       while ( parent && !( parentDir = parent.getDirection() ) )\r
+                               parent = parent.getParent();\r
+\r
+                       if ( dir == parentDir )\r
+                               element.removeAttribute( 'dir' );\r
+               }\r
+       }\r
+\r
        CKEDITOR.plugins.list = {\r
                /*\r
                 * Convert a DOM list tree into a data structure that is easier to\r
@@ -107,8 +121,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                                        if ( orgDir != rootNode.getDirection( 1 ) )\r
                                                currentListItem.setAttribute( 'dir', orgDir );\r
-                                       else\r
-                                               currentListItem.removeAttribute( 'dir' );\r
 \r
                                        for ( var i = 0 ; i < item.contents.length ; i++ )\r
                                                currentListItem.append( item.contents[i].clone( 1, 1 ) );\r
@@ -155,8 +167,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        {\r
                                                if ( item.grandparent.getDirection( 1 ) != orgDir )\r
                                                        currentListItem.setAttribute( 'dir', orgDir );\r
-                                               else\r
-                                                       currentListItem.removeAttribute( 'dir' );\r
                                        }\r
 \r
                                        for ( i = 0 ; i < item.contents.length ; i++ )\r
@@ -208,14 +218,23 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        break;\r
                        }\r
 \r
-                       // Clear marker attributes for the new list tree made of cloned nodes, if any.\r
                        if ( database )\r
                        {\r
-                               var currentNode = retval.getFirst();\r
+                               var currentNode = retval.getFirst(),\r
+                                       listRoot = listArray[ 0 ].parent;\r
+\r
                                while ( currentNode )\r
                                {\r
                                        if ( currentNode.type == CKEDITOR.NODE_ELEMENT )\r
+                                       {\r
+                                               // Clear marker attributes for the new list tree made of cloned nodes, if any.\r
                                                CKEDITOR.dom.element.clearMarkers( database, currentNode );\r
+\r
+                                               // Clear redundant direction attribute specified on list items.\r
+                                               if ( currentNode.getName() in CKEDITOR.dtd.$listItem )\r
+                                                       cleanUpDirection( currentNode );\r
+                                       }\r
+\r
                                        currentNode = currentNode.getNextSourceNode();\r
                                }\r
                        }\r
@@ -464,6 +483,22 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                this.type = type;\r
        }\r
 \r
+       // Move direction attribute from root to list items.\r
+       function dirToListItems( list )\r
+       {\r
+               var dir = list.getDirection();\r
+               if ( dir )\r
+               {\r
+                       for ( var i = 0, children = list.getChildren(), child; child = children.getItem( i ), i < children.count(); i++ )\r
+                       {\r
+                               if ( child.type == CKEDITOR.NODE_ELEMENT && child.is( 'li' ) && !child.getDirection() )\r
+                                       child.setAttribute( 'dir', dir );\r
+                       }\r
+\r
+                       list.removeAttribute( 'dir' );\r
+               }\r
+       }\r
+\r
        listCommand.prototype = {\r
                exec : function( editor )\r
                {\r
@@ -617,6 +652,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        if ( sibling && sibling.getName &&\r
                                                 sibling.getName() == listCommand.type )\r
                                        {\r
+\r
+                                               // In case to be merged lists have difference directions. (#7448)\r
+                                               if ( sibling.getDirection( 1 ) != listNode.getDirection( 1 ) )\r
+                                                       dirToListItems( listNode.getDirection() ? listNode : sibling );\r
+\r
                                                sibling.remove();\r
                                                // Move children order by merge direction.(#3820)\r
                                                sibling.moveChildren( listNode, rtl );\r