X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fstyles%2Fplugin.js;h=85cda5f84d5f179e24267e614ab3edd6b5536604;hb=059b4c2fef02528bf1af189f7996e80652faddfb;hp=1d468ad4a4c0ccc938cfcbbfdcf3aff33caa2079;hpb=ea7e3453c7b0f023b050aca6d9f83ab372860d91;p=ckeditor.git diff --git a/_source/plugins/styles/plugin.js b/_source/plugins/styles/plugin.js index 1d468ad..85cda5f 100644 --- a/_source/plugins/styles/plugin.js +++ b/_source/plugins/styles/plugin.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -198,8 +198,8 @@ CKEDITOR.STYLE_OBJECT = 3; if ( attName == '_length' ) continue; - var elementAttr = element.getAttribute( attName ); - if ( attribs[attName] == + var elementAttr = element.getAttribute( attName ) || ''; + if ( attribs[ attName ] == ( attName == 'style' ? normalizeCssText( elementAttr, false ) : elementAttr ) ) { @@ -209,7 +209,7 @@ CKEDITOR.STYLE_OBJECT = 3; else if ( fullMatch ) return false; } - if( fullMatch ) + if ( fullMatch ) return true; } else @@ -267,7 +267,7 @@ CKEDITOR.STYLE_OBJECT = 3; stylesText = stylesText.replace( semicolonFixRegex, ';' ); for ( var style in stylesDef ) - stylesText += style + ':' + stylesDef[ style ] + ';'; + stylesText += ( style + ':' + stylesDef[ style ] ).replace( semicolonFixRegex, ';' ); // Browsers make some changes to the style when applying them. So, here // we normalize it to the browser format. @@ -375,13 +375,17 @@ CKEDITOR.STYLE_OBJECT = 3; } // Check if the current node can be a child of the style element. - 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 ) ) ) + 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 ) + && ( !def.childRule || def.childRule( currentNode ) ) ) ) { var currentParent = currentNode.getParent(); // Check if the style element can be a child of the current // node parent or if the element is not defined in the DTD. - if ( currentParent && ( ( currentParent.getDtd() || CKEDITOR.dtd.span )[ elementName ] || isUnknownElement ) ) + if ( currentParent + && ( ( currentParent.getDtd() || CKEDITOR.dtd.span )[ elementName ] || isUnknownElement ) + && ( !def.parentRule || def.parentRule( currentParent ) ) ) { // This node will be part of our range, so if it has not // been started, place its start right before the node. @@ -406,7 +410,8 @@ CKEDITOR.STYLE_OBJECT = 3; // to the range. while ( !includedNode.$.nextSibling && ( parentNode = includedNode.getParent(), dtd[ parentNode.getName() ] ) - && ( parentNode.getPosition( firstNode ) | CKEDITOR.POSITION_FOLLOWING | CKEDITOR.POSITION_IDENTICAL | CKEDITOR.POSITION_IS_CONTAINED ) == ( CKEDITOR.POSITION_FOLLOWING + CKEDITOR.POSITION_IDENTICAL + CKEDITOR.POSITION_IS_CONTAINED ) ) + && ( parentNode.getPosition( firstNode ) | CKEDITOR.POSITION_FOLLOWING | CKEDITOR.POSITION_IDENTICAL | CKEDITOR.POSITION_IS_CONTAINED ) == ( CKEDITOR.POSITION_FOLLOWING + CKEDITOR.POSITION_IDENTICAL + CKEDITOR.POSITION_IS_CONTAINED ) + && ( !def.childRule || def.childRule( parentNode ) ) ) { includedNode = parentNode; } @@ -575,7 +580,7 @@ CKEDITOR.STYLE_OBJECT = 3; if ( newElement.equals( boundaryElement ) ) break; // Avoid copying any matched element. - else if( newElement.match ) + else if ( newElement.match ) continue; else newElement = newElement.clone(); @@ -645,7 +650,7 @@ CKEDITOR.STYLE_OBJECT = 3; if ( currentNode.type == CKEDITOR.NODE_ELEMENT && this.checkElementRemovable( currentNode ) ) { // Remove style from element or overriding element. - if( currentNode.getName() == this.element ) + if ( currentNode.getName() == this.element ) removeFromElement( this, currentNode ); else removeOverrides( currentNode, getOverrides( this )[ currentNode.getName() ] ); @@ -682,7 +687,7 @@ CKEDITOR.STYLE_OBJECT = 3; var doc = range.document; var previousPreBlock; - while( ( block = iterator.getNextParagraph() ) ) // Only one = + while ( ( block = iterator.getNextParagraph() ) ) // Only one = { var newBlock = getElement( this, doc ); replaceBlock( block, newBlock ); @@ -890,7 +895,7 @@ CKEDITOR.STYLE_OBJECT = 3; // Now remove override styles on the element. attributes = overrides[ element.getName() ]; - if( attributes ) + if ( attributes ) removeAttrs(); removeNoAttribsElement( element ); } @@ -1126,7 +1131,7 @@ CKEDITOR.STYLE_OBJECT = 3; */ function getOverrides( style ) { - if( style._.overrides ) + if ( style._.overrides ) return style._.overrides; var overrides = ( style._.overrides = {} ), @@ -1191,7 +1196,7 @@ CKEDITOR.STYLE_OBJECT = 3; // retrieving its final format. var temp = new CKEDITOR.dom.element( 'span' ); temp.setAttribute( 'style', unparsedCssText ); - styleText = temp.getAttribute( 'style' ); + styleText = temp.getAttribute( 'style' ) || ''; } else styleText = unparsedCssText; @@ -1200,6 +1205,7 @@ 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). .toLowerCase(); } @@ -1240,3 +1246,13 @@ CKEDITOR.styleCommand.prototype.exec = function( editor ) return !!doc; }; + +CKEDITOR.stylesSet = new CKEDITOR.resourceManager( '', 'stylesSet' ); + +// Backward compatibility (#5025). +CKEDITOR.addStylesSet = CKEDITOR.tools.bind( CKEDITOR.stylesSet.add, CKEDITOR.stylesSet ); +CKEDITOR.loadStylesSet = function( name, url, callback ) + { + CKEDITOR.stylesSet.addExternal( name, url, '' ); + CKEDITOR.stylesSet.load( name, callback ); + };