X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fplugins%2Fstyles%2Fplugin.js;h=5eee1855aa4ec1e4db913c820a6e37af48f05acb;hp=8bab79d92351b8823d37c4924603a52af9e5e66b;hb=039a051ccf3901311661022a30afd60fc38130c9;hpb=c9fdde67e6384bd5a66adc2b3bba5c4ce9db56c7 diff --git a/_source/plugins/styles/plugin.js b/_source/plugins/styles/plugin.js index 8bab79d..5eee185 100644 --- a/_source/plugins/styles/plugin.js +++ b/_source/plugins/styles/plugin.js @@ -478,39 +478,64 @@ CKEDITOR.STYLE_OBJECT = 3; if ( applyStyle && styleRange && !styleRange.collapsed ) { // Build the style element, based on the style object definition. - var styleNode = getElement( this, document ); + var styleNode = getElement( this, document ), + styleHasAttrs = styleNode.hasAttributes(); // Get the element that holds the entire range. var parent = styleRange.getCommonAncestor(); + var removeList = { + styles : {}, + attrs : {}, + // Styles cannot be removed. + blockedStyles : {}, + // Attrs cannot be removed. + blockedAttrs : {} + }; + + var attName, styleName, value; + // Loop through the parents, removing the redundant attributes // from the element to be applied. while ( styleNode && parent ) { if ( parent.getName() == elementName ) { - for ( var attName in def.attributes ) + for ( attName in def.attributes ) { - if ( styleNode.getAttribute( attName ) == parent.getAttribute( attName ) ) - styleNode.removeAttribute( attName ); - } + if ( removeList.blockedAttrs[ attName ] || !( value = parent.getAttribute( styleName ) ) ) + continue; - for ( var styleName in def.styles ) - { - if ( styleNode.getStyle( styleName ) == parent.getStyle( styleName ) ) - styleNode.removeStyle( styleName ); + if ( styleNode.getAttribute( attName ) == value ) + removeList.attrs[ attName ] = 1; + else + removeList.blockedAttrs[ attName ] = 1; } - if ( !styleNode.hasAttributes() ) + for ( styleName in def.styles ) { - styleNode = null; - break; + if ( removeList.blockedStyles[ styleName ] || !( value = parent.getStyle( styleName ) ) ) + continue; + + if ( styleNode.getStyle( styleName ) == value ) + removeList.styles[ styleName ] = 1; + else + removeList.blockedStyles[ styleName ] = 1; } } parent = parent.getParent(); } + for ( attName in removeList.attrs ) + styleNode.removeAttribute( attName ); + + for ( styleName in removeList.styles ) + styleNode.removeStyle( styleName ); + + if ( styleHasAttrs && !styleNode.hasAttributes() ) + styleNode = null; + if ( styleNode ) { // Move the contents of the range to the style element. @@ -536,6 +561,15 @@ CKEDITOR.STYLE_OBJECT = 3; if ( !CKEDITOR.env.ie ) styleNode.$.normalize(); } + // Style already inherit from parents, left just to clear up any internal overrides. (#5931) + else + { + styleNode = new CKEDITOR.dom.element( 'span' ); + styleRange.extractContents().appendTo( styleNode ); + styleRange.insertNode( styleNode ); + removeFromInsideElement( this, styleNode ); + styleNode.remove( true ); + } // Style applied, let's release the range, so it gets // re-initialization in the next loop. @@ -775,7 +809,7 @@ CKEDITOR.STYLE_OBJECT = 3; while ( ( block = iterator.getNextParagraph() ) ) // Only one = { - var newBlock = getElement( this, doc ); + var newBlock = getElement( this, doc, block ); replaceBlock( block, newBlock ); } @@ -1083,7 +1117,7 @@ CKEDITOR.STYLE_OBJECT = 3; } } - function getElement( style, targetDocument ) + function getElement( style, targetDocument, element ) { var el; @@ -1098,6 +1132,10 @@ CKEDITOR.STYLE_OBJECT = 3; // Create the element. el = new CKEDITOR.dom.element( elementName, targetDocument ); + // #6226: attributes should be copied before the new ones are applied + if ( element ) + element.copyAttributes( el ); + return setupElement( el, style ); } @@ -1117,16 +1155,8 @@ CKEDITOR.STYLE_OBJECT = 3; } // Assign all defined styles. - if ( def.styles ) - { - for ( var i in def.styles ) - { - if ( !def.styles.hasOwnProperty( i ) ) - continue; - - el.setStyle( i, def.styles[ i ] ); - } - } + if( styles ) + el.setAttribute( 'style', styles ); return el; } @@ -1276,7 +1306,11 @@ CKEDITOR.STYLE_OBJECT = 3; // Compensate tail semi-colon. return styleText.replace( /\s*([;:])\s*/, '$1' ) .replace( /([^\s;])$/, '$1;') - .replace( /,\s+/g, ',' ) // Trimming spaces after comma (e.g. font-family name)(#4107). + // Trimming spaces after comma(#4107), + // remove quotations(#6403), + // mostly for differences on "font-family". + .replace( /,\s+/g, ',' ) + .replace( /\"/g,'' ) .toLowerCase(); } @@ -1320,8 +1354,8 @@ CKEDITOR.STYLE_OBJECT = 3; { var selection = document.getSelection(), // Bookmark the range so we can re-select it after processing. - bookmarks = selection.createBookmarks(), - ranges = selection.getRanges( true ), + bookmarks = selection.createBookmarks( 1 ), + ranges = selection.getRanges( 1 ), func = remove ? this.removeFromRange : this.applyToRange, range; @@ -1332,7 +1366,7 @@ CKEDITOR.STYLE_OBJECT = 3; if ( bookmarks.length == 1 && bookmarks[0].collapsed ) { selection.selectRanges( ranges ); - bookmarks[0].startNode.remove(); + document.getById( bookmarks[ 0 ].startNode ).remove(); } else selection.selectBookmarks( bookmarks );