X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fstyles%2Fplugin.js;h=6d5bd8d3af3f6ecfe9543a4461963eab5997962d;hb=3fe9cac293e090ea459a3ee10d78cbe9e1dd0e03;hp=0850a66bbdd111b59762200c982b5a394a1969e7;hpb=f0610347140239143439a511ee2bd48cb784f470;p=ckeditor.git diff --git a/_source/plugins/styles/plugin.js b/_source/plugins/styles/plugin.js index 0850a66..6d5bd8d 100644 --- a/_source/plugins/styles/plugin.js +++ b/_source/plugins/styles/plugin.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -90,6 +90,16 @@ CKEDITOR.STYLE_OBJECT = 3; CKEDITOR.style = function( styleDefinition, variablesValues ) { + // Inline style text as attribute should be converted + // to styles object. + var attrs = styleDefinition.attributes; + if ( attrs && attrs.style ) + { + styleDefinition.styles = CKEDITOR.tools.extend( {}, + styleDefinition.styles, parseStyleText( attrs.style ) ); + delete attrs.style; + } + if ( variablesValues ) { styleDefinition = CKEDITOR.tools.clone( styleDefinition ); @@ -218,15 +228,15 @@ CKEDITOR.STYLE_OBJECT = 3; return true; }, - // Checks if an element, or any of its attributes, is removable by the - // current style definition. - checkElementRemovable : function( element, fullMatch ) + // Check if the element matches the current style definition. + checkElementMatch : function( element, fullMatch ) { - if ( !element || element.isReadOnly() ) + var def = this._.definition; + + if ( !element || !def.ignoreReadonly && element.isReadOnly() ) return false; - var def = this._.definition, - attribs, + var attribs, name = element.getName(); // If the element name is the same as the style name. @@ -265,10 +275,23 @@ CKEDITOR.STYLE_OBJECT = 3; return true; } - // Check if the element can be somehow overriden. + return false; + }, + + // Checks if an element, or any of its attributes, is removable by the + // current style definition. + checkElementRemovable : function( element, fullMatch ) + { + // Check element matches the style itself. + if ( this.checkElementMatch( element, fullMatch ) ) + return true; + + // Check if the element matches the style overrides. var override = getOverrides( this )[ element.getName() ] ; if ( override ) { + var attribs, attName; + // If no attributes have been defined, remove the element. if ( !( attribs = override.attributes ) ) return true; @@ -423,7 +446,8 @@ CKEDITOR.STYLE_OBJECT = 3; var isUnknownElement; // Indicates that fully selected read-only elements are to be included in the styling range. - var includeReadonly = def.includeReadonly; + var ignoreReadonly = def.ignoreReadonly, + includeReadonly = ignoreReadonly || def.includeReadonly; // If the read-only inclusion is not available in the definition, try // to get it from the document data. @@ -447,19 +471,22 @@ CKEDITOR.STYLE_OBJECT = 3; var styleRange; - // Check if the boundaries are inside non stylable elements. - var firstUnstylable = getUnstylableParent( firstNode ), - lastUnstylable = getUnstylableParent( lastNode ); - - // If the first element can't be styled, we'll start processing right - // after its unstylable root. - if ( firstUnstylable ) - currentNode = firstUnstylable.getNextSourceNode( true ); - - // If the last element can't be styled, we'll stop processing on its - // unstylable root. - if ( lastUnstylable ) - lastNode = lastUnstylable; + if ( !ignoreReadonly ) + { + // Check if the boundaries are inside non stylable elements. + var firstUnstylable = getUnstylableParent( firstNode ), + lastUnstylable = getUnstylableParent( lastNode ); + + // If the first element can't be styled, we'll start processing right + // after its unstylable root. + if ( firstUnstylable ) + currentNode = firstUnstylable.getNextSourceNode( true ); + + // If the last element can't be styled, we'll stop processing on its + // unstylable root. + if ( lastUnstylable ) + lastNode = lastUnstylable; + } // Do nothing if the current node now follows the last node to be processed. if ( currentNode.getPosition( lastNode ) == CKEDITOR.POSITION_FOLLOWING ) @@ -786,7 +813,7 @@ CKEDITOR.STYLE_OBJECT = 3; breakNodes(); // Now, do the DFS walk. - var currentNode = startNode.getNext(); + var currentNode = startNode; while ( !currentNode.equals( endNode ) ) { /* @@ -839,7 +866,6 @@ CKEDITOR.STYLE_OBJECT = 3; var style = this, def = style._.definition, attributes = def.attributes; - var styles = CKEDITOR.style.getStyleText( def ); // Remove all defined attributes. if ( attributes ) @@ -1128,8 +1154,9 @@ CKEDITOR.STYLE_OBJECT = 3; function removeFromElement( style, element ) { var def = style._.definition, - attributes = CKEDITOR.tools.extend( {}, def.attributes, getOverrides( style )[ element.getName() ] ), + attributes = def.attributes, styles = def.styles, + overrides = getOverrides( style )[ element.getName() ], // If the style is only about the element itself, we have to remove the element. removeEmpty = CKEDITOR.tools.isEmpty( attributes ) && CKEDITOR.tools.isEmpty( styles ); @@ -1155,6 +1182,9 @@ CKEDITOR.STYLE_OBJECT = 3; element.removeStyle( styleName ); } + // Remove overrides, but don't remove the element if it's a block element + removeOverrides( element, overrides, blockElements[ element.getName() ] ) ; + if ( removeEmpty ) { !CKEDITOR.dtd.$block[ element.getName() ] || style._.enterMode == CKEDITOR.ENTER_BR && !element.hasAttributes() ? @@ -1196,8 +1226,9 @@ CKEDITOR.STYLE_OBJECT = 3; * Note: Remove the element if no attributes remain. * @param {Object} element * @param {Object} overrides + * @param {Boolean} Don't remove the element */ - function removeOverrides( element, overrides ) + function removeOverrides( element, overrides, dontRemove ) { var attributes = overrides && overrides.attributes ; @@ -1225,7 +1256,8 @@ CKEDITOR.STYLE_OBJECT = 3; } } - removeNoAttribsElement( element ); + if ( !dontRemove ) + removeNoAttribsElement( element ); } // If the element has no more attributes, remove it.