(function()\r
{\r
var blockElements = { address:1,div:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1,p:1,pre:1 };\r
- var objectElements = { a:1,embed:1,hr:1,img:1,li:1,object:1,ol:1,table:1,td:1,tr:1,ul:1 };\r
+ var objectElements = { a:1,embed:1,hr:1,img:1,li:1,object:1,ol:1,table:1,td:1,tr:1,th:1,ul:1,dl:1,dt:1,dd:1,form:1};\r
\r
var semicolonFixRegex = /\s*(?:;\s*|$)/;\r
\r
applyInlineStyle\r
: this.type == CKEDITOR.STYLE_BLOCK ?\r
applyBlockStyle\r
+ : this.type == CKEDITOR.STYLE_OBJECT ?\r
+ applyObjectStyle\r
: null ).call( this, range );\r
},\r
\r
case CKEDITOR.STYLE_BLOCK :\r
return this.checkElementRemovable( elementPath.block || elementPath.blockLimit, true );\r
\r
+ case CKEDITOR.STYLE_OBJECT :\r
case CKEDITOR.STYLE_INLINE :\r
\r
var elements = elementPath.elements;\r
\r
for ( var i = 0, element ; i < elements.length ; i++ )\r
{\r
- element = elements[i];\r
+ element = elements[ i ];\r
\r
- if ( element == elementPath.block || element == elementPath.blockLimit )\r
+ if ( this.type == CKEDITOR.STYLE_INLINE\r
+ && ( element == elementPath.block || element == elementPath.blockLimit ) )\r
continue;\r
\r
+ if( this.type == CKEDITOR.STYLE_OBJECT\r
+ && !( element.getName() in objectElements ) )\r
+ continue;\r
+\r
if ( this.checkElementRemovable( element, true ) )\r
return true;\r
}\r
return false;\r
},\r
\r
+ checkApplicable : function( elementPath )\r
+ {\r
+ switch ( this.type )\r
+ {\r
+ case CKEDITOR.STYLE_INLINE :\r
+ case CKEDITOR.STYLE_BLOCK :\r
+ break;\r
+\r
+ case CKEDITOR.STYLE_OBJECT :\r
+ return elementPath.lastElement.getAscendant( this.element, true );\r
+ }\r
+\r
+ return true;\r
+ },\r
+\r
// Checks if an element, or any of its attributes, is removable by the\r
// current style definition.\r
checkElementRemovable : function( element, fullMatch )\r
continue;\r
\r
var elementAttr = element.getAttribute( attName ) || '';\r
- if ( attribs[ attName ] ==\r
- ( attName == 'style' ?\r
- normalizeCssText( elementAttr, false ) : elementAttr ) )\r
+ if ( attName == 'style' ?\r
+ compareCssText( attribs[ attName ], normalizeCssText( elementAttr, false ) )\r
+ : attribs[ attName ] == elementAttr )\r
{\r
if ( !fullMatch )\r
return true;\r
}\r
}\r
return false;\r
+ },\r
+\r
+ // Builds the preview HTML based on the styles definition.\r
+ buildPreview : function()\r
+ {\r
+ var styleDefinition = this._.definition,\r
+ html = [],\r
+ elementName = styleDefinition.element;\r
+\r
+ // Avoid <bdo> in the preview.\r
+ if ( elementName == 'bdo' )\r
+ elementName = 'span';\r
+\r
+ html = [ '<', elementName ];\r
+\r
+ // Assign all defined attributes.\r
+ var attribs = styleDefinition.attributes;\r
+ if ( attribs )\r
+ {\r
+ for ( var att in attribs )\r
+ {\r
+ html.push( ' ', att, '="', attribs[ att ], '"' );\r
+ }\r
+ }\r
+\r
+ // Assign the style attribute.\r
+ var cssStyle = CKEDITOR.style.getStyleText( styleDefinition );\r
+ if ( cssStyle )\r
+ html.push( ' style="', cssStyle, '"' );\r
+\r
+ html.push( '>', styleDefinition.name, '</', elementName, '>' );\r
+\r
+ return html.join( '' );\r
}\r
};\r
\r
stylesDef = styleDefinition.styles;\r
\r
// Builds the StyleText.\r
-\r
- var stylesText = ( styleDefinition.attributes && styleDefinition.attributes[ 'style' ] ) || '';\r
+ var stylesText = ( styleDefinition.attributes && styleDefinition.attributes[ 'style' ] ) || '',\r
+ specialStylesText = '';\r
\r
if ( stylesText.length )\r
stylesText = stylesText.replace( semicolonFixRegex, ';' );\r
\r
for ( var style in stylesDef )\r
- stylesText += ( style + ':' + stylesDef[ style ] ).replace( semicolonFixRegex, ';' );\r
+ {\r
+ var styleVal = stylesDef[ style ],\r
+ text = ( style + ':' + styleVal ).replace( semicolonFixRegex, ';' );\r
+\r
+ // Some browsers don't support 'inherit' property value, leave them intact. (#5242)\r
+ if ( styleVal == 'inherit' )\r
+ specialStylesText += text;\r
+ else\r
+ stylesText += text;\r
+ }\r
\r
// Browsers make some changes to the style when applying them. So, here\r
// we normalize it to the browser format.\r
if ( stylesText.length )\r
stylesText = normalizeCssText( stylesText );\r
\r
+ stylesText += specialStylesText;\r
+\r
// Return it, saving it to the next request.\r
return ( styleDefinition._ST = stylesText );\r
};\r
\r
// Get the first node to be processed and the last, which concludes the\r
// processing.\r
- var boundaryNodes = range.getBoundaryNodes();\r
- var firstNode = boundaryNodes.startNode;\r
- var lastNode = boundaryNodes.endNode.getNextSourceNode( true );\r
-\r
- // Probably the document end is reached, we need a marker node.\r
- if ( !lastNode )\r
- {\r
- var marker;\r
- lastNode = marker = document.createText( '' );\r
- lastNode.insertAfter( range.endContainer );\r
- }\r
- // The detection algorithm below skips the contents inside bookmark nodes, so\r
- // we'll need to make sure lastNode isn't the inside a bookmark node.\r
- var lastParent = lastNode.getParent();\r
- if ( lastParent && lastParent.getAttribute( '_fck_bookmark' ) )\r
- lastNode = lastParent;\r
-\r
- if ( lastNode.equals( firstNode ) )\r
- {\r
- // If the last node is the same as the the first one, we must move\r
- // it to the next one, otherwise the first one will not be\r
- // processed.\r
- lastNode = lastNode.getNextSourceNode( true );\r
-\r
- // It may happen that there are no more nodes after it (the end of\r
- // the document), so we must add something there to make our code\r
- // simpler.\r
- if ( !lastNode )\r
- {\r
- lastNode = marker = document.createText( '' );\r
- lastNode.insertAfter( firstNode );\r
- }\r
- }\r
+ var boundaryNodes = range.createBookmark(),\r
+ firstNode = boundaryNodes.startNode,\r
+ lastNode = boundaryNodes.endNode;\r
\r
var currentNode = firstNode;\r
\r
var styleRange;\r
\r
- // Indicates that that some useful inline content has been found, so\r
- // the style should be applied.\r
- var hasContents;\r
-\r
while ( currentNode )\r
{\r
var applyStyle = false;\r
if ( !includedNode.$.nextSibling )\r
applyStyle = true;\r
\r
- if ( !hasContents )\r
- hasContents = ( nodeType != CKEDITOR.NODE_TEXT || (/[^\s\ufeff]/).test( currentNode.getText() ) );\r
}\r
}\r
else\r
}\r
\r
// Apply the style if we have something to which apply it.\r
- if ( applyStyle && hasContents && styleRange && !styleRange.collapsed )\r
+ if ( applyStyle && styleRange && !styleRange.collapsed )\r
{\r
// Build the style element, based on the style object definition.\r
var styleNode = getElement( this, document );\r
styleRange.insertNode( styleNode );\r
\r
// Let's merge our new style with its neighbors, if possible.\r
- mergeSiblings( styleNode );\r
+ styleNode.mergeSiblings();\r
\r
// As the style system breaks text nodes constantly, let's normalize\r
// things for performance.\r
}\r
}\r
\r
- // Remove the temporary marking node.(#4111)\r
- marker && marker.remove();\r
+ firstNode.remove();\r
+ lastNode.remove();\r
range.moveToBookmark( bookmark );\r
+ // Minimize the result range to exclude empty text nodes. (#5374)\r
+ range.shrink( CKEDITOR.SHRINK_TEXT );\r
}\r
\r
function removeInlineStyle( range )\r
* no difference that they're separate entities in the DOM tree. So, merge\r
* them before removal.\r
*/\r
- mergeSiblings( element );\r
+ element.mergeSiblings();\r
removeFromElement( this, element );\r
\r
}\r
range.moveToBookmark( bookmark );\r
}\r
\r
+ function applyObjectStyle( range )\r
+ {\r
+ var root = range.getCommonAncestor( true, true ),\r
+ element = root.getAscendant( this.element, true );\r
+ element && setupElement( element, this );\r
+ }\r
+\r
function applyBlockStyle( range )\r
{\r
// Serializible bookmarks is needed here since\r
var iterator = range.createIterator();\r
iterator.enforceRealBlocks = true;\r
\r
+ // make recognize <br /> tag as a separator in ENTER_BR mode (#5121)\r
+ if ( this._.enterMode )\r
+ iterator.enlargeBr = ( this._.enterMode != CKEDITOR.ENTER_BR );\r
+\r
var block;\r
var doc = range.document;\r
var previousPreBlock;\r
} );\r
\r
var pres = [];\r
- splitedHtml.replace( /<pre>([\s\S]*?)<\/pre>/gi, function( match, preContent ){\r
+ splitedHtml.replace( /<pre\b.*?>([\s\S]*?)<\/pre>/gi, function( match, preContent ){\r
pres.push( preContent );\r
} );\r
return pres;\r
function removeFromElement( style, element )\r
{\r
var def = style._.definition,\r
- attributes = def.attributes,\r
+ attributes = CKEDITOR.tools.extend( {}, def.attributes, getOverrides( style )[ element.getName() ] ),\r
styles = def.styles,\r
- overrides = getOverrides( style );\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
- function removeAttrs()\r
+ // Remove definition attributes/style from the elemnt.\r
+ for ( var attName in attributes )\r
{\r
- for ( var attName in attributes )\r
- {\r
- // The 'class' element value must match (#1318).\r
- if ( attName == 'class' && element.getAttribute( attName ) != attributes[ attName ] )\r
- continue;\r
- element.removeAttribute( attName );\r
- }\r
+ // The 'class' element value must match (#1318).\r
+ if ( ( attName == 'class' || style._.definition.fullMatch )\r
+ && element.getAttribute( attName ) != normalizeProperty( attName, attributes[ attName ] ) )\r
+ continue;\r
+ removeEmpty = element.hasAttribute( attName );\r
+ element.removeAttribute( attName );\r
}\r
\r
- // Remove definition attributes/style from the elemnt.\r
- removeAttrs();\r
for ( var styleName in styles )\r
+ {\r
+ // Full match style insist on having fully equivalence. (#5018)\r
+ if ( style._.definition.fullMatch\r
+ && element.getStyle( styleName ) != normalizeProperty( styleName, styles[ styleName ], true ) )\r
+ continue;\r
+\r
+ removeEmpty = removeEmpty || !!element.getStyle( styleName );\r
element.removeStyle( styleName );\r
+ }\r
\r
- // Now remove override styles on the element.\r
- attributes = overrides[ element.getName() ];\r
- if ( attributes )\r
- removeAttrs();\r
- removeNoAttribsElement( element );\r
+ removeEmpty && removeNoAttribsElement( element );\r
}\r
\r
// Removes a style from inside an element.\r
if ( firstChild )\r
{\r
// Check the cached nodes for merging.\r
- mergeSiblings( firstChild );\r
-\r
- if ( lastChild && !firstChild.equals( lastChild ) )\r
- mergeSiblings( lastChild );\r
- }\r
- }\r
- }\r
-\r
- function mergeSiblings( element )\r
- {\r
- if ( !element || element.type != CKEDITOR.NODE_ELEMENT || !CKEDITOR.dtd.$removeEmpty[ element.getName() ] )\r
- return;\r
-\r
- mergeElements( element, element.getNext(), true );\r
- mergeElements( element, element.getPrevious() );\r
- }\r
-\r
- function mergeElements( element, sibling, isNext )\r
- {\r
- if ( sibling && sibling.type == CKEDITOR.NODE_ELEMENT )\r
- {\r
- var hasBookmark = sibling.getAttribute( '_fck_bookmark' );\r
-\r
- if ( hasBookmark )\r
- sibling = isNext ? sibling.getNext() : sibling.getPrevious();\r
-\r
- if ( sibling && sibling.type == CKEDITOR.NODE_ELEMENT && element.isIdentical( sibling ) )\r
- {\r
- // Save the last child to be checked too, to merge things like\r
- // <b><i></i></b><b><i></i></b> => <b><i></i></b>\r
- var innerSibling = isNext ? element.getLast() : element.getFirst();\r
+ firstChild.type == CKEDITOR.NODE_ELEMENT && firstChild.mergeSiblings();\r
\r
- if ( hasBookmark )\r
- ( isNext ? sibling.getPrevious() : sibling.getNext() ).move( element, !isNext );\r
-\r
- sibling.moveChildren( element, !isNext );\r
- sibling.remove();\r
-\r
- // Now check the last inner child (see two comments above).\r
- if ( innerSibling )\r
- mergeSiblings( innerSibling );\r
+ if ( lastChild && !firstChild.equals( lastChild )\r
+ && lastChild.type == CKEDITOR.NODE_ELEMENT )\r
+ lastChild.mergeSiblings();\r
}\r
}\r
}\r
return overrides;\r
}\r
\r
+ function normalizeProperty( name, value, isStyle )\r
+ {\r
+ var temp = new CKEDITOR.dom.element( 'span' );\r
+ temp [ isStyle ? 'setStyle' : 'setAttribute' ]( name, value );\r
+ return temp[ isStyle ? 'getStyle' : 'getAttribute' ]( name );\r
+ }\r
+\r
function normalizeCssText( unparsedCssText, nativeNormalize )\r
{\r
var styleText;\r
.toLowerCase();\r
}\r
\r
+ // Turn inline style text properties into one hash.\r
+ function parseStyleText( styleText )\r
+ {\r
+ var retval = {};\r
+ styleText\r
+ .replace( /"/g, '"' )\r
+ .replace( /\s*([^ :;]+)\s*:\s*([^;]+)\s*(?=;|$)/g, function( match, name, value )\r
+ {\r
+ retval[ name ] = value;\r
+ } );\r
+ return retval;\r
+ }\r
+\r
+ function compareCssText( source, target )\r
+ {\r
+ typeof source == 'string' && ( source = parseStyleText( source ) );\r
+ typeof target == 'string' && ( target = parseStyleText( target ) );\r
+ for( var name in source )\r
+ {\r
+ // Value 'inherit' is treated as a wildcard,\r
+ // which will match any value.\r
+ if ( !( name in target &&\r
+ ( target[ name ] == source[ name ]\r
+ || source[ name ] == 'inherit'\r
+ || target[ name ] == 'inherit' ) ) )\r
+ {\r
+ return false;\r
+ }\r
+ }\r
+ return true;\r
+ }\r
+\r
function applyStyle( document, remove )\r
{\r
// Get all ranges from the selection.\r
CKEDITOR.stylesSet.addExternal( name, url, '' );\r
CKEDITOR.stylesSet.load( name, callback );\r
};\r
+\r
+\r
+/**\r
+ * Gets the current styleSet for this instance\r
+ * @param {Function} The function to be called with the styles data.\r
+ * @example\r
+ * editor.getStylesSet( function( stylesDefinitions ) {} );\r
+ */\r
+CKEDITOR.editor.prototype.getStylesSet = function( callback )\r
+{\r
+ if ( !this._.stylesDefinitions )\r
+ {\r
+ var editor = this,\r
+ // Respect the backwards compatible definition entry\r
+ configStyleSet = editor.config.stylesCombo_stylesSet || editor.config.stylesSet || 'default';\r
+\r
+ // #5352 Allow to define the styles directly in the config object\r
+ if ( configStyleSet instanceof Array )\r
+ {\r
+ editor._.stylesDefinitions = configStyleSet;\r
+ callback( configStyleSet );\r
+ return;\r
+ }\r
+\r
+ var partsStylesSet = configStyleSet.split( ':' ),\r
+ styleSetName = partsStylesSet[ 0 ],\r
+ externalPath = partsStylesSet[ 1 ],\r
+ pluginPath = CKEDITOR.plugins.registered.styles.path;\r
+\r
+ CKEDITOR.stylesSet.addExternal( styleSetName,\r
+ externalPath ?\r
+ partsStylesSet.slice( 1 ).join( ':' ) :\r
+ pluginPath + 'styles/' + styleSetName + '.js', '' );\r
+\r
+ CKEDITOR.stylesSet.load( styleSetName, function( stylesSet )\r
+ {\r
+ editor._.stylesDefinitions = stylesSet[ styleSetName ];\r
+ callback( editor._.stylesDefinitions );\r
+ } ) ;\r
+ }\r
+ else\r
+ callback( this._.stylesDefinitions );\r
+};\r
+\r
+/**\r
+ * The "styles definition set" to use in the editor. They will be used in the\r
+ * styles combo and the Style selector of the div container. <br>\r
+ * The styles may be defined in the page containing the editor, or can be\r
+ * loaded on demand from an external file. In the second case, if this setting\r
+ * contains only a name, the styles definition file will be loaded from the\r
+ * "styles" folder inside the styles plugin folder.\r
+ * Otherwise, this setting has the "name:url" syntax, making it\r
+ * possible to set the URL from which loading the styles file.<br>\r
+ * Previously this setting was available as config.stylesCombo_stylesSet<br>\r
+ * @name CKEDITOR.config.stylesSet\r
+ * @type String|Array\r
+ * @default 'default'\r
+ * @since 3.3\r
+ * @example\r
+ * // Load from the styles' styles folder (mystyles.js file).\r
+ * config.stylesSet = 'mystyles';\r
+ * @example\r
+ * // Load from a relative URL.\r
+ * config.stylesSet = 'mystyles:/editorstyles/styles.js';\r
+ * @example\r
+ * // Load from a full URL.\r
+ * config.stylesSet = 'mystyles:http://www.example.com/editorstyles/styles.js';\r
+ * @example\r
+ * // Load from a list of definitions.\r
+ * config.stylesSet = [\r
+ * { name : 'Strong Emphasis', element : 'strong' },\r
+ * { name : 'Emphasis', element : 'em' }, ... ];\r
+ */\r