JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.6.3
[ckeditor.git] / _source / plugins / styles / plugin.js
index 0850a66..2c16b7e 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.\r
 For licensing, see LICENSE.html or http://ckeditor.com/license\r
 */\r
 \r
@@ -222,11 +222,12 @@ CKEDITOR.STYLE_OBJECT = 3;
                // current style definition.\r
                checkElementRemovable : function( element, fullMatch )\r
                {\r
-                       if ( !element || element.isReadOnly() )\r
+                       var def = this._.definition;\r
+\r
+                       if ( !element || !def.ignoreReadonly && element.isReadOnly() )\r
                                return false;\r
 \r
-                       var def = this._.definition,\r
-                               attribs,\r
+                       var attribs,\r
                                name = element.getName();\r
 \r
                        // If the element name is the same as the style name.\r
@@ -423,7 +424,8 @@ CKEDITOR.STYLE_OBJECT = 3;
                var isUnknownElement;\r
 \r
                // Indicates that fully selected read-only elements are to be included in the styling range.\r
-               var includeReadonly = def.includeReadonly;\r
+               var ignoreReadonly = def.ignoreReadonly,\r
+                       includeReadonly = ignoreReadonly || def.includeReadonly;\r
 \r
                // If the read-only inclusion is not available in the definition, try\r
                // to get it from the document data.\r
@@ -447,19 +449,22 @@ CKEDITOR.STYLE_OBJECT = 3;
 \r
                var styleRange;\r
 \r
-               // Check if the boundaries are inside non stylable elements.\r
-               var firstUnstylable = getUnstylableParent( firstNode ),\r
-                       lastUnstylable = getUnstylableParent( lastNode );\r
-\r
-               // If the first element can't be styled, we'll start processing right\r
-               // after its unstylable root.\r
-               if ( firstUnstylable )\r
-                       currentNode = firstUnstylable.getNextSourceNode( true );\r
-\r
-               // If the last element can't be styled, we'll stop processing on its\r
-               // unstylable root.\r
-               if ( lastUnstylable )\r
-                       lastNode = lastUnstylable;\r
+               if ( !ignoreReadonly )\r
+               {\r
+                       // Check if the boundaries are inside non stylable elements.\r
+                       var firstUnstylable = getUnstylableParent( firstNode ),\r
+                                       lastUnstylable = getUnstylableParent( lastNode );\r
+\r
+                       // If the first element can't be styled, we'll start processing right\r
+                       // after its unstylable root.\r
+                       if ( firstUnstylable )\r
+                               currentNode = firstUnstylable.getNextSourceNode( true );\r
+\r
+                       // If the last element can't be styled, we'll stop processing on its\r
+                       // unstylable root.\r
+                       if ( lastUnstylable )\r
+                               lastNode = lastUnstylable;\r
+               }\r
 \r
                // Do nothing if the current node now follows the last node to be processed.\r
                if ( currentNode.getPosition( lastNode ) == CKEDITOR.POSITION_FOLLOWING )\r
@@ -786,7 +791,7 @@ CKEDITOR.STYLE_OBJECT = 3;
                        breakNodes();\r
 \r
                        // Now, do the DFS walk.\r
-                       var currentNode = startNode.getNext();\r
+                       var currentNode = startNode;\r
                        while ( !currentNode.equals( endNode ) )\r
                        {\r
                                /*\r
@@ -839,7 +844,6 @@ CKEDITOR.STYLE_OBJECT = 3;
                var style = this,\r
                        def = style._.definition,\r
                        attributes = def.attributes;\r
-               var styles = CKEDITOR.style.getStyleText( def );\r
 \r
                // Remove all defined attributes.\r
                if ( attributes )\r
@@ -1128,8 +1132,9 @@ CKEDITOR.STYLE_OBJECT = 3;
        function removeFromElement( style, element )\r
        {\r
                var def = style._.definition,\r
-                       attributes = CKEDITOR.tools.extend( {}, def.attributes, getOverrides( style )[ element.getName() ] ),\r
+                       attributes = def.attributes,\r
                        styles = def.styles,\r
+                       overrides = getOverrides( style )[ element.getName() ],\r
                        // If the style is only about the element itself, we have to remove the element.\r
                        removeEmpty = CKEDITOR.tools.isEmpty( attributes ) && CKEDITOR.tools.isEmpty( styles );\r
 \r
@@ -1155,6 +1160,9 @@ CKEDITOR.STYLE_OBJECT = 3;
                        element.removeStyle( styleName );\r
                }\r
 \r
+               // Remove overrides, but don't remove the element if it's a block element\r
+               removeOverrides( element, overrides, blockElements[ element.getName() ] ) ;\r
+\r
                if ( removeEmpty )\r
                {\r
                        !CKEDITOR.dtd.$block[ element.getName() ] || style._.enterMode == CKEDITOR.ENTER_BR && !element.hasAttributes() ?\r
@@ -1196,8 +1204,9 @@ CKEDITOR.STYLE_OBJECT = 3;
         *  Note: Remove the element if no attributes remain.\r
         * @param {Object} element\r
         * @param {Object} overrides\r
+        * @param {Boolean} Don't remove the element\r
         */\r
-       function removeOverrides( element, overrides )\r
+       function removeOverrides( element, overrides, dontRemove )\r
        {\r
                var attributes = overrides && overrides.attributes ;\r
 \r
@@ -1225,7 +1234,8 @@ CKEDITOR.STYLE_OBJECT = 3;
                        }\r
                }\r
 \r
-               removeNoAttribsElement( element );\r
+               if ( !dontRemove )\r
+                       removeNoAttribsElement( element );\r
        }\r
 \r
        // If the element has no more attributes, remove it.\r