X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fplugins%2Fstyles%2Fplugin.js;h=eade43b36e2ce5532d35b403e8c77e9d495a615e;hp=37126f13c841384805a96f5ac43c0159bd931d30;hb=9afde8772159bd3436f1f5b7862960307710ae5a;hpb=614511639979907ceb0da3614122a4d8eb963ad4 diff --git a/_source/plugins/styles/plugin.js b/_source/plugins/styles/plugin.js index 37126f1..eade43b 100644 --- a/_source/plugins/styles/plugin.js +++ b/_source/plugins/styles/plugin.js @@ -5,7 +5,17 @@ For licensing, see LICENSE.html or http://ckeditor.com/license CKEDITOR.plugins.add( 'styles', { - requires : [ 'selection' ] + requires : [ 'selection' ], + init : function( editor ) + { + // This doesn't look like correct, but it's the safest way to proper + // pass the disableReadonlyStyling configuration to the style system + // without having to change any method signature in the API. (#6103) + editor.on( 'contentDom', function() + { + editor.document.setCustomData( 'cke_includeReadonly', !editor.config.disableReadonlyStyling ); + }); + } }); /** @@ -353,6 +363,35 @@ CKEDITOR.STYLE_OBJECT = 3; return ( styleDefinition._ST = stylesText ); }; + // Gets the parent element which blocks the styling for an element. This + // can be done through read-only elements (contenteditable=false) or + // elements with the "data-cke-nostyle" attribute. + function getUnstylableParent( element ) + { + var unstylable, + editable; + + while ( ( element = element.getParent() ) ) + { + if ( element.getName() == 'body' ) + break; + + if ( element.getAttribute( 'data-cke-nostyle' ) ) + unstylable = element; + else if ( !editable ) + { + var contentEditable = element.getAttribute( 'contentEditable' ); + + if ( contentEditable == 'false' ) + unstylable = element; + else if ( contentEditable == 'true' ) + editable = 1; + } + } + + return unstylable; + } + function applyInlineStyle( range ) { var document = range.document; @@ -375,6 +414,14 @@ CKEDITOR.STYLE_OBJECT = 3; var def = this._.definition; var isUnknownElement; + // Indicates that fully selected read-only elements are to be included in the styling range. + var includeReadonly = def.includeReadonly; + + // If the read-only inclusion is not available in the definition, try + // to get it from the document data. + if ( includeReadonly == undefined ) + includeReadonly = document.getCustomData( 'cke_includeReadonly' ); + // Get the DTD definition for the element. Defaults to "span". var dtd = CKEDITOR.dtd[ elementName ] || ( isUnknownElement = true, CKEDITOR.dtd.span ); @@ -392,6 +439,24 @@ 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; + + // Do nothing if the current node now follows the last node to be processed. + if ( currentNode.getPosition( lastNode ) == CKEDITOR.POSITION_FOLLOWING ) + currentNode = 0; + while ( currentNode ) { var applyStyle = false; @@ -405,8 +470,10 @@ CKEDITOR.STYLE_OBJECT = 3; { var nodeType = currentNode.type; var nodeName = nodeType == CKEDITOR.NODE_ELEMENT ? currentNode.getName() : null; + var nodeIsReadonly = nodeName && ( currentNode.getAttribute( 'contentEditable' ) == 'false' ); + var nodeIsNoStyle = nodeName && currentNode.getAttribute( 'data-cke-nostyle' ); - if ( nodeName && currentNode.getAttribute( '_cke_bookmark' ) ) + if ( nodeName && currentNode.data( 'cke-bookmark' ) ) { currentNode = currentNode.getNextSourceNode( true ); continue; @@ -414,6 +481,8 @@ CKEDITOR.STYLE_OBJECT = 3; // Check if the current node can be a child of the style element. if ( !nodeName || ( dtd[ nodeName ] + && !nodeIsNoStyle + && ( !nodeIsReadonly || includeReadonly ) && ( 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 ) ) ) ) { @@ -435,9 +504,9 @@ CKEDITOR.STYLE_OBJECT = 3; styleRange.setStartBefore( currentNode ); } - // Non element nodes, or empty elements can be added - // completely to the range. - if ( nodeType == CKEDITOR.NODE_TEXT || ( nodeType == CKEDITOR.NODE_ELEMENT && !currentNode.getChildCount() ) ) + // Non element nodes, readonly elements, or empty + // elements can be added completely to the range. + if ( nodeType == CKEDITOR.NODE_TEXT || nodeIsReadonly || ( nodeType == CKEDITOR.NODE_ELEMENT && !currentNode.getChildCount() ) ) { var includedNode = currentNode; var parentNode; @@ -461,7 +530,6 @@ CKEDITOR.STYLE_OBJECT = 3; // in this style DTD, so apply the style immediately. if ( !includedNode.$.nextSibling ) applyStyle = true; - } } else @@ -471,7 +539,7 @@ CKEDITOR.STYLE_OBJECT = 3; applyStyle = true; // Get the next node to be processed. - currentNode = currentNode.getNextSourceNode(); + currentNode = currentNode.getNextSourceNode( nodeIsNoStyle || nodeIsReadonly ); } // Apply the style if we have something to which apply it. @@ -883,7 +951,7 @@ CKEDITOR.STYLE_OBJECT = 3; { // Exclude the ones at header OR at tail, // and ignore bookmark content between them. - var duoBrRegex = /(\S\s*)\n(?:\s|(]+_cke_bookmark.*?\/span>))*\n(?!$)/gi, + var duoBrRegex = /(\S\s*)\n(?:\s|(]+data-cke-bookmark.*?\/span>))*\n(?!$)/gi, blockName = preBlock.getName(), splitedHtml = replace( preBlock.getOuterHtml(), duoBrRegex, @@ -905,7 +973,7 @@ CKEDITOR.STYLE_OBJECT = 3; var headBookmark = '', tailBookmark = ''; - str = str.replace( /(^]+_cke_bookmark.*?\/span>)|(]+_cke_bookmark.*?\/span>$)/gi, + str = str.replace( /(^]+data-cke-bookmark.*?\/span>)|(]+data-cke-bookmark.*?\/span>$)/gi, function( str, m1, m2 ){ m1 && ( headBookmark = m1 ); m2 && ( tailBookmark = m2 ); @@ -1355,7 +1423,7 @@ CKEDITOR.STYLE_OBJECT = 3; var selection = document.getSelection(), // Bookmark the range so we can re-select it after processing. bookmarks = selection.createBookmarks( 1 ), - ranges = selection.getRanges( 1 ), + ranges = selection.getRanges(), func = remove ? this.removeFromRange : this.applyToRange, range; @@ -1449,6 +1517,23 @@ CKEDITOR.editor.prototype.getStylesSet = function( callback ) }; /** + * Indicates that fully selected read-only elements will be included when + * applying the style (for inline styles only). + * @name CKEDITOR.style.includeReadonly + * @type Boolean + * @default false + * @since 3.5 + */ + + /** + * Disables inline styling on read-only elements. + * @name CKEDITOR.config.disableReadonlyStyling + * @type Boolean + * @default false + * @since 3.5 + */ + +/** * The "styles definition set" to use in the editor. They will be used in the * styles combo and the Style selector of the div container.
* The styles may be defined in the page containing the editor, or can be