JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.5.1
[ckeditor.git] / _source / plugins / bidi / plugin.js
index d3ef351..830e2d4 100644 (file)
@@ -1,11 +1,11 @@
 /*\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
 (function()\r
 {\r
-       var guardElements = { table:1, tbody: 1, ul:1, ol:1, blockquote:1, div:1, tr: 1 },\r
+       var guardElements = { table:1, ul:1, ol:1, blockquote:1, div:1 },\r
                directSelectionGuardElements = {},\r
                // All guard elements which can have a direction applied on them.\r
                allGuardElements = {};\r
@@ -33,7 +33,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                selectedElement = selectedElement || path.block || path.blockLimit;\r
 \r
-               if ( !selectedElement || selectedElement.getName() == 'body' )\r
+               // If we're having BODY here, user probably done CTRL+A, let's try to get the enclosed node, if any.\r
+               selectedElement.is( 'body' ) &&\r
+                       ( selectedElement = editor.getSelection().getRanges()[ 0 ].getEnclosedNode() );\r
+\r
+               if ( !selectedElement )\r
                        return;\r
 \r
                var selectionDir = useComputedState ?\r
@@ -136,11 +140,14 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                return null;\r
        }\r
 \r
-       function getFullySelected( range, elements )\r
+       function getFullySelected( range, elements, enterMode )\r
        {\r
                var ancestor = range.getCommonAncestor( false, true );\r
 \r
-               range.enlarge( CKEDITOR.ENLARGE_BLOCK_CONTENTS );\r
+               range = range.clone();\r
+               range.enlarge( enterMode == CKEDITOR.ENTER_BR ?\r
+                               CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS\r
+                               : CKEDITOR.ENLARGE_BLOCK_CONTENTS );\r
 \r
                if ( range.checkBoundaryOfElement( ancestor, CKEDITOR.START )\r
                                && range.checkBoundaryOfElement( ancestor, CKEDITOR.END ) )\r
@@ -149,8 +156,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        while ( ancestor && ancestor.type == CKEDITOR.NODE_ELEMENT\r
                                        && ( parent = ancestor.getParent() )\r
                                        && parent.getChildCount() == 1\r
-                                       && ( !( ancestor.getName() in elements ) || ( parent.getName() in elements ) )\r
-                                       )\r
+                                       && !( ancestor.getName() in elements ) )\r
                                ancestor = parent;\r
 \r
                        return ancestor.type == CKEDITOR.NODE_ELEMENT\r
@@ -187,7 +193,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        if ( !selectedElement || selectedElement\r
                                                        && !( selectedElement.type == CKEDITOR.NODE_ELEMENT && selectedElement.getName() in directSelectionGuardElements )\r
                                                )\r
-                                               selectedElement = getFullySelected( range, guardElements );\r
+                                               selectedElement = getFullySelected( range, guardElements, enterMode );\r
 \r
                                        if ( selectedElement && !selectedElement.isReadOnly() )\r
                                                switchDir( selectedElement, dir, editor, database );\r
@@ -205,7 +211,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        {\r
                                                return !! ( node.type == CKEDITOR.NODE_ELEMENT\r
                                                                && node.getName() in guardElements\r
-                                                               && !( node.getName() == ( enterMode == CKEDITOR.ENTER_P ) ? 'p' : 'div'\r
+                                                               && !( node.getName() == ( enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' )\r
                                                                        && node.getParent().type == CKEDITOR.NODE_ELEMENT\r
                                                                        && node.getParent().getName() == 'blockquote' )\r
                                                                // Element must be fully included in the range as well. (#6485).\r
@@ -221,7 +227,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                                        while ( ( block = iterator.getNextParagraph( enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) ) )\r
                                                !block.isReadOnly() && switchDir( block, dir, editor, database );\r
-                               }\r
+                                       }\r
 \r
                                CKEDITOR.dom.element.clearAllMarkers( database );\r
 \r
@@ -263,3 +269,12 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
        });\r
 \r
 })();\r
+\r
+/**\r
+ * Fired when the language direction of an element is changed\r
+ * @name CKEDITOR.editor#dirChanged\r
+ * @event\r
+ * @param {CKEDITOR.editor} editor This editor instance.\r
+ * @param {Object} eventData.node The element that is being changed.\r
+ * @param {String} eventData.dir The new direction.\r
+ */\r