\r
CKEDITOR.plugins.add( 'styles',\r
{\r
- requires : [ 'selection' ]\r
+ requires : [ 'selection' ],\r
+ init : function( editor )\r
+ {\r
+ // This doesn't look like correct, but it's the safest way to proper\r
+ // pass the disableReadonlyStyling configuration to the style system\r
+ // without having to change any method signature in the API. (#6103)\r
+ editor.on( 'contentDom', function()\r
+ {\r
+ editor.document.setCustomData( 'cke_includeReadonly', !editor.config.disableReadonlyStyling );\r
+ });\r
+ }\r
});\r
\r
/**\r
return ( styleDefinition._ST = stylesText );\r
};\r
\r
+ // Gets the parent element which blocks the styling for an element. This\r
+ // can be done through read-only elements (contenteditable=false) or\r
+ // elements with the "data-cke-nostyle" attribute.\r
+ function getUnstylableParent( element )\r
+ {\r
+ var unstylable,\r
+ editable;\r
+\r
+ while ( ( element = element.getParent() ) )\r
+ {\r
+ if ( element.getName() == 'body' )\r
+ break;\r
+\r
+ if ( element.getAttribute( 'data-cke-nostyle' ) )\r
+ unstylable = element;\r
+ else if ( !editable )\r
+ {\r
+ var contentEditable = element.getAttribute( 'contentEditable' );\r
+\r
+ if ( contentEditable == 'false' )\r
+ unstylable = element;\r
+ else if ( contentEditable == 'true' )\r
+ editable = 1;\r
+ }\r
+ }\r
+\r
+ return unstylable;\r
+ }\r
+\r
function applyInlineStyle( range )\r
{\r
var document = range.document;\r
var def = this._.definition;\r
var isUnknownElement;\r
\r
+ // Indicates that fully selected read-only elements are to be included in the styling range.\r
+ var includeReadonly = def.includeReadonly;\r
+\r
+ // If the read-only inclusion is not available in the definition, try\r
+ // to get it from the document data.\r
+ if ( includeReadonly == undefined )\r
+ includeReadonly = document.getCustomData( 'cke_includeReadonly' );\r
+\r
// Get the DTD definition for the element. Defaults to "span".\r
var dtd = CKEDITOR.dtd[ elementName ] || ( isUnknownElement = true, CKEDITOR.dtd.span );\r
\r
\r
var styleRange;\r
\r
+ // Check if the boundaries are inside non stylable elements.\r
+ var firstUnstylable = getUnstylableParent( firstNode ),\r
+ lastUnstylable = getUnstylableParent( lastNode );\r
+\r
+ // If the first element can't be styled, we'll start processing right\r
+ // after its unstylable root.\r
+ if ( firstUnstylable )\r
+ currentNode = firstUnstylable.getNextSourceNode( true );\r
+\r
+ // If the last element can't be styled, we'll stop processing on its\r
+ // unstylable root.\r
+ if ( lastUnstylable )\r
+ lastNode = lastUnstylable;\r
+\r
+ // Do nothing if the current node now follows the last node to be processed.\r
+ if ( currentNode.getPosition( lastNode ) == CKEDITOR.POSITION_FOLLOWING )\r
+ currentNode = 0;\r
+\r
while ( currentNode )\r
{\r
var applyStyle = false;\r
{\r
var nodeType = currentNode.type;\r
var nodeName = nodeType == CKEDITOR.NODE_ELEMENT ? currentNode.getName() : null;\r
+ var nodeIsReadonly = nodeName && ( currentNode.getAttribute( 'contentEditable' ) == 'false' );\r
+ var nodeIsNoStyle = nodeName && currentNode.getAttribute( 'data-cke-nostyle' );\r
\r
- if ( nodeName && currentNode.getAttribute( '_cke_bookmark' ) )\r
+ if ( nodeName && currentNode.data( 'cke-bookmark' ) )\r
{\r
currentNode = currentNode.getNextSourceNode( true );\r
continue;\r
\r
// Check if the current node can be a child of the style element.\r
if ( !nodeName || ( dtd[ nodeName ]\r
+ && !nodeIsNoStyle\r
+ && ( !nodeIsReadonly || includeReadonly )\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
styleRange.setStartBefore( currentNode );\r
}\r
\r
- // Non element nodes, or empty elements can be added\r
- // completely to the range.\r
- if ( nodeType == CKEDITOR.NODE_TEXT || ( nodeType == CKEDITOR.NODE_ELEMENT && !currentNode.getChildCount() ) )\r
+ // Non element nodes, readonly elements, or empty\r
+ // elements can be added completely to the range.\r
+ if ( nodeType == CKEDITOR.NODE_TEXT || nodeIsReadonly || ( nodeType == CKEDITOR.NODE_ELEMENT && !currentNode.getChildCount() ) )\r
{\r
var includedNode = currentNode;\r
var parentNode;\r
// in this style DTD, so apply the style immediately.\r
if ( !includedNode.$.nextSibling )\r
applyStyle = true;\r
-\r
}\r
}\r
else\r
applyStyle = true;\r
\r
// Get the next node to be processed.\r
- currentNode = currentNode.getNextSourceNode();\r
+ currentNode = currentNode.getNextSourceNode( nodeIsNoStyle || nodeIsReadonly );\r
}\r
\r
// Apply the style if we have something to which apply it.\r
{\r
// Exclude the ones at header OR at tail,\r
// and ignore bookmark content between them.\r
- var duoBrRegex = /(\S\s*)\n(?:\s|(<span[^>]+_cke_bookmark.*?\/span>))*\n(?!$)/gi,\r
+ var duoBrRegex = /(\S\s*)\n(?:\s|(<span[^>]+data-cke-bookmark.*?\/span>))*\n(?!$)/gi,\r
blockName = preBlock.getName(),\r
splitedHtml = replace( preBlock.getOuterHtml(),\r
duoBrRegex,\r
var headBookmark = '',\r
tailBookmark = '';\r
\r
- str = str.replace( /(^<span[^>]+_cke_bookmark.*?\/span>)|(<span[^>]+_cke_bookmark.*?\/span>$)/gi,\r
+ str = str.replace( /(^<span[^>]+data-cke-bookmark.*?\/span>)|(<span[^>]+data-cke-bookmark.*?\/span>$)/gi,\r
function( str, m1, m2 ){\r
m1 && ( headBookmark = m1 );\r
m2 && ( tailBookmark = m2 );\r
var selection = document.getSelection(),\r
// Bookmark the range so we can re-select it after processing.\r
bookmarks = selection.createBookmarks( 1 ),\r
- ranges = selection.getRanges( 1 ),\r
+ ranges = selection.getRanges(),\r
func = remove ? this.removeFromRange : this.applyToRange,\r
range;\r
\r
};\r
\r
/**\r
+ * Indicates that fully selected read-only elements will be included when\r
+ * applying the style (for inline styles only).\r
+ * @name CKEDITOR.style.includeReadonly\r
+ * @type Boolean\r
+ * @default false\r
+ * @since 3.5\r
+ */\r
+\r
+ /**\r
+ * Disables inline styling on read-only elements.\r
+ * @name CKEDITOR.config.disableReadonlyStyling\r
+ * @type Boolean\r
+ * @default false\r
+ * @since 3.5\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