2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
6 CKEDITOR.plugins.add( 'styles',
\r
8 requires : [ 'selection' ],
\r
9 init : function( editor )
\r
11 // This doesn't look like correct, but it's the safest way to proper
\r
12 // pass the disableReadonlyStyling configuration to the style system
\r
13 // without having to change any method signature in the API. (#6103)
\r
14 editor.on( 'contentDom', function()
\r
16 editor.document.setCustomData( 'cke_includeReadonly', !editor.config.disableReadonlyStyling );
\r
22 * Registers a function to be called whenever a style changes its state in the
\r
23 * editing area. The current state is passed to the function. The possible
\r
24 * states are {@link CKEDITOR.TRISTATE_ON} and {@link CKEDITOR.TRISTATE_OFF}.
\r
25 * @param {CKEDITOR.style} style The style to be watched.
\r
26 * @param {Function} callback The function to be called when the style state changes.
\r
28 * // Create a style object for the <b> element.
\r
29 * var style = new CKEDITOR.style( { element : 'b' } );
\r
30 * var editor = CKEDITOR.instances.editor1;
\r
31 * editor.attachStyleStateChange( style, function( state )
\r
33 * if ( state == CKEDITOR.TRISTATE_ON )
\r
34 * alert( 'The current state for the B element is ON' );
\r
36 * alert( 'The current state for the B element is OFF' );
\r
39 CKEDITOR.editor.prototype.attachStyleStateChange = function( style, callback )
\r
41 // Try to get the list of attached callbacks.
\r
42 var styleStateChangeCallbacks = this._.styleStateChangeCallbacks;
\r
44 // If it doesn't exist, it means this is the first call. So, let's create
\r
45 // all the structure to manage the style checks and the callback calls.
\r
46 if ( !styleStateChangeCallbacks )
\r
48 // Create the callbacks array.
\r
49 styleStateChangeCallbacks = this._.styleStateChangeCallbacks = [];
\r
51 // Attach to the selectionChange event, so we can check the styles at
\r
53 this.on( 'selectionChange', function( ev )
\r
55 // Loop throw all registered callbacks.
\r
56 for ( var i = 0 ; i < styleStateChangeCallbacks.length ; i++ )
\r
58 var callback = styleStateChangeCallbacks[ i ];
\r
60 // Check the current state for the style defined for that
\r
62 var currentState = callback.style.checkActive( ev.data.path ) ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF;
\r
64 // If the state changed since the last check.
\r
65 if ( callback.state !== currentState )
\r
67 // Call the callback function, passing the current
\r
69 callback.fn.call( this, currentState );
\r
71 // Save the current state, so it can be compared next
\r
73 callback.state = currentState;
\r
79 // Save the callback info, so it can be checked on the next occurrence of
\r
81 styleStateChangeCallbacks.push( { style : style, fn : callback } );
\r
84 CKEDITOR.STYLE_BLOCK = 1;
\r
85 CKEDITOR.STYLE_INLINE = 2;
\r
86 CKEDITOR.STYLE_OBJECT = 3;
\r
90 var blockElements = { address:1,div:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1,p:1,pre:1 };
\r
91 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
93 var semicolonFixRegex = /\s*(?:;\s*|$)/;
\r
95 var notBookmark = CKEDITOR.dom.walker.bookmark( 0, 1 );
\r
97 CKEDITOR.style = function( styleDefinition, variablesValues )
\r
99 if ( variablesValues )
\r
101 styleDefinition = CKEDITOR.tools.clone( styleDefinition );
\r
103 replaceVariables( styleDefinition.attributes, variablesValues );
\r
104 replaceVariables( styleDefinition.styles, variablesValues );
\r
107 var element = this.element = ( styleDefinition.element || '*' ).toLowerCase();
\r
110 ( element == '#' || blockElements[ element ] ) ?
\r
111 CKEDITOR.STYLE_BLOCK
\r
112 : objectElements[ element ] ?
\r
113 CKEDITOR.STYLE_OBJECT
\r
115 CKEDITOR.STYLE_INLINE;
\r
119 definition : styleDefinition
\r
123 CKEDITOR.style.prototype =
\r
125 apply : function( document )
\r
127 applyStyle.call( this, document, false );
\r
130 remove : function( document )
\r
132 applyStyle.call( this, document, true );
\r
135 applyToRange : function( range )
\r
137 return ( this.applyToRange =
\r
138 this.type == CKEDITOR.STYLE_INLINE ?
\r
140 : this.type == CKEDITOR.STYLE_BLOCK ?
\r
142 : this.type == CKEDITOR.STYLE_OBJECT ?
\r
144 : null ).call( this, range );
\r
147 removeFromRange : function( range )
\r
149 return ( this.removeFromRange =
\r
150 this.type == CKEDITOR.STYLE_INLINE ?
\r
152 : this.type == CKEDITOR.STYLE_BLOCK ?
\r
154 : this.type == CKEDITOR.STYLE_OBJECT ?
\r
156 : null ).call( this, range );
\r
159 applyToObject : function( element )
\r
161 setupElement( element, this );
\r
165 * Get the style state inside an element path. Returns "true" if the
\r
166 * element is active in the path.
\r
168 checkActive : function( elementPath )
\r
170 switch ( this.type )
\r
172 case CKEDITOR.STYLE_BLOCK :
\r
173 return this.checkElementRemovable( elementPath.block || elementPath.blockLimit, true );
\r
175 case CKEDITOR.STYLE_OBJECT :
\r
176 case CKEDITOR.STYLE_INLINE :
\r
178 var elements = elementPath.elements;
\r
180 for ( var i = 0, element ; i < elements.length ; i++ )
\r
182 element = elements[ i ];
\r
184 if ( this.type == CKEDITOR.STYLE_INLINE
\r
185 && ( element == elementPath.block || element == elementPath.blockLimit ) )
\r
188 if( this.type == CKEDITOR.STYLE_OBJECT
\r
189 && !( element.getName() in objectElements ) )
\r
192 if ( this.checkElementRemovable( element, true ) )
\r
200 * Whether this style can be applied at the element path.
\r
201 * @param elementPath
\r
203 checkApplicable : function( elementPath )
\r
205 switch ( this.type )
\r
207 case CKEDITOR.STYLE_INLINE :
\r
208 case CKEDITOR.STYLE_BLOCK :
\r
211 case CKEDITOR.STYLE_OBJECT :
\r
212 return elementPath.lastElement.getAscendant( this.element, true );
\r
218 // Checks if an element, or any of its attributes, is removable by the
\r
219 // current style definition.
\r
220 checkElementRemovable : function( element, fullMatch )
\r
225 var def = this._.definition,
\r
228 // If the element name is the same as the style name.
\r
229 if ( element.getName() == this.element )
\r
231 // If no attributes are defined in the element.
\r
232 if ( !fullMatch && !element.hasAttributes() )
\r
235 attribs = getAttributesForComparison( def );
\r
237 if ( attribs._length )
\r
239 for ( var attName in attribs )
\r
241 if ( attName == '_length' )
\r
244 var elementAttr = element.getAttribute( attName ) || '';
\r
246 // Special treatment for 'style' attribute is required.
\r
247 if ( attName == 'style' ?
\r
248 compareCssText( attribs[ attName ], normalizeCssText( elementAttr, false ) )
\r
249 : attribs[ attName ] == elementAttr )
\r
254 else if ( fullMatch )
\r
264 // Check if the element can be somehow overriden.
\r
265 var override = getOverrides( this )[ element.getName() ] ;
\r
268 // If no attributes have been defined, remove the element.
\r
269 if ( !( attribs = override.attributes ) )
\r
272 for ( var i = 0 ; i < attribs.length ; i++ )
\r
274 attName = attribs[i][0];
\r
275 var actualAttrValue = element.getAttribute( attName );
\r
276 if ( actualAttrValue )
\r
278 var attValue = attribs[i][1];
\r
280 // Remove the attribute if:
\r
281 // - The override definition value is null;
\r
282 // - The override definition value is a string that
\r
283 // matches the attribute value exactly.
\r
284 // - The override definition value is a regex that
\r
285 // has matches in the attribute value.
\r
286 if ( attValue === null ||
\r
287 ( typeof attValue == 'string' && actualAttrValue == attValue ) ||
\r
288 attValue.test( actualAttrValue ) )
\r
296 // Builds the preview HTML based on the styles definition.
\r
297 buildPreview : function()
\r
299 var styleDefinition = this._.definition,
\r
301 elementName = styleDefinition.element;
\r
303 // Avoid <bdo> in the preview.
\r
304 if ( elementName == 'bdo' )
\r
305 elementName = 'span';
\r
307 html = [ '<', elementName ];
\r
309 // Assign all defined attributes.
\r
310 var attribs = styleDefinition.attributes;
\r
313 for ( var att in attribs )
\r
315 html.push( ' ', att, '="', attribs[ att ], '"' );
\r
319 // Assign the style attribute.
\r
320 var cssStyle = CKEDITOR.style.getStyleText( styleDefinition );
\r
322 html.push( ' style="', cssStyle, '"' );
\r
324 html.push( '>', styleDefinition.name, '</', elementName, '>' );
\r
326 return html.join( '' );
\r
330 // Build the cssText based on the styles definition.
\r
331 CKEDITOR.style.getStyleText = function( styleDefinition )
\r
333 // If we have already computed it, just return it.
\r
334 var stylesDef = styleDefinition._ST;
\r
338 stylesDef = styleDefinition.styles;
\r
340 // Builds the StyleText.
\r
341 var stylesText = ( styleDefinition.attributes && styleDefinition.attributes[ 'style' ] ) || '',
\r
342 specialStylesText = '';
\r
344 if ( stylesText.length )
\r
345 stylesText = stylesText.replace( semicolonFixRegex, ';' );
\r
347 for ( var style in stylesDef )
\r
349 var styleVal = stylesDef[ style ],
\r
350 text = ( style + ':' + styleVal ).replace( semicolonFixRegex, ';' );
\r
352 // Some browsers don't support 'inherit' property value, leave them intact. (#5242)
\r
353 if ( styleVal == 'inherit' )
\r
354 specialStylesText += text;
\r
356 stylesText += text;
\r
359 // Browsers make some changes to the style when applying them. So, here
\r
360 // we normalize it to the browser format.
\r
361 if ( stylesText.length )
\r
362 stylesText = normalizeCssText( stylesText );
\r
364 stylesText += specialStylesText;
\r
366 // Return it, saving it to the next request.
\r
367 return ( styleDefinition._ST = stylesText );
\r
370 // Gets the parent element which blocks the styling for an element. This
\r
371 // can be done through read-only elements (contenteditable=false) or
\r
372 // elements with the "data-nostyle" attribute.
\r
373 function getUnstylableParent( element )
\r
378 while ( ( element = element.getParent() ) )
\r
380 if ( element.getName() == 'body' )
\r
383 if ( element.getAttribute( 'data-nostyle' ) )
\r
384 unstylable = element;
\r
385 else if ( !editable )
\r
387 var contentEditable = element.getAttribute( 'contentEditable' );
\r
389 if ( contentEditable == 'false' )
\r
390 unstylable = element;
\r
391 else if ( contentEditable == 'true' )
\r
399 function applyInlineStyle( range )
\r
401 var document = range.document;
\r
403 if ( range.collapsed )
\r
405 // Create the element to be inserted in the DOM.
\r
406 var collapsedElement = getElement( this, document );
\r
408 // Insert the empty element into the DOM at the range position.
\r
409 range.insertNode( collapsedElement );
\r
411 // Place the selection right inside the empty element.
\r
412 range.moveToPosition( collapsedElement, CKEDITOR.POSITION_BEFORE_END );
\r
417 var elementName = this.element;
\r
418 var def = this._.definition;
\r
419 var isUnknownElement;
\r
421 // Indicates that fully selected read-only elements are to be included in the styling range.
\r
422 var includeReadonly = def.includeReadonly;
\r
424 // If the read-only inclusion is not available in the definition, try
\r
425 // to get it from the document data.
\r
426 if ( includeReadonly == undefined )
\r
427 includeReadonly = document.getCustomData( 'cke_includeReadonly' );
\r
429 // Get the DTD definition for the element. Defaults to "span".
\r
430 var dtd = CKEDITOR.dtd[ elementName ] || ( isUnknownElement = true, CKEDITOR.dtd.span );
\r
432 // Expand the range.
\r
433 range.enlarge( CKEDITOR.ENLARGE_ELEMENT, 1 );
\r
436 // Get the first node to be processed and the last, which concludes the
\r
438 var boundaryNodes = range.createBookmark(),
\r
439 firstNode = boundaryNodes.startNode,
\r
440 lastNode = boundaryNodes.endNode;
\r
442 var currentNode = firstNode;
\r
446 // Check if the boundaries are inside non stylable elements.
\r
447 var firstUnstylable = getUnstylableParent( firstNode ),
\r
448 lastUnstylable = getUnstylableParent( lastNode );
\r
450 // If the first element can't be styled, we'll start processing right
\r
451 // after its unstylable root.
\r
452 if ( firstUnstylable )
\r
453 currentNode = firstUnstylable.getNextSourceNode( true );
\r
455 // If the last element can't be styled, we'll stop processing on its
\r
456 // unstylable root.
\r
457 if ( lastUnstylable )
\r
458 lastNode = lastUnstylable;
\r
460 // Do nothing if the current node now follows the last node to be processed.
\r
461 if ( currentNode.getPosition( lastNode ) == CKEDITOR.POSITION_FOLLOWING )
\r
464 while ( currentNode )
\r
466 var applyStyle = false;
\r
468 if ( currentNode.equals( lastNode ) )
\r
470 currentNode = null;
\r
475 var nodeType = currentNode.type;
\r
476 var nodeName = nodeType == CKEDITOR.NODE_ELEMENT ? currentNode.getName() : null;
\r
477 var nodeIsReadonly = nodeName && ( currentNode.getAttribute( 'contentEditable' ) == 'false' );
\r
478 var nodeIsNoStyle = nodeName && currentNode.getAttribute( 'data-nostyle' );
\r
480 if ( nodeName && currentNode.data( 'cke-bookmark' ) )
\r
482 currentNode = currentNode.getNextSourceNode( true );
\r
486 // Check if the current node can be a child of the style element.
\r
487 if ( !nodeName || ( dtd[ nodeName ]
\r
489 && ( !nodeIsReadonly || includeReadonly )
\r
490 && ( currentNode.getPosition( lastNode ) | CKEDITOR.POSITION_PRECEDING | CKEDITOR.POSITION_IDENTICAL | CKEDITOR.POSITION_IS_CONTAINED ) == ( CKEDITOR.POSITION_PRECEDING + CKEDITOR.POSITION_IDENTICAL + CKEDITOR.POSITION_IS_CONTAINED )
\r
491 && ( !def.childRule || def.childRule( currentNode ) ) ) )
\r
493 var currentParent = currentNode.getParent();
\r
495 // Check if the style element can be a child of the current
\r
496 // node parent or if the element is not defined in the DTD.
\r
498 && ( ( currentParent.getDtd() || CKEDITOR.dtd.span )[ elementName ] || isUnknownElement )
\r
499 && ( !def.parentRule || def.parentRule( currentParent ) ) )
\r
501 // This node will be part of our range, so if it has not
\r
502 // been started, place its start right before the node.
\r
503 // In the case of an element node, it will be included
\r
504 // only if it is entirely inside the range.
\r
505 if ( !styleRange && ( !nodeName || !CKEDITOR.dtd.$removeEmpty[ nodeName ] || ( currentNode.getPosition( lastNode ) | CKEDITOR.POSITION_PRECEDING | CKEDITOR.POSITION_IDENTICAL | CKEDITOR.POSITION_IS_CONTAINED ) == ( CKEDITOR.POSITION_PRECEDING + CKEDITOR.POSITION_IDENTICAL + CKEDITOR.POSITION_IS_CONTAINED ) ) )
\r
507 styleRange = new CKEDITOR.dom.range( document );
\r
508 styleRange.setStartBefore( currentNode );
\r
511 // Non element nodes, readonly elements, or empty
\r
512 // elements can be added completely to the range.
\r
513 if ( nodeType == CKEDITOR.NODE_TEXT || nodeIsReadonly || ( nodeType == CKEDITOR.NODE_ELEMENT && !currentNode.getChildCount() ) )
\r
515 var includedNode = currentNode;
\r
518 // This node is about to be included completelly, but,
\r
519 // if this is the last node in its parent, we must also
\r
520 // check if the parent itself can be added completelly
\r
521 // to the range, otherwise apply the style immediately.
\r
522 while ( ( applyStyle = !includedNode.getNext( notBookmark ) )
\r
523 && ( parentNode = includedNode.getParent(), dtd[ parentNode.getName() ] )
\r
524 && ( parentNode.getPosition( firstNode ) | CKEDITOR.POSITION_FOLLOWING | CKEDITOR.POSITION_IDENTICAL | CKEDITOR.POSITION_IS_CONTAINED ) == ( CKEDITOR.POSITION_FOLLOWING + CKEDITOR.POSITION_IDENTICAL + CKEDITOR.POSITION_IS_CONTAINED )
\r
525 && ( !def.childRule || def.childRule( parentNode ) ) )
\r
527 includedNode = parentNode;
\r
530 styleRange.setEndAfter( includedNode );
\r
540 // Get the next node to be processed.
\r
541 currentNode = currentNode.getNextSourceNode( nodeIsNoStyle || nodeIsReadonly );
\r
544 // Apply the style if we have something to which apply it.
\r
545 if ( applyStyle && styleRange && !styleRange.collapsed )
\r
547 // Build the style element, based on the style object definition.
\r
548 var styleNode = getElement( this, document ),
\r
549 styleHasAttrs = styleNode.hasAttributes();
\r
551 // Get the element that holds the entire range.
\r
552 var parent = styleRange.getCommonAncestor();
\r
557 // Styles cannot be removed.
\r
558 blockedStyles : {},
\r
559 // Attrs cannot be removed.
\r
563 var attName, styleName, value;
\r
565 // Loop through the parents, removing the redundant attributes
\r
566 // from the element to be applied.
\r
567 while ( styleNode && parent )
\r
569 if ( parent.getName() == elementName )
\r
571 for ( attName in def.attributes )
\r
573 if ( removeList.blockedAttrs[ attName ] || !( value = parent.getAttribute( styleName ) ) )
\r
576 if ( styleNode.getAttribute( attName ) == value )
\r
577 removeList.attrs[ attName ] = 1;
\r
579 removeList.blockedAttrs[ attName ] = 1;
\r
582 for ( styleName in def.styles )
\r
584 if ( removeList.blockedStyles[ styleName ] || !( value = parent.getStyle( styleName ) ) )
\r
587 if ( styleNode.getStyle( styleName ) == value )
\r
588 removeList.styles[ styleName ] = 1;
\r
590 removeList.blockedStyles[ styleName ] = 1;
\r
594 parent = parent.getParent();
\r
597 for ( attName in removeList.attrs )
\r
598 styleNode.removeAttribute( attName );
\r
600 for ( styleName in removeList.styles )
\r
601 styleNode.removeStyle( styleName );
\r
603 if ( styleHasAttrs && !styleNode.hasAttributes() )
\r
608 // Move the contents of the range to the style element.
\r
609 styleRange.extractContents().appendTo( styleNode );
\r
611 // Here we do some cleanup, removing all duplicated
\r
612 // elements from the style element.
\r
613 removeFromInsideElement( this, styleNode );
\r
615 // Insert it into the range position (it is collapsed after
\r
616 // extractContents.
\r
617 styleRange.insertNode( styleNode );
\r
619 // Let's merge our new style with its neighbors, if possible.
\r
620 styleNode.mergeSiblings();
\r
622 // As the style system breaks text nodes constantly, let's normalize
\r
623 // things for performance.
\r
624 // With IE, some paragraphs get broken when calling normalize()
\r
625 // repeatedly. Also, for IE, we must normalize body, not documentElement.
\r
626 // IE is also known for having a "crash effect" with normalize().
\r
627 // We should try to normalize with IE too in some way, somewhere.
\r
628 if ( !CKEDITOR.env.ie )
\r
629 styleNode.$.normalize();
\r
631 // Style already inherit from parents, left just to clear up any internal overrides. (#5931)
\r
634 styleNode = new CKEDITOR.dom.element( 'span' );
\r
635 styleRange.extractContents().appendTo( styleNode );
\r
636 styleRange.insertNode( styleNode );
\r
637 removeFromInsideElement( this, styleNode );
\r
638 styleNode.remove( true );
\r
641 // Style applied, let's release the range, so it gets
\r
642 // re-initialization in the next loop.
\r
647 // Remove the bookmark nodes.
\r
648 range.moveToBookmark( boundaryNodes );
\r
650 // Minimize the result range to exclude empty text nodes. (#5374)
\r
651 range.shrink( CKEDITOR.SHRINK_TEXT );
\r
654 function removeInlineStyle( range )
\r
657 * Make sure our range has included all "collpased" parent inline nodes so
\r
658 * that our operation logic can be simpler.
\r
660 range.enlarge( CKEDITOR.ENLARGE_ELEMENT, 1 );
\r
662 var bookmark = range.createBookmark(),
\r
663 startNode = bookmark.startNode;
\r
665 if ( range.collapsed )
\r
668 var startPath = new CKEDITOR.dom.elementPath( startNode.getParent() ),
\r
669 // The topmost element in elementspatch which we should jump out of.
\r
673 for ( var i = 0, element ; i < startPath.elements.length
\r
674 && ( element = startPath.elements[i] ) ; i++ )
\r
677 * 1. If it's collaped inside text nodes, try to remove the style from the whole element.
\r
679 * 2. Otherwise if it's collapsed on element boundaries, moving the selection
\r
680 * outside the styles instead of removing the whole tag,
\r
681 * also make sure other inner styles were well preserverd.(#3309)
\r
683 if ( element == startPath.block || element == startPath.blockLimit )
\r
686 if ( this.checkElementRemovable( element ) )
\r
690 if ( range.collapsed && (
\r
691 range.checkBoundaryOfElement( element, CKEDITOR.END ) ||
\r
692 ( isStart = range.checkBoundaryOfElement( element, CKEDITOR.START ) ) ) )
\r
694 boundaryElement = element;
\r
695 boundaryElement.match = isStart ? 'start' : 'end';
\r
700 * Before removing the style node, there may be a sibling to the style node
\r
701 * that's exactly the same to the one to be removed. To the user, it makes
\r
702 * no difference that they're separate entities in the DOM tree. So, merge
\r
703 * them before removal.
\r
705 element.mergeSiblings();
\r
706 removeFromElement( this, element );
\r
712 // Re-create the style tree after/before the boundary element,
\r
713 // the replication start from bookmark start node to define the
\r
715 if ( boundaryElement )
\r
717 var clonedElement = startNode;
\r
718 for ( i = 0 ;; i++ )
\r
720 var newElement = startPath.elements[ i ];
\r
721 if ( newElement.equals( boundaryElement ) )
\r
723 // Avoid copying any matched element.
\r
724 else if ( newElement.match )
\r
727 newElement = newElement.clone();
\r
728 newElement.append( clonedElement );
\r
729 clonedElement = newElement;
\r
731 clonedElement[ boundaryElement.match == 'start' ?
\r
732 'insertBefore' : 'insertAfter' ]( boundaryElement );
\r
738 * Now our range isn't collapsed. Lets walk from the start node to the end
\r
739 * node via DFS and remove the styles one-by-one.
\r
741 var endNode = bookmark.endNode,
\r
745 * Find out the style ancestor that needs to be broken down at startNode
\r
748 function breakNodes()
\r
750 var startPath = new CKEDITOR.dom.elementPath( startNode.getParent() ),
\r
751 endPath = new CKEDITOR.dom.elementPath( endNode.getParent() ),
\r
754 for ( var i = 0 ; i < startPath.elements.length ; i++ )
\r
756 var element = startPath.elements[ i ];
\r
758 if ( element == startPath.block || element == startPath.blockLimit )
\r
761 if ( me.checkElementRemovable( element ) )
\r
762 breakStart = element;
\r
764 for ( i = 0 ; i < endPath.elements.length ; i++ )
\r
766 element = endPath.elements[ i ];
\r
768 if ( element == endPath.block || element == endPath.blockLimit )
\r
771 if ( me.checkElementRemovable( element ) )
\r
772 breakEnd = element;
\r
776 endNode.breakParent( breakEnd );
\r
778 startNode.breakParent( breakStart );
\r
782 // Now, do the DFS walk.
\r
783 var currentNode = startNode.getNext();
\r
784 while ( !currentNode.equals( endNode ) )
\r
787 * Need to get the next node first because removeFromElement() can remove
\r
788 * the current node from DOM tree.
\r
790 var nextNode = currentNode.getNextSourceNode();
\r
791 if ( currentNode.type == CKEDITOR.NODE_ELEMENT && this.checkElementRemovable( currentNode ) )
\r
793 // Remove style from element or overriding element.
\r
794 if ( currentNode.getName() == this.element )
\r
795 removeFromElement( this, currentNode );
\r
797 removeOverrides( currentNode, getOverrides( this )[ currentNode.getName() ] );
\r
800 * removeFromElement() may have merged the next node with something before
\r
801 * the startNode via mergeSiblings(). In that case, the nextNode would
\r
802 * contain startNode and we'll have to call breakNodes() again and also
\r
803 * reassign the nextNode to something after startNode.
\r
805 if ( nextNode.type == CKEDITOR.NODE_ELEMENT && nextNode.contains( startNode ) )
\r
808 nextNode = startNode.getNext();
\r
811 currentNode = nextNode;
\r
815 range.moveToBookmark( bookmark );
\r
818 function applyObjectStyle( range )
\r
820 var root = range.getCommonAncestor( true, true ),
\r
821 element = root.getAscendant( this.element, true );
\r
822 element && setupElement( element, this );
\r
825 function removeObjectStyle( range )
\r
827 var root = range.getCommonAncestor( true, true ),
\r
828 element = root.getAscendant( this.element, true );
\r
834 var def = style._.definition;
\r
835 var attributes = def.attributes;
\r
836 var styles = CKEDITOR.style.getStyleText( def );
\r
838 // Remove all defined attributes.
\r
841 for ( var att in attributes )
\r
843 element.removeAttribute( att, attributes[ att ] );
\r
847 // Assign all defined styles.
\r
850 for ( var i in def.styles )
\r
852 if ( !def.styles.hasOwnProperty( i ) )
\r
855 element.removeStyle( i );
\r
860 function applyBlockStyle( range )
\r
862 // Serializible bookmarks is needed here since
\r
863 // elements may be merged.
\r
864 var bookmark = range.createBookmark( true );
\r
866 var iterator = range.createIterator();
\r
867 iterator.enforceRealBlocks = true;
\r
869 // make recognize <br /> tag as a separator in ENTER_BR mode (#5121)
\r
870 if ( this._.enterMode )
\r
871 iterator.enlargeBr = ( this._.enterMode != CKEDITOR.ENTER_BR );
\r
874 var doc = range.document;
\r
875 var previousPreBlock;
\r
877 while ( ( block = iterator.getNextParagraph() ) ) // Only one =
\r
879 var newBlock = getElement( this, doc, block );
\r
880 replaceBlock( block, newBlock );
\r
883 range.moveToBookmark( bookmark );
\r
886 function removeBlockStyle( range )
\r
888 // Serializible bookmarks is needed here since
\r
889 // elements may be merged.
\r
890 var bookmark = range.createBookmark( 1 );
\r
892 var iterator = range.createIterator();
\r
893 iterator.enforceRealBlocks = true;
\r
894 iterator.enlargeBr = this._.enterMode != CKEDITOR.ENTER_BR;
\r
897 while ( ( block = iterator.getNextParagraph() ) )
\r
899 if ( this.checkElementRemovable( block ) )
\r
901 // <pre> get special treatment.
\r
902 if ( block.is( 'pre' ) )
\r
904 var newBlock = this._.enterMode == CKEDITOR.ENTER_BR ?
\r
905 null : range.document.createElement(
\r
906 this._.enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' );
\r
908 newBlock && block.copyAttributes( newBlock );
\r
909 replaceBlock( block, newBlock );
\r
912 removeFromElement( this, block, 1 );
\r
916 range.moveToBookmark( bookmark );
\r
919 // Replace the original block with new one, with special treatment
\r
920 // for <pre> blocks to make sure content format is well preserved, and merging/splitting adjacent
\r
921 // when necessary.(#3188)
\r
922 function replaceBlock( block, newBlock )
\r
924 // Block is to be removed, create a temp element to
\r
926 var removeBlock = !newBlock;
\r
929 newBlock = block.getDocument().createElement( 'div' );
\r
930 block.copyAttributes( newBlock );
\r
933 var newBlockIsPre = newBlock && newBlock.is( 'pre' );
\r
934 var blockIsPre = block.is( 'pre' );
\r
936 var isToPre = newBlockIsPre && !blockIsPre;
\r
937 var isFromPre = !newBlockIsPre && blockIsPre;
\r
940 newBlock = toPre( block, newBlock );
\r
941 else if ( isFromPre )
\r
942 // Split big <pre> into pieces before start to convert.
\r
943 newBlock = fromPres( removeBlock ?
\r
944 [ block.getHtml() ] : splitIntoPres( block ), newBlock );
\r
946 block.moveChildren( newBlock );
\r
948 newBlock.replace( block );
\r
950 if ( newBlockIsPre )
\r
952 // Merge previous <pre> blocks.
\r
953 mergePre( newBlock );
\r
955 else if ( removeBlock )
\r
956 removeNoAttribsElement( newBlock );
\r
959 var nonWhitespaces = CKEDITOR.dom.walker.whitespaces( 1 );
\r
961 * Merge a <pre> block with a previous sibling if available.
\r
963 function mergePre( preBlock )
\r
966 if ( !( ( previousBlock = preBlock.getPrevious( nonWhitespaces ) )
\r
967 && previousBlock.is
\r
968 && previousBlock.is( 'pre') ) )
\r
971 // Merge the previous <pre> block contents into the current <pre>
\r
974 // Another thing to be careful here is that currentBlock might contain
\r
975 // a '\n' at the beginning, and previousBlock might contain a '\n'
\r
976 // towards the end. These new lines are not normally displayed but they
\r
977 // become visible after merging.
\r
978 var mergedHtml = replace( previousBlock.getHtml(), /\n$/, '' ) + '\n\n' +
\r
979 replace( preBlock.getHtml(), /^\n/, '' ) ;
\r
981 // Krugle: IE normalizes innerHTML from <pre>, breaking whitespaces.
\r
982 if ( CKEDITOR.env.ie )
\r
983 preBlock.$.outerHTML = '<pre>' + mergedHtml + '</pre>';
\r
985 preBlock.setHtml( mergedHtml );
\r
987 previousBlock.remove();
\r
991 * Split into multiple <pre> blocks separated by double line-break.
\r
994 function splitIntoPres( preBlock )
\r
996 // Exclude the ones at header OR at tail,
\r
997 // and ignore bookmark content between them.
\r
998 var duoBrRegex = /(\S\s*)\n(?:\s|(<span[^>]+data-cke-bookmark.*?\/span>))*\n(?!$)/gi,
\r
999 blockName = preBlock.getName(),
\r
1000 splitedHtml = replace( preBlock.getOuterHtml(),
\r
1002 function( match, charBefore, bookmark )
\r
1004 return charBefore + '</pre>' + bookmark + '<pre>';
\r
1008 splitedHtml.replace( /<pre\b.*?>([\s\S]*?)<\/pre>/gi, function( match, preContent ){
\r
1009 pres.push( preContent );
\r
1014 // Wrapper function of String::replace without considering of head/tail bookmarks nodes.
\r
1015 function replace( str, regexp, replacement )
\r
1017 var headBookmark = '',
\r
1018 tailBookmark = '';
\r
1020 str = str.replace( /(^<span[^>]+data-cke-bookmark.*?\/span>)|(<span[^>]+data-cke-bookmark.*?\/span>$)/gi,
\r
1021 function( str, m1, m2 ){
\r
1022 m1 && ( headBookmark = m1 );
\r
1023 m2 && ( tailBookmark = m2 );
\r
1026 return headBookmark + str.replace( regexp, replacement ) + tailBookmark;
\r
1029 * Converting a list of <pre> into blocks with format well preserved.
\r
1031 function fromPres( preHtmls, newBlock )
\r
1034 if ( preHtmls.length > 1 )
\r
1035 docFrag = new CKEDITOR.dom.documentFragment( newBlock.getDocument() );
\r
1037 for ( var i = 0 ; i < preHtmls.length ; i++ )
\r
1039 var blockHtml = preHtmls[ i ];
\r
1041 // 1. Trim the first and last line-breaks immediately after and before <pre>,
\r
1042 // they're not visible.
\r
1043 blockHtml = blockHtml.replace( /(\r\n|\r)/g, '\n' ) ;
\r
1044 blockHtml = replace( blockHtml, /^[ \t]*\n/, '' ) ;
\r
1045 blockHtml = replace( blockHtml, /\n$/, '' ) ;
\r
1046 // 2. Convert spaces or tabs at the beginning or at the end to
\r
1047 blockHtml = replace( blockHtml, /^[ \t]+|[ \t]+$/g, function( match, offset, s )
\r
1049 if ( match.length == 1 ) // one space, preserve it
\r
1051 else if ( !offset ) // beginning of block
\r
1052 return CKEDITOR.tools.repeat( ' ', match.length - 1 ) + ' ';
\r
1053 else // end of block
\r
1054 return ' ' + CKEDITOR.tools.repeat( ' ', match.length - 1 );
\r
1057 // 3. Convert \n to <BR>.
\r
1058 // 4. Convert contiguous (i.e. non-singular) spaces or tabs to
\r
1059 blockHtml = blockHtml.replace( /\n/g, '<br>' ) ;
\r
1060 blockHtml = blockHtml.replace( /[ \t]{2,}/g,
\r
1061 function ( match )
\r
1063 return CKEDITOR.tools.repeat( ' ', match.length - 1 ) + ' ' ;
\r
1068 var newBlockClone = newBlock.clone();
\r
1069 newBlockClone.setHtml( blockHtml );
\r
1070 docFrag.append( newBlockClone );
\r
1073 newBlock.setHtml( blockHtml );
\r
1076 return docFrag || newBlock;
\r
1080 * Converting from a non-PRE block to a PRE block in formatting operations.
\r
1082 function toPre( block, newBlock )
\r
1084 var bogus = block.getBogus();
\r
1085 bogus && bogus.remove();
\r
1087 // First trim the block content.
\r
1088 var preHtml = block.getHtml();
\r
1090 // 1. Trim head/tail spaces, they're not visible.
\r
1091 preHtml = replace( preHtml, /(?:^[ \t\n\r]+)|(?:[ \t\n\r]+$)/g, '' );
\r
1092 // 2. Delete ANSI whitespaces immediately before and after <BR> because
\r
1093 // they are not visible.
\r
1094 preHtml = preHtml.replace( /[ \t\r\n]*(<br[^>]*>)[ \t\r\n]*/gi, '$1' );
\r
1095 // 3. Compress other ANSI whitespaces since they're only visible as one
\r
1096 // single space previously.
\r
1097 // 4. Convert to spaces since is no longer needed in <PRE>.
\r
1098 preHtml = preHtml.replace( /([ \t\n\r]+| )/g, ' ' );
\r
1099 // 5. Convert any <BR /> to \n. This must not be done earlier because
\r
1100 // the \n would then get compressed.
\r
1101 preHtml = preHtml.replace( /<br\b[^>]*>/gi, '\n' );
\r
1103 // Krugle: IE normalizes innerHTML to <pre>, breaking whitespaces.
\r
1104 if ( CKEDITOR.env.ie )
\r
1106 var temp = block.getDocument().createElement( 'div' );
\r
1107 temp.append( newBlock );
\r
1108 newBlock.$.outerHTML = '<pre>' + preHtml + '</pre>';
\r
1109 newBlock.copyAttributes( temp.getFirst() );
\r
1110 newBlock = temp.getFirst().remove();
\r
1113 newBlock.setHtml( preHtml );
\r
1118 // Removes a style from an element itself, don't care about its subtree.
\r
1119 function removeFromElement( style, element )
\r
1121 var def = style._.definition,
\r
1122 attributes = CKEDITOR.tools.extend( {}, def.attributes, getOverrides( style )[ element.getName() ] ),
\r
1123 styles = def.styles,
\r
1124 // If the style is only about the element itself, we have to remove the element.
\r
1125 removeEmpty = CKEDITOR.tools.isEmpty( attributes ) && CKEDITOR.tools.isEmpty( styles );
\r
1127 // Remove definition attributes/style from the elemnt.
\r
1128 for ( var attName in attributes )
\r
1130 // The 'class' element value must match (#1318).
\r
1131 if ( ( attName == 'class' || style._.definition.fullMatch )
\r
1132 && element.getAttribute( attName ) != normalizeProperty( attName, attributes[ attName ] ) )
\r
1134 removeEmpty = element.hasAttribute( attName );
\r
1135 element.removeAttribute( attName );
\r
1138 for ( var styleName in styles )
\r
1140 // Full match style insist on having fully equivalence. (#5018)
\r
1141 if ( style._.definition.fullMatch
\r
1142 && element.getStyle( styleName ) != normalizeProperty( styleName, styles[ styleName ], true ) )
\r
1145 removeEmpty = removeEmpty || !!element.getStyle( styleName );
\r
1146 element.removeStyle( styleName );
\r
1149 if ( removeEmpty )
\r
1151 !CKEDITOR.dtd.$block[ element.getName() ] || style._.enterMode == CKEDITOR.ENTER_BR && !element.hasAttributes() ?
\r
1152 removeNoAttribsElement( element ) :
\r
1153 element.renameNode( style._.enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' );
\r
1157 // Removes a style from inside an element.
\r
1158 function removeFromInsideElement( style, element )
\r
1160 var def = style._.definition,
\r
1161 attribs = def.attributes,
\r
1162 styles = def.styles,
\r
1163 overrides = getOverrides( style );
\r
1165 var innerElements = element.getElementsByTag( style.element );
\r
1167 for ( var i = innerElements.count(); --i >= 0 ; )
\r
1168 removeFromElement( style, innerElements.getItem( i ) );
\r
1170 // Now remove any other element with different name that is
\r
1171 // defined to be overriden.
\r
1172 for ( var overrideElement in overrides )
\r
1174 if ( overrideElement != style.element )
\r
1176 innerElements = element.getElementsByTag( overrideElement ) ;
\r
1177 for ( i = innerElements.count() - 1 ; i >= 0 ; i-- )
\r
1179 var innerElement = innerElements.getItem( i );
\r
1180 removeOverrides( innerElement, overrides[ overrideElement ] ) ;
\r
1188 * Remove overriding styles/attributes from the specific element.
\r
1189 * Note: Remove the element if no attributes remain.
\r
1190 * @param {Object} element
\r
1191 * @param {Object} overrides
\r
1193 function removeOverrides( element, overrides )
\r
1195 var attributes = overrides && overrides.attributes ;
\r
1199 for ( var i = 0 ; i < attributes.length ; i++ )
\r
1201 var attName = attributes[i][0], actualAttrValue ;
\r
1203 if ( ( actualAttrValue = element.getAttribute( attName ) ) )
\r
1205 var attValue = attributes[i][1] ;
\r
1207 // Remove the attribute if:
\r
1208 // - The override definition value is null ;
\r
1209 // - The override definition valie is a string that
\r
1210 // matches the attribute value exactly.
\r
1211 // - The override definition value is a regex that
\r
1212 // has matches in the attribute value.
\r
1213 if ( attValue === null ||
\r
1214 ( attValue.test && attValue.test( actualAttrValue ) ) ||
\r
1215 ( typeof attValue == 'string' && actualAttrValue == attValue ) )
\r
1216 element.removeAttribute( attName ) ;
\r
1221 removeNoAttribsElement( element );
\r
1224 // If the element has no more attributes, remove it.
\r
1225 function removeNoAttribsElement( element )
\r
1227 // If no more attributes remained in the element, remove it,
\r
1228 // leaving its children.
\r
1229 if ( !element.hasAttributes() )
\r
1231 if ( CKEDITOR.dtd.$block[ element.getName() ] )
\r
1233 var previous = element.getPrevious( nonWhitespaces ),
\r
1234 next = element.getNext( nonWhitespaces );
\r
1236 if ( previous && ( previous.type == CKEDITOR.NODE_TEXT || !previous.isBlockBoundary( { br : 1 } ) ) )
\r
1237 element.append( 'br', 1 );
\r
1238 if ( next && ( next.type == CKEDITOR.NODE_TEXT || !next.isBlockBoundary( { br : 1 } ) ) )
\r
1239 element.append( 'br' );
\r
1241 element.remove( true );
\r
1245 // Removing elements may open points where merging is possible,
\r
1246 // so let's cache the first and last nodes for later checking.
\r
1247 var firstChild = element.getFirst();
\r
1248 var lastChild = element.getLast();
\r
1250 element.remove( true );
\r
1254 // Check the cached nodes for merging.
\r
1255 firstChild.type == CKEDITOR.NODE_ELEMENT && firstChild.mergeSiblings();
\r
1257 if ( lastChild && !firstChild.equals( lastChild )
\r
1258 && lastChild.type == CKEDITOR.NODE_ELEMENT )
\r
1259 lastChild.mergeSiblings();
\r
1266 function getElement( style, targetDocument, element )
\r
1270 var def = style._.definition;
\r
1272 var elementName = style.element;
\r
1274 // The "*" element name will always be a span for this function.
\r
1275 if ( elementName == '*' )
\r
1276 elementName = 'span';
\r
1278 // Create the element.
\r
1279 el = new CKEDITOR.dom.element( elementName, targetDocument );
\r
1281 // #6226: attributes should be copied before the new ones are applied
\r
1283 element.copyAttributes( el );
\r
1285 el = setupElement( el, style );
\r
1287 // Avoid ID duplication.
\r
1288 if ( targetDocument.getCustomData( 'doc_processing_style' ) && el.hasAttribute( 'id' ) )
\r
1289 el.removeAttribute( 'id' );
\r
1291 targetDocument.setCustomData( 'doc_processing_style', 1 );
\r
1296 function setupElement( el, style )
\r
1298 var def = style._.definition;
\r
1299 var attributes = def.attributes;
\r
1300 var styles = CKEDITOR.style.getStyleText( def );
\r
1302 // Assign all defined attributes.
\r
1305 for ( var att in attributes )
\r
1307 el.setAttribute( att, attributes[ att ] );
\r
1311 // Assign all defined styles.
\r
1313 el.setAttribute( 'style', styles );
\r
1318 var varRegex = /#\((.+?)\)/g;
\r
1319 function replaceVariables( list, variablesValues )
\r
1321 for ( var item in list )
\r
1323 list[ item ] = list[ item ].replace( varRegex, function( match, varName )
\r
1325 return variablesValues[ varName ];
\r
1331 // Returns an object that can be used for style matching comparison.
\r
1332 // Attributes names and values are all lowercased, and the styles get
\r
1333 // merged with the style attribute.
\r
1334 function getAttributesForComparison( styleDefinition )
\r
1336 // If we have already computed it, just return it.
\r
1337 var attribs = styleDefinition._AC;
\r
1345 // Loop through all defined attributes.
\r
1346 var styleAttribs = styleDefinition.attributes;
\r
1347 if ( styleAttribs )
\r
1349 for ( var styleAtt in styleAttribs )
\r
1352 attribs[ styleAtt ] = styleAttribs[ styleAtt ];
\r
1356 // Includes the style definitions.
\r
1357 var styleText = CKEDITOR.style.getStyleText( styleDefinition );
\r
1360 if ( !attribs[ 'style' ] )
\r
1362 attribs[ 'style' ] = styleText;
\r
1365 // Appends the "length" information to the object.
\r
1366 attribs._length = length;
\r
1368 // Return it, saving it to the next request.
\r
1369 return ( styleDefinition._AC = attribs );
\r
1373 * Get the the collection used to compare the elements and attributes,
\r
1374 * defined in this style overrides, with other element. All information in
\r
1375 * it is lowercased.
\r
1376 * @param {CKEDITOR.style} style
\r
1378 function getOverrides( style )
\r
1380 if ( style._.overrides )
\r
1381 return style._.overrides;
\r
1383 var overrides = ( style._.overrides = {} ),
\r
1384 definition = style._.definition.overrides;
\r
1388 // The override description can be a string, object or array.
\r
1389 // Internally, well handle arrays only, so transform it if needed.
\r
1390 if ( !CKEDITOR.tools.isArray( definition ) )
\r
1391 definition = [ definition ];
\r
1393 // Loop through all override definitions.
\r
1394 for ( var i = 0 ; i < definition.length ; i++ )
\r
1396 var override = definition[i];
\r
1401 // If can be a string with the element name.
\r
1402 if ( typeof override == 'string' )
\r
1403 elementName = override.toLowerCase();
\r
1407 elementName = override.element ? override.element.toLowerCase() : style.element;
\r
1408 attrs = override.attributes;
\r
1411 // We can have more than one override definition for the same
\r
1412 // element name, so we attempt to simply append information to
\r
1413 // it if it already exists.
\r
1414 overrideEl = overrides[ elementName ] || ( overrides[ elementName ] = {} );
\r
1418 // The returning attributes list is an array, because we
\r
1419 // could have different override definitions for the same
\r
1420 // attribute name.
\r
1421 var overrideAttrs = ( overrideEl.attributes = overrideEl.attributes || new Array() );
\r
1422 for ( var attName in attrs )
\r
1424 // Each item in the attributes array is also an array,
\r
1425 // where [0] is the attribute name and [1] is the
\r
1426 // override value.
\r
1427 overrideAttrs.push( [ attName.toLowerCase(), attrs[ attName ] ] );
\r
1436 // Make the comparison of attribute value easier by standardizing it.
\r
1437 function normalizeProperty( name, value, isStyle )
\r
1439 var temp = new CKEDITOR.dom.element( 'span' );
\r
1440 temp [ isStyle ? 'setStyle' : 'setAttribute' ]( name, value );
\r
1441 return temp[ isStyle ? 'getStyle' : 'getAttribute' ]( name );
\r
1444 // Make the comparison of style text easier by standardizing it.
\r
1445 function normalizeCssText( unparsedCssText, nativeNormalize )
\r
1448 if ( nativeNormalize !== false )
\r
1450 // Injects the style in a temporary span object, so the browser parses it,
\r
1451 // retrieving its final format.
\r
1452 var temp = new CKEDITOR.dom.element( 'span' );
\r
1453 temp.setAttribute( 'style', unparsedCssText );
\r
1454 styleText = temp.getAttribute( 'style' ) || '';
\r
1457 styleText = unparsedCssText;
\r
1459 // Shrinking white-spaces around colon and semi-colon (#4147).
\r
1460 // Compensate tail semi-colon.
\r
1461 return styleText.replace( /\s*([;:])\s*/, '$1' )
\r
1462 .replace( /([^\s;])$/, '$1;')
\r
1463 // Trimming spaces after comma(#4107),
\r
1464 // remove quotations(#6403),
\r
1465 // mostly for differences on "font-family".
\r
1466 .replace( /,\s+/g, ',' )
\r
1467 .replace( /\"/g,'' )
\r
1471 // Turn inline style text properties into one hash.
\r
1472 function parseStyleText( styleText )
\r
1476 .replace( /"/g, '"' )
\r
1477 .replace( /\s*([^ :;]+)\s*:\s*([^;]+)\s*(?=;|$)/g, function( match, name, value )
\r
1479 retval[ name ] = value;
\r
1485 * Compare two bunch of styles, with the speciality that value 'inherit'
\r
1486 * is treated as a wildcard which will match any value.
\r
1487 * @param {Object|String} source
\r
1488 * @param {Object|String} target
\r
1490 function compareCssText( source, target )
\r
1492 typeof source == 'string' && ( source = parseStyleText( source ) );
\r
1493 typeof target == 'string' && ( target = parseStyleText( target ) );
\r
1494 for( var name in source )
\r
1496 if ( !( name in target &&
\r
1497 ( target[ name ] == source[ name ]
\r
1498 || source[ name ] == 'inherit'
\r
1499 || target[ name ] == 'inherit' ) ) )
\r
1507 function applyStyle( document, remove )
\r
1509 var selection = document.getSelection(),
\r
1510 ranges = selection.getRanges(),
\r
1511 func = remove ? this.removeFromRange : this.applyToRange,
\r
1514 var iterator = ranges.createIterator();
\r
1515 while ( ( range = iterator.getNextRange() ) )
\r
1516 func.call( this, range );
\r
1518 selection.selectRanges( ranges );
\r
1520 document.removeCustomData( 'doc_processing_style' );
\r
1524 CKEDITOR.styleCommand = function( style )
\r
1526 this.style = style;
\r
1529 CKEDITOR.styleCommand.prototype.exec = function( editor )
\r
1533 var doc = editor.document;
\r
1537 if ( this.state == CKEDITOR.TRISTATE_OFF )
\r
1538 this.style.apply( doc );
\r
1539 else if ( this.state == CKEDITOR.TRISTATE_ON )
\r
1540 this.style.remove( doc );
\r
1546 CKEDITOR.stylesSet = new CKEDITOR.resourceManager( '', 'stylesSet' );
\r
1548 // Backward compatibility (#5025).
\r
1549 CKEDITOR.addStylesSet = CKEDITOR.tools.bind( CKEDITOR.stylesSet.add, CKEDITOR.stylesSet );
\r
1550 CKEDITOR.loadStylesSet = function( name, url, callback )
\r
1552 CKEDITOR.stylesSet.addExternal( name, url, '' );
\r
1553 CKEDITOR.stylesSet.load( name, callback );
\r
1558 * Gets the current styleSet for this instance
\r
1559 * @param {Function} callback The function to be called with the styles data.
\r
1561 * editor.getStylesSet( function( stylesDefinitions ) {} );
\r
1563 CKEDITOR.editor.prototype.getStylesSet = function( callback )
\r
1565 if ( !this._.stylesDefinitions )
\r
1567 var editor = this,
\r
1568 // Respect the backwards compatible definition entry
\r
1569 configStyleSet = editor.config.stylesCombo_stylesSet || editor.config.stylesSet || 'default';
\r
1571 // #5352 Allow to define the styles directly in the config object
\r
1572 if ( configStyleSet instanceof Array )
\r
1574 editor._.stylesDefinitions = configStyleSet;
\r
1575 callback( configStyleSet );
\r
1579 var partsStylesSet = configStyleSet.split( ':' ),
\r
1580 styleSetName = partsStylesSet[ 0 ],
\r
1581 externalPath = partsStylesSet[ 1 ],
\r
1582 pluginPath = CKEDITOR.plugins.registered.styles.path;
\r
1584 CKEDITOR.stylesSet.addExternal( styleSetName,
\r
1586 partsStylesSet.slice( 1 ).join( ':' ) :
\r
1587 pluginPath + 'styles/' + styleSetName + '.js', '' );
\r
1589 CKEDITOR.stylesSet.load( styleSetName, function( stylesSet )
\r
1591 editor._.stylesDefinitions = stylesSet[ styleSetName ];
\r
1592 callback( editor._.stylesDefinitions );
\r
1596 callback( this._.stylesDefinitions );
\r
1600 * Indicates that fully selected read-only elements will be included when
\r
1601 * applying the style (for inline styles only).
\r
1602 * @name CKEDITOR.style.includeReadonly
\r
1609 * Disables inline styling on read-only elements.
\r
1610 * @name CKEDITOR.config.disableReadonlyStyling
\r
1617 * The "styles definition set" to use in the editor. They will be used in the
\r
1618 * styles combo and the Style selector of the div container. <br>
\r
1619 * The styles may be defined in the page containing the editor, or can be
\r
1620 * loaded on demand from an external file. In the second case, if this setting
\r
1621 * contains only a name, the styles definition file will be loaded from the
\r
1622 * "styles" folder inside the styles plugin folder.
\r
1623 * Otherwise, this setting has the "name:url" syntax, making it
\r
1624 * possible to set the URL from which loading the styles file.<br>
\r
1625 * Previously this setting was available as config.stylesCombo_stylesSet<br>
\r
1626 * @name CKEDITOR.config.stylesSet
\r
1627 * @type String|Array
\r
1628 * @default 'default'
\r
1631 * // Load from the styles' styles folder (mystyles.js file).
\r
1632 * config.stylesSet = 'mystyles';
\r
1634 * // Load from a relative URL.
\r
1635 * config.stylesSet = 'mystyles:/editorstyles/styles.js';
\r
1637 * // Load from a full URL.
\r
1638 * config.stylesSet = 'mystyles:http://www.example.com/editorstyles/styles.js';
\r
1640 * // Load from a list of definitions.
\r
1641 * config.stylesSet = [
\r
1642 * { name : 'Strong Emphasis', element : 'strong' },
\r
1643 * { name : 'Emphasis', element : 'em' }, ... ];
\r