JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.2
[ckeditor.git] / _source / plugins / styles / plugin.js
index 1d468ad..85cda5f 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
@@ -198,8 +198,8 @@ CKEDITOR.STYLE_OBJECT = 3;
                                                if ( attName == '_length' )\r
                                                        continue;\r
 \r
-                                               var elementAttr = element.getAttribute( attName );\r
-                                               if ( attribs[attName] ==\r
+                                               var elementAttr = element.getAttribute( attName ) || '';\r
+                                               if ( attribs[ attName ] ==\r
                                                         ( attName == 'style' ?\r
                                                           normalizeCssText( elementAttr, false ) : elementAttr  ) )\r
                                                {\r
@@ -209,7 +209,7 @@ CKEDITOR.STYLE_OBJECT = 3;
                                                else if ( fullMatch )\r
                                                                return false;\r
                                        }\r
-                                       if( fullMatch )\r
+                                       if ( fullMatch )\r
                                                return true;\r
                                }\r
                                else\r
@@ -267,7 +267,7 @@ CKEDITOR.STYLE_OBJECT = 3;
                        stylesText = stylesText.replace( semicolonFixRegex, ';' );\r
 \r
                for ( var style in stylesDef )\r
-                       stylesText += style + ':' + stylesDef[ style ] + ';';\r
+                       stylesText += ( style + ':' + stylesDef[ style ] ).replace( semicolonFixRegex, ';' );\r
 \r
                // Browsers make some changes to the style when applying them. So, here\r
                // we normalize it to the browser format.\r
@@ -375,13 +375,17 @@ CKEDITOR.STYLE_OBJECT = 3;
                                }\r
 \r
                                // Check if the current node can be a child of the style element.\r
-                               if ( !nodeName || ( dtd[ nodeName ] && ( currentNode.getPosition( lastNode ) | CKEDITOR.POSITION_PRECEDING | CKEDITOR.POSITION_IDENTICAL | CKEDITOR.POSITION_IS_CONTAINED ) == ( CKEDITOR.POSITION_PRECEDING + CKEDITOR.POSITION_IDENTICAL + CKEDITOR.POSITION_IS_CONTAINED ) ) )\r
+                               if ( !nodeName || ( dtd[ nodeName ]\r
+                                       && ( currentNode.getPosition( lastNode ) | CKEDITOR.POSITION_PRECEDING | CKEDITOR.POSITION_IDENTICAL | CKEDITOR.POSITION_IS_CONTAINED ) == ( CKEDITOR.POSITION_PRECEDING + CKEDITOR.POSITION_IDENTICAL + CKEDITOR.POSITION_IS_CONTAINED )\r
+                                       && ( !def.childRule || def.childRule( currentNode ) ) ) )\r
                                {\r
                                        var currentParent = currentNode.getParent();\r
 \r
                                        // Check if the style element can be a child of the current\r
                                        // node parent or if the element is not defined in the DTD.\r
-                                       if ( currentParent && ( ( currentParent.getDtd() || CKEDITOR.dtd.span )[ elementName ] || isUnknownElement ) )\r
+                                       if ( currentParent\r
+                                               && ( ( currentParent.getDtd() || CKEDITOR.dtd.span )[ elementName ] || isUnknownElement )\r
+                                               && ( !def.parentRule || def.parentRule( currentParent ) ) )\r
                                        {\r
                                                // This node will be part of our range, so if it has not\r
                                                // been started, place its start right before the node.\r
@@ -406,7 +410,8 @@ CKEDITOR.STYLE_OBJECT = 3;
                                                        // to the range.\r
                                                        while ( !includedNode.$.nextSibling\r
                                                                && ( parentNode = includedNode.getParent(), dtd[ parentNode.getName() ] )\r
-                                                               && ( parentNode.getPosition( firstNode ) | CKEDITOR.POSITION_FOLLOWING | CKEDITOR.POSITION_IDENTICAL | CKEDITOR.POSITION_IS_CONTAINED ) == ( CKEDITOR.POSITION_FOLLOWING + CKEDITOR.POSITION_IDENTICAL + CKEDITOR.POSITION_IS_CONTAINED ) )\r
+                                                               && ( parentNode.getPosition( firstNode ) | CKEDITOR.POSITION_FOLLOWING | CKEDITOR.POSITION_IDENTICAL | CKEDITOR.POSITION_IS_CONTAINED ) == ( CKEDITOR.POSITION_FOLLOWING + CKEDITOR.POSITION_IDENTICAL + CKEDITOR.POSITION_IS_CONTAINED )\r
+                                                               && ( !def.childRule || def.childRule( parentNode ) ) )\r
                                                        {\r
                                                                includedNode = parentNode;\r
                                                        }\r
@@ -575,7 +580,7 @@ CKEDITOR.STYLE_OBJECT = 3;
                                        if ( newElement.equals( boundaryElement ) )\r
                                                break;\r
                                        // Avoid copying any matched element.\r
-                                       else if( newElement.match )\r
+                                       else if ( newElement.match )\r
                                                continue;\r
                                        else\r
                                                newElement = newElement.clone();\r
@@ -645,7 +650,7 @@ CKEDITOR.STYLE_OBJECT = 3;
                                if ( currentNode.type == CKEDITOR.NODE_ELEMENT && this.checkElementRemovable( currentNode ) )\r
                                {\r
                                        // Remove style from element or overriding element.\r
-                                       if( currentNode.getName() == this.element )\r
+                                       if ( currentNode.getName() == this.element )\r
                                                removeFromElement( this, currentNode );\r
                                        else\r
                                                removeOverrides( currentNode, getOverrides( this )[ currentNode.getName() ] );\r
@@ -682,7 +687,7 @@ CKEDITOR.STYLE_OBJECT = 3;
                var doc = range.document;\r
                var previousPreBlock;\r
 \r
-               while( ( block = iterator.getNextParagraph() ) )                // Only one =\r
+               while ( ( block = iterator.getNextParagraph() ) )               // Only one =\r
                {\r
                        var newBlock = getElement( this, doc );\r
                        replaceBlock( block, newBlock );\r
@@ -890,7 +895,7 @@ CKEDITOR.STYLE_OBJECT = 3;
 \r
                // Now remove override styles on the element.\r
                attributes = overrides[ element.getName() ];\r
-               if( attributes )\r
+               if ( attributes )\r
                        removeAttrs();\r
                removeNoAttribsElement( element );\r
        }\r
@@ -1126,7 +1131,7 @@ CKEDITOR.STYLE_OBJECT = 3;
         */\r
        function getOverrides( style )\r
        {\r
-               if( style._.overrides )\r
+               if ( style._.overrides )\r
                        return style._.overrides;\r
 \r
                var overrides = ( style._.overrides = {} ),\r
@@ -1191,7 +1196,7 @@ CKEDITOR.STYLE_OBJECT = 3;
                        // retrieving its final format.\r
                        var temp = new CKEDITOR.dom.element( 'span' );\r
                        temp.setAttribute( 'style', unparsedCssText );\r
-                       styleText = temp.getAttribute( 'style' );\r
+                       styleText = temp.getAttribute( 'style' ) || '';\r
                }\r
                else\r
                        styleText = unparsedCssText;\r
@@ -1200,6 +1205,7 @@ CKEDITOR.STYLE_OBJECT = 3;
                // Compensate tail semi-colon.\r
                return styleText.replace( /\s*([;:])\s*/, '$1' )\r
                                                         .replace( /([^\s;])$/, '$1;')\r
+                                                        .replace( /,\s+/g, ',' ) // Trimming spaces after comma (e.g. font-family name)(#4107).\r
                                                         .toLowerCase();\r
        }\r
 \r
@@ -1240,3 +1246,13 @@ CKEDITOR.styleCommand.prototype.exec = function( editor )
 \r
        return !!doc;\r
 };\r
+\r
+CKEDITOR.stylesSet = new CKEDITOR.resourceManager( '', 'stylesSet' );\r
+\r
+// Backward compatibility (#5025).\r
+CKEDITOR.addStylesSet = CKEDITOR.tools.bind( CKEDITOR.stylesSet.add, CKEDITOR.stylesSet );\r
+CKEDITOR.loadStylesSet = function( name, url, callback )\r
+       {\r
+               CKEDITOR.stylesSet.addExternal( name, url, '' );\r
+               CKEDITOR.stylesSet.load( name, callback );\r
+       };\r