2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
6 CKEDITOR
.plugins
.add( 'styles',
8 requires
: [ 'selection' ],
9 init : function( editor
)
11 // This doesn't look like correct, but it's the safest way to proper
12 // pass the disableReadonlyStyling configuration to the style system
13 // without having to change any method signature in the API. (#6103)
14 editor
.on( 'contentDom', function()
16 editor
.document
.setCustomData( 'cke_includeReadonly', !editor
.config
.disableReadonlyStyling
);
22 * Registers a function to be called whenever the selection position changes in the
23 * editing area. The current state is passed to the function. The possible
24 * states are {@link CKEDITOR.TRISTATE_ON} and {@link CKEDITOR.TRISTATE_OFF}.
25 * @param {CKEDITOR.style} style The style to be watched.
26 * @param {Function} callback The function to be called.
28 * // Create a style object for the <b> element.
29 * var style = new CKEDITOR.style( { element : 'b' } );
30 * var editor = CKEDITOR.instances.editor1;
31 * editor.attachStyleStateChange( style, function( state )
33 * if ( state == CKEDITOR.TRISTATE_ON )
34 * alert( 'The current state for the B element is ON' );
36 * alert( 'The current state for the B element is OFF' );
39 CKEDITOR
.editor
.prototype.attachStyleStateChange = function( style
, callback
)
41 // Try to get the list of attached callbacks.
42 var styleStateChangeCallbacks
= this._
.styleStateChangeCallbacks
;
44 // If it doesn't exist, it means this is the first call. So, let's create
45 // all the structure to manage the style checks and the callback calls.
46 if ( !styleStateChangeCallbacks
)
48 // Create the callbacks array.
49 styleStateChangeCallbacks
= this._
.styleStateChangeCallbacks
= [];
51 // Attach to the selectionChange event, so we can check the styles at
53 this.on( 'selectionChange', function( ev
)
55 // Loop throw all registered callbacks.
56 for ( var i
= 0 ; i
< styleStateChangeCallbacks
.length
; i
++ )
58 var callback
= styleStateChangeCallbacks
[ i
];
60 // Check the current state for the style defined for that
62 var currentState
= callback
.style
.checkActive( ev
.data
.path
) ? CKEDITOR
.TRISTATE_ON
: CKEDITOR
.TRISTATE_OFF
;
64 // Call the callback function, passing the current
66 callback
.fn
.call( this, currentState
);
71 // Save the callback info, so it can be checked on the next occurrence of
73 styleStateChangeCallbacks
.push( { style
: style
, fn
: callback
} );
76 CKEDITOR
.STYLE_BLOCK
= 1;
77 CKEDITOR
.STYLE_INLINE
= 2;
78 CKEDITOR
.STYLE_OBJECT
= 3;
82 var blockElements
= { address
:1,div
:1,h1
:1,h2
:1,h3
:1,h4
:1,h5
:1,h6
:1,p
:1,pre
:1,section
:1,header
:1,footer
:1,nav
:1,article
:1,aside
:1,figure
:1,dialog
:1,hgroup
:1,time
:1,meter
:1,menu
:1,command
:1,keygen
:1,output
:1,progress
:1,details
:1,datagrid
:1,datalist
:1 },
83 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,audio
:1,video
:1 };
85 var semicolonFixRegex
= /\s*(?:;\s*|$)/,
86 varRegex
= /#\((.+?)\)/g;
88 var notBookmark
= CKEDITOR
.dom
.walker
.bookmark( 0, 1 ),
89 nonWhitespaces
= CKEDITOR
.dom
.walker
.whitespaces( 1 );
91 CKEDITOR
.style = function( styleDefinition
, variablesValues
)
93 if ( variablesValues
)
95 styleDefinition
= CKEDITOR
.tools
.clone( styleDefinition
);
97 replaceVariables( styleDefinition
.attributes
, variablesValues
);
98 replaceVariables( styleDefinition
.styles
, variablesValues
);
101 var element
= this.element
= styleDefinition
.element
?
102 ( typeof styleDefinition
.element
== 'string' ? styleDefinition
.element
.toLowerCase() : styleDefinition
.element
)
106 blockElements
[ element
] ?
108 : objectElements
[ element
] ?
109 CKEDITOR
.STYLE_OBJECT
111 CKEDITOR
.STYLE_INLINE
;
113 // If the 'element' property is an object with a set of possible element, it will be applied like an object style: only to existing elements
114 if ( typeof this.element
== 'object' )
115 this.type
= CKEDITOR
.STYLE_OBJECT
;
119 definition
: styleDefinition
123 CKEDITOR
.style
.prototype =
125 apply : function( document
)
127 applyStyle
.call( this, document
, false );
130 remove : function( document
)
132 applyStyle
.call( this, document
, true );
135 applyToRange : function( range
)
137 return ( this.applyToRange
=
138 this.type
== CKEDITOR
.STYLE_INLINE
?
140 : this.type
== CKEDITOR
.STYLE_BLOCK
?
142 : this.type
== CKEDITOR
.STYLE_OBJECT
?
144 : null ).call( this, range
);
147 removeFromRange : function( range
)
149 return ( this.removeFromRange
=
150 this.type
== CKEDITOR
.STYLE_INLINE
?
152 : this.type
== CKEDITOR
.STYLE_BLOCK
?
154 : this.type
== CKEDITOR
.STYLE_OBJECT
?
156 : null ).call( this, range
);
159 applyToObject : function( element
)
161 setupElement( element
, this );
165 * Get the style state inside an element path. Returns "true" if the
166 * element is active in the path.
168 checkActive : function( elementPath
)
172 case CKEDITOR
.STYLE_BLOCK
:
173 return this.checkElementRemovable( elementPath
.block
|| elementPath
.blockLimit
, true );
175 case CKEDITOR
.STYLE_OBJECT
:
176 case CKEDITOR
.STYLE_INLINE
:
178 var elements
= elementPath
.elements
;
180 for ( var i
= 0, element
; i
< elements
.length
; i
++ )
182 element
= elements
[ i
];
184 if ( this.type
== CKEDITOR
.STYLE_INLINE
185 && ( element
== elementPath
.block
|| element
== elementPath
.blockLimit
) )
188 if( this.type
== CKEDITOR
.STYLE_OBJECT
)
190 var name
= element
.getName();
191 if ( !( typeof this.element
== 'string' ? name
== this.element
: name
in this.element
) )
195 if ( this.checkElementRemovable( element
, true ) )
203 * Whether this style can be applied at the element path.
206 checkApplicable : function( elementPath
)
210 case CKEDITOR
.STYLE_INLINE
:
211 case CKEDITOR
.STYLE_BLOCK
:
214 case CKEDITOR
.STYLE_OBJECT
:
215 return elementPath
.lastElement
.getAscendant( this.element
, true );
221 // Checks if an element, or any of its attributes, is removable by the
222 // current style definition.
223 checkElementRemovable : function( element
, fullMatch
)
225 if ( !element
|| element
.isReadOnly() )
228 var def
= this._
.definition
,
230 name
= element
.getName();
232 // If the element name is the same as the style name.
233 if ( typeof this.element
== 'string' ? name
== this.element
: name
in this.element
)
235 // If no attributes are defined in the element.
236 if ( !fullMatch
&& !element
.hasAttributes() )
239 attribs
= getAttributesForComparison( def
);
241 if ( attribs
._length
)
243 for ( var attName
in attribs
)
245 if ( attName
== '_length' )
248 var elementAttr
= element
.getAttribute( attName
) || '';
250 // Special treatment for 'style' attribute is required.
251 if ( attName
== 'style' ?
252 compareCssText( attribs
[ attName
], normalizeCssText( elementAttr
, false ) )
253 : attribs
[ attName
] == elementAttr
)
258 else if ( fullMatch
)
268 // Check if the element can be somehow overriden.
269 var override
= getOverrides( this )[ element
.getName() ] ;
272 // If no attributes have been defined, remove the element.
273 if ( !( attribs
= override
.attributes
) )
276 for ( var i
= 0 ; i
< attribs
.length
; i
++ )
278 attName
= attribs
[i
][0];
279 var actualAttrValue
= element
.getAttribute( attName
);
280 if ( actualAttrValue
)
282 var attValue
= attribs
[i
][1];
284 // Remove the attribute if:
285 // - The override definition value is null;
286 // - The override definition value is a string that
287 // matches the attribute value exactly.
288 // - The override definition value is a regex that
289 // has matches in the attribute value.
290 if ( attValue
=== null ||
291 ( typeof attValue
== 'string' && actualAttrValue
== attValue
) ||
292 attValue
.test( actualAttrValue
) )
300 // Builds the preview HTML based on the styles definition.
301 buildPreview : function( label
)
303 var styleDefinition
= this._
.definition
,
305 elementName
= styleDefinition
.element
;
307 // Avoid <bdo> in the preview.
308 if ( elementName
== 'bdo' )
309 elementName
= 'span';
311 html
= [ '<', elementName
];
313 // Assign all defined attributes.
314 var attribs
= styleDefinition
.attributes
;
317 for ( var att
in attribs
)
319 html
.push( ' ', att
, '="', attribs
[ att
], '"' );
323 // Assign the style attribute.
324 var cssStyle
= CKEDITOR
.style
.getStyleText( styleDefinition
);
326 html
.push( ' style="', cssStyle
, '"' );
328 html
.push( '>', ( label
|| styleDefinition
.name
), '</', elementName
, '>' );
330 return html
.join( '' );
334 // Build the cssText based on the styles definition.
335 CKEDITOR
.style
.getStyleText = function( styleDefinition
)
337 // If we have already computed it, just return it.
338 var stylesDef
= styleDefinition
._ST
;
342 stylesDef
= styleDefinition
.styles
;
344 // Builds the StyleText.
345 var stylesText
= ( styleDefinition
.attributes
&& styleDefinition
.attributes
[ 'style' ] ) || '',
346 specialStylesText
= '';
348 if ( stylesText
.length
)
349 stylesText
= stylesText
.replace( semicolonFixRegex
, ';' );
351 for ( var style
in stylesDef
)
353 var styleVal
= stylesDef
[ style
],
354 text
= ( style
+ ':' + styleVal
).replace( semicolonFixRegex
, ';' );
356 // Some browsers don't support 'inherit' property value, leave them intact. (#5242)
357 if ( styleVal
== 'inherit' )
358 specialStylesText
+= text
;
363 // Browsers make some changes to the style when applying them. So, here
364 // we normalize it to the browser format.
365 if ( stylesText
.length
)
366 stylesText
= normalizeCssText( stylesText
);
368 stylesText
+= specialStylesText
;
370 // Return it, saving it to the next request.
371 return ( styleDefinition
._ST
= stylesText
);
374 // Gets the parent element which blocks the styling for an element. This
375 // can be done through read-only elements (contenteditable=false) or
376 // elements with the "data-nostyle" attribute.
377 function getUnstylableParent( element
)
382 while ( ( element
= element
.getParent() ) )
384 if ( element
.getName() == 'body' )
387 if ( element
.getAttribute( 'data-nostyle' ) )
388 unstylable
= element
;
389 else if ( !editable
)
391 var contentEditable
= element
.getAttribute( 'contentEditable' );
393 if ( contentEditable
== 'false' )
394 unstylable
= element
;
395 else if ( contentEditable
== 'true' )
403 function applyInlineStyle( range
)
405 var document
= range
.document
;
407 if ( range
.collapsed
)
409 // Create the element to be inserted in the DOM.
410 var collapsedElement
= getElement( this, document
);
412 // Insert the empty element into the DOM at the range position.
413 range
.insertNode( collapsedElement
);
415 // Place the selection right inside the empty element.
416 range
.moveToPosition( collapsedElement
, CKEDITOR
.POSITION_BEFORE_END
);
421 var elementName
= this.element
;
422 var def
= this._
.definition
;
423 var isUnknownElement
;
425 // Indicates that fully selected read-only elements are to be included in the styling range.
426 var includeReadonly
= def
.includeReadonly
;
428 // If the read-only inclusion is not available in the definition, try
429 // to get it from the document data.
430 if ( includeReadonly
== undefined )
431 includeReadonly
= document
.getCustomData( 'cke_includeReadonly' );
433 // Get the DTD definition for the element. Defaults to "span".
434 var dtd
= CKEDITOR
.dtd
[ elementName
] || ( isUnknownElement
= true, CKEDITOR
.dtd
.span
);
437 range
.enlarge( CKEDITOR
.ENLARGE_ELEMENT
, 1 );
440 // Get the first node to be processed and the last, which concludes the
442 var boundaryNodes
= range
.createBookmark(),
443 firstNode
= boundaryNodes
.startNode
,
444 lastNode
= boundaryNodes
.endNode
;
446 var currentNode
= firstNode
;
450 // Check if the boundaries are inside non stylable elements.
451 var firstUnstylable
= getUnstylableParent( firstNode
),
452 lastUnstylable
= getUnstylableParent( lastNode
);
454 // If the first element can't be styled, we'll start processing right
455 // after its unstylable root.
456 if ( firstUnstylable
)
457 currentNode
= firstUnstylable
.getNextSourceNode( true );
459 // If the last element can't be styled, we'll stop processing on its
461 if ( lastUnstylable
)
462 lastNode
= lastUnstylable
;
464 // Do nothing if the current node now follows the last node to be processed.
465 if ( currentNode
.getPosition( lastNode
) == CKEDITOR
.POSITION_FOLLOWING
)
468 while ( currentNode
)
470 var applyStyle
= false;
472 if ( currentNode
.equals( lastNode
) )
479 var nodeType
= currentNode
.type
;
480 var nodeName
= nodeType
== CKEDITOR
.NODE_ELEMENT
? currentNode
.getName() : null;
481 var nodeIsReadonly
= nodeName
&& ( currentNode
.getAttribute( 'contentEditable' ) == 'false' );
482 var nodeIsNoStyle
= nodeName
&& currentNode
.getAttribute( 'data-nostyle' );
484 if ( nodeName
&& currentNode
.data( 'cke-bookmark' ) )
486 currentNode
= currentNode
.getNextSourceNode( true );
490 // Check if the current node can be a child of the style element.
491 if ( !nodeName
|| ( dtd
[ nodeName
]
493 && ( !nodeIsReadonly
|| includeReadonly
)
494 && ( currentNode
.getPosition( lastNode
) | CKEDITOR
.POSITION_PRECEDING
| CKEDITOR
.POSITION_IDENTICAL
| CKEDITOR
.POSITION_IS_CONTAINED
) == ( CKEDITOR
.POSITION_PRECEDING
+ CKEDITOR
.POSITION_IDENTICAL
+ CKEDITOR
.POSITION_IS_CONTAINED
)
495 && ( !def
.childRule
|| def
.childRule( currentNode
) ) ) )
497 var currentParent
= currentNode
.getParent();
499 // Check if the style element can be a child of the current
500 // node parent or if the element is not defined in the DTD.
502 && ( ( currentParent
.getDtd() || CKEDITOR
.dtd
.span
)[ elementName
] || isUnknownElement
)
503 && ( !def
.parentRule
|| def
.parentRule( currentParent
) ) )
505 // This node will be part of our range, so if it has not
506 // been started, place its start right before the node.
507 // In the case of an element node, it will be included
508 // only if it is entirely inside the range.
509 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
) ) )
511 styleRange
= new CKEDITOR
.dom
.range( document
);
512 styleRange
.setStartBefore( currentNode
);
515 // Non element nodes, readonly elements, or empty
516 // elements can be added completely to the range.
517 if ( nodeType
== CKEDITOR
.NODE_TEXT
|| nodeIsReadonly
|| ( nodeType
== CKEDITOR
.NODE_ELEMENT
&& !currentNode
.getChildCount() ) )
519 var includedNode
= currentNode
;
522 // This node is about to be included completelly, but,
523 // if this is the last node in its parent, we must also
524 // check if the parent itself can be added completelly
525 // to the range, otherwise apply the style immediately.
526 while ( ( applyStyle
= !includedNode
.getNext( notBookmark
) )
527 && ( parentNode
= includedNode
.getParent(), dtd
[ parentNode
.getName() ] )
528 && ( parentNode
.getPosition( firstNode
) | CKEDITOR
.POSITION_FOLLOWING
| CKEDITOR
.POSITION_IDENTICAL
| CKEDITOR
.POSITION_IS_CONTAINED
) == ( CKEDITOR
.POSITION_FOLLOWING
+ CKEDITOR
.POSITION_IDENTICAL
+ CKEDITOR
.POSITION_IS_CONTAINED
)
529 && ( !def
.childRule
|| def
.childRule( parentNode
) ) )
531 includedNode
= parentNode
;
534 styleRange
.setEndAfter( includedNode
);
544 // Get the next node to be processed.
545 currentNode
= currentNode
.getNextSourceNode( nodeIsNoStyle
|| nodeIsReadonly
);
548 // Apply the style if we have something to which apply it.
549 if ( applyStyle
&& styleRange
&& !styleRange
.collapsed
)
551 // Build the style element, based on the style object definition.
552 var styleNode
= getElement( this, document
),
553 styleHasAttrs
= styleNode
.hasAttributes();
555 // Get the element that holds the entire range.
556 var parent
= styleRange
.getCommonAncestor();
561 // Styles cannot be removed.
563 // Attrs cannot be removed.
567 var attName
, styleName
, value
;
569 // Loop through the parents, removing the redundant attributes
570 // from the element to be applied.
571 while ( styleNode
&& parent
)
573 if ( parent
.getName() == elementName
)
575 for ( attName
in def
.attributes
)
577 if ( removeList
.blockedAttrs
[ attName
] || !( value
= parent
.getAttribute( styleName
) ) )
580 if ( styleNode
.getAttribute( attName
) == value
)
581 removeList
.attrs
[ attName
] = 1;
583 removeList
.blockedAttrs
[ attName
] = 1;
586 for ( styleName
in def
.styles
)
588 if ( removeList
.blockedStyles
[ styleName
] || !( value
= parent
.getStyle( styleName
) ) )
591 if ( styleNode
.getStyle( styleName
) == value
)
592 removeList
.styles
[ styleName
] = 1;
594 removeList
.blockedStyles
[ styleName
] = 1;
598 parent
= parent
.getParent();
601 for ( attName
in removeList
.attrs
)
602 styleNode
.removeAttribute( attName
);
604 for ( styleName
in removeList
.styles
)
605 styleNode
.removeStyle( styleName
);
607 if ( styleHasAttrs
&& !styleNode
.hasAttributes() )
612 // Move the contents of the range to the style element.
613 styleRange
.extractContents().appendTo( styleNode
);
615 // Here we do some cleanup, removing all duplicated
616 // elements from the style element.
617 removeFromInsideElement( this, styleNode
);
619 // Insert it into the range position (it is collapsed after
621 styleRange
.insertNode( styleNode
);
623 // Let's merge our new style with its neighbors, if possible.
624 styleNode
.mergeSiblings();
626 // As the style system breaks text nodes constantly, let's normalize
627 // things for performance.
628 // With IE, some paragraphs get broken when calling normalize()
629 // repeatedly. Also, for IE, we must normalize body, not documentElement.
630 // IE is also known for having a "crash effect" with normalize().
631 // We should try to normalize with IE too in some way, somewhere.
632 if ( !CKEDITOR
.env
.ie
)
633 styleNode
.$.normalize();
635 // Style already inherit from parents, left just to clear up any internal overrides. (#5931)
638 styleNode
= new CKEDITOR
.dom
.element( 'span' );
639 styleRange
.extractContents().appendTo( styleNode
);
640 styleRange
.insertNode( styleNode
);
641 removeFromInsideElement( this, styleNode
);
642 styleNode
.remove( true );
645 // Style applied, let's release the range, so it gets
646 // re-initialization in the next loop.
651 // Remove the bookmark nodes.
652 range
.moveToBookmark( boundaryNodes
);
654 // Minimize the result range to exclude empty text nodes. (#5374)
655 range
.shrink( CKEDITOR
.SHRINK_TEXT
);
658 function removeInlineStyle( range
)
661 * Make sure our range has included all "collpased" parent inline nodes so
662 * that our operation logic can be simpler.
664 range
.enlarge( CKEDITOR
.ENLARGE_ELEMENT
, 1 );
666 var bookmark
= range
.createBookmark(),
667 startNode
= bookmark
.startNode
;
669 if ( range
.collapsed
)
672 var startPath
= new CKEDITOR
.dom
.elementPath( startNode
.getParent() ),
673 // The topmost element in elementspatch which we should jump out of.
677 for ( var i
= 0, element
; i
< startPath
.elements
.length
678 && ( element
= startPath
.elements
[i
] ) ; i
++ )
681 * 1. If it's collaped inside text nodes, try to remove the style from the whole element.
683 * 2. Otherwise if it's collapsed on element boundaries, moving the selection
684 * outside the styles instead of removing the whole tag,
685 * also make sure other inner styles were well preserverd.(#3309)
687 if ( element
== startPath
.block
|| element
== startPath
.blockLimit
)
690 if ( this.checkElementRemovable( element
) )
694 if ( range
.collapsed
&& (
695 range
.checkBoundaryOfElement( element
, CKEDITOR
.END
) ||
696 ( isStart
= range
.checkBoundaryOfElement( element
, CKEDITOR
.START
) ) ) )
698 boundaryElement
= element
;
699 boundaryElement
.match
= isStart
? 'start' : 'end';
704 * Before removing the style node, there may be a sibling to the style node
705 * that's exactly the same to the one to be removed. To the user, it makes
706 * no difference that they're separate entities in the DOM tree. So, merge
707 * them before removal.
709 element
.mergeSiblings();
710 if ( element
.getName() == this.element
)
711 removeFromElement( this, element
);
713 removeOverrides( element
, getOverrides( this )[ element
.getName() ] );
718 // Re-create the style tree after/before the boundary element,
719 // the replication start from bookmark start node to define the
721 if ( boundaryElement
)
723 var clonedElement
= startNode
;
726 var newElement
= startPath
.elements
[ i
];
727 if ( newElement
.equals( boundaryElement
) )
729 // Avoid copying any matched element.
730 else if ( newElement
.match
)
733 newElement
= newElement
.clone();
734 newElement
.append( clonedElement
);
735 clonedElement
= newElement
;
737 clonedElement
[ boundaryElement
.match
== 'start' ?
738 'insertBefore' : 'insertAfter' ]( boundaryElement
);
744 * Now our range isn't collapsed. Lets walk from the start node to the end
745 * node via DFS and remove the styles one-by-one.
747 var endNode
= bookmark
.endNode
,
751 * Find out the style ancestor that needs to be broken down at startNode
754 function breakNodes()
756 var startPath
= new CKEDITOR
.dom
.elementPath( startNode
.getParent() ),
757 endPath
= new CKEDITOR
.dom
.elementPath( endNode
.getParent() ),
760 for ( var i
= 0 ; i
< startPath
.elements
.length
; i
++ )
762 var element
= startPath
.elements
[ i
];
764 if ( element
== startPath
.block
|| element
== startPath
.blockLimit
)
767 if ( me
.checkElementRemovable( element
) )
768 breakStart
= element
;
770 for ( i
= 0 ; i
< endPath
.elements
.length
; i
++ )
772 element
= endPath
.elements
[ i
];
774 if ( element
== endPath
.block
|| element
== endPath
.blockLimit
)
777 if ( me
.checkElementRemovable( element
) )
782 endNode
.breakParent( breakEnd
);
784 startNode
.breakParent( breakStart
);
788 // Now, do the DFS walk.
789 var currentNode
= startNode
.getNext();
790 while ( !currentNode
.equals( endNode
) )
793 * Need to get the next node first because removeFromElement() can remove
794 * the current node from DOM tree.
796 var nextNode
= currentNode
.getNextSourceNode();
797 if ( currentNode
.type
== CKEDITOR
.NODE_ELEMENT
&& this.checkElementRemovable( currentNode
) )
799 // Remove style from element or overriding element.
800 if ( currentNode
.getName() == this.element
)
801 removeFromElement( this, currentNode
);
803 removeOverrides( currentNode
, getOverrides( this )[ currentNode
.getName() ] );
806 * removeFromElement() may have merged the next node with something before
807 * the startNode via mergeSiblings(). In that case, the nextNode would
808 * contain startNode and we'll have to call breakNodes() again and also
809 * reassign the nextNode to something after startNode.
811 if ( nextNode
.type
== CKEDITOR
.NODE_ELEMENT
&& nextNode
.contains( startNode
) )
814 nextNode
= startNode
.getNext();
817 currentNode
= nextNode
;
821 range
.moveToBookmark( bookmark
);
824 function applyObjectStyle( range
)
826 var root
= range
.getCommonAncestor( true, true ),
827 element
= root
.getAscendant( this.element
, true );
828 element
&& !element
.isReadOnly() && setupElement( element
, this );
831 function removeObjectStyle( range
)
833 var root
= range
.getCommonAncestor( true, true ),
834 element
= root
.getAscendant( this.element
, true );
840 def
= style
._
.definition
,
841 attributes
= def
.attributes
;
842 var styles
= CKEDITOR
.style
.getStyleText( def
);
844 // Remove all defined attributes.
847 for ( var att
in attributes
)
849 element
.removeAttribute( att
, attributes
[ att
] );
853 // Assign all defined styles.
856 for ( var i
in def
.styles
)
858 if ( !def
.styles
.hasOwnProperty( i
) )
861 element
.removeStyle( i
);
866 function applyBlockStyle( range
)
868 // Serializible bookmarks is needed here since
869 // elements may be merged.
870 var bookmark
= range
.createBookmark( true );
872 var iterator
= range
.createIterator();
873 iterator
.enforceRealBlocks
= true;
875 // make recognize <br /> tag as a separator in ENTER_BR mode (#5121)
876 if ( this._
.enterMode
)
877 iterator
.enlargeBr
= ( this._
.enterMode
!= CKEDITOR
.ENTER_BR
);
880 var doc
= range
.document
;
881 var previousPreBlock
;
883 while ( ( block
= iterator
.getNextParagraph() ) ) // Only one =
885 if ( !block
.isReadOnly() )
887 var newBlock
= getElement( this, doc
, block
);
888 replaceBlock( block
, newBlock
);
892 range
.moveToBookmark( bookmark
);
895 function removeBlockStyle( range
)
897 // Serializible bookmarks is needed here since
898 // elements may be merged.
899 var bookmark
= range
.createBookmark( 1 );
901 var iterator
= range
.createIterator();
902 iterator
.enforceRealBlocks
= true;
903 iterator
.enlargeBr
= this._
.enterMode
!= CKEDITOR
.ENTER_BR
;
906 while ( ( block
= iterator
.getNextParagraph() ) )
908 if ( this.checkElementRemovable( block
) )
910 // <pre> get special treatment.
911 if ( block
.is( 'pre' ) )
913 var newBlock
= this._
.enterMode
== CKEDITOR
.ENTER_BR
?
914 null : range
.document
.createElement(
915 this._
.enterMode
== CKEDITOR
.ENTER_P
? 'p' : 'div' );
917 newBlock
&& block
.copyAttributes( newBlock
);
918 replaceBlock( block
, newBlock
);
921 removeFromElement( this, block
, 1 );
925 range
.moveToBookmark( bookmark
);
928 // Replace the original block with new one, with special treatment
929 // for <pre> blocks to make sure content format is well preserved, and merging/splitting adjacent
930 // when necessary.(#3188)
931 function replaceBlock( block
, newBlock
)
933 // Block is to be removed, create a temp element to
935 var removeBlock
= !newBlock
;
938 newBlock
= block
.getDocument().createElement( 'div' );
939 block
.copyAttributes( newBlock
);
942 var newBlockIsPre
= newBlock
&& newBlock
.is( 'pre' );
943 var blockIsPre
= block
.is( 'pre' );
945 var isToPre
= newBlockIsPre
&& !blockIsPre
;
946 var isFromPre
= !newBlockIsPre
&& blockIsPre
;
949 newBlock
= toPre( block
, newBlock
);
950 else if ( isFromPre
)
951 // Split big <pre> into pieces before start to convert.
952 newBlock
= fromPres( removeBlock
?
953 [ block
.getHtml() ] : splitIntoPres( block
), newBlock
);
955 block
.moveChildren( newBlock
);
957 newBlock
.replace( block
);
961 // Merge previous <pre> blocks.
962 mergePre( newBlock
);
964 else if ( removeBlock
)
965 removeNoAttribsElement( newBlock
);
969 * Merge a <pre> block with a previous sibling if available.
971 function mergePre( preBlock
)
974 if ( !( ( previousBlock
= preBlock
.getPrevious( nonWhitespaces
) )
976 && previousBlock
.is( 'pre') ) )
979 // Merge the previous <pre> block contents into the current <pre>
982 // Another thing to be careful here is that currentBlock might contain
983 // a '\n' at the beginning, and previousBlock might contain a '\n'
984 // towards the end. These new lines are not normally displayed but they
985 // become visible after merging.
986 var mergedHtml
= replace( previousBlock
.getHtml(), /\n$/, '' ) + '\n\n' +
987 replace( preBlock
.getHtml(), /^\n/, '' ) ;
989 // Krugle: IE normalizes innerHTML from <pre>, breaking whitespaces.
990 if ( CKEDITOR
.env
.ie
)
991 preBlock
.$.outerHTML
= '<pre>' + mergedHtml
+ '</pre>';
993 preBlock
.setHtml( mergedHtml
);
995 previousBlock
.remove();
999 * Split into multiple <pre> blocks separated by double line-break.
1002 function splitIntoPres( preBlock
)
1004 // Exclude the ones at header OR at tail,
1005 // and ignore bookmark content between them.
1006 var duoBrRegex
= /(\S\s*)\n(?:\s|(<span[^>]+data-cke-bookmark.*?\/span>))*\n(?!$)/gi,
1007 blockName
= preBlock
.getName(),
1008 splitedHtml
= replace( preBlock
.getOuterHtml(),
1010 function( match
, charBefore
, bookmark
)
1012 return charBefore
+ '</pre>' + bookmark
+ '<pre>';
1016 splitedHtml
.replace( /<pre\b.*?>([\s\S]*?)<\/pre>/gi, function( match
, preContent
){
1017 pres
.push( preContent
);
1022 // Wrapper function of String::replace without considering of head/tail bookmarks nodes.
1023 function replace( str
, regexp
, replacement
)
1025 var headBookmark
= '',
1028 str
= str
.replace( /(^<span[^>]+data-cke-bookmark.*?\/span>)|(<span[^>]+data-cke-bookmark.*?\/span>$)/gi,
1029 function( str
, m1
, m2
){
1030 m1
&& ( headBookmark
= m1
);
1031 m2
&& ( tailBookmark
= m2
);
1034 return headBookmark
+ str
.replace( regexp
, replacement
) + tailBookmark
;
1038 * Converting a list of <pre> into blocks with format well preserved.
1040 function fromPres( preHtmls
, newBlock
)
1043 if ( preHtmls
.length
> 1 )
1044 docFrag
= new CKEDITOR
.dom
.documentFragment( newBlock
.getDocument() );
1046 for ( var i
= 0 ; i
< preHtmls
.length
; i
++ )
1048 var blockHtml
= preHtmls
[ i
];
1050 // 1. Trim the first and last line-breaks immediately after and before <pre>,
1051 // they're not visible.
1052 blockHtml
= blockHtml
.replace( /(\r\n|\r)/g, '\n' ) ;
1053 blockHtml
= replace( blockHtml
, /^[ \t]*\n/, '' ) ;
1054 blockHtml
= replace( blockHtml
, /\n$/, '' ) ;
1055 // 2. Convert spaces or tabs at the beginning or at the end to
1056 blockHtml
= replace( blockHtml
, /^[ \t]+|[ \t]+$/g, function( match
, offset
, s
)
1058 if ( match
.length
== 1 ) // one space, preserve it
1060 else if ( !offset
) // beginning of block
1061 return CKEDITOR
.tools
.repeat( ' ', match
.length
- 1 ) + ' ';
1062 else // end of block
1063 return ' ' + CKEDITOR
.tools
.repeat( ' ', match
.length
- 1 );
1066 // 3. Convert \n to <BR>.
1067 // 4. Convert contiguous (i.e. non-singular) spaces or tabs to
1068 blockHtml
= blockHtml
.replace( /\n/g, '<br>' ) ;
1069 blockHtml
= blockHtml
.replace( /[ \t]{2,}/g,
1072 return CKEDITOR
.tools
.repeat( ' ', match
.length
- 1 ) + ' ' ;
1077 var newBlockClone
= newBlock
.clone();
1078 newBlockClone
.setHtml( blockHtml
);
1079 docFrag
.append( newBlockClone
);
1082 newBlock
.setHtml( blockHtml
);
1085 return docFrag
|| newBlock
;
1089 * Converting from a non-PRE block to a PRE block in formatting operations.
1091 function toPre( block
, newBlock
)
1093 var bogus
= block
.getBogus();
1094 bogus
&& bogus
.remove();
1096 // First trim the block content.
1097 var preHtml
= block
.getHtml();
1099 // 1. Trim head/tail spaces, they're not visible.
1100 preHtml
= replace( preHtml
, /(?:^[ \t\n\r]+)|(?:[ \t\n\r]+$)/g, '' );
1101 // 2. Delete ANSI whitespaces immediately before and after <BR> because
1102 // they are not visible.
1103 preHtml
= preHtml
.replace( /[ \t\r\n]*(<br[^>]*>)[ \t\r\n]*/gi, '$1' );
1104 // 3. Compress other ANSI whitespaces since they're only visible as one
1105 // single space previously.
1106 // 4. Convert to spaces since is no longer needed in <PRE>.
1107 preHtml
= preHtml
.replace( /([ \t\n\r]+| )/g, ' ' );
1108 // 5. Convert any <BR /> to \n. This must not be done earlier because
1109 // the \n would then get compressed.
1110 preHtml
= preHtml
.replace( /<br\b[^>]*>/gi, '\n' );
1112 // Krugle: IE normalizes innerHTML to <pre>, breaking whitespaces.
1113 if ( CKEDITOR
.env
.ie
)
1115 var temp
= block
.getDocument().createElement( 'div' );
1116 temp
.append( newBlock
);
1117 newBlock
.$.outerHTML
= '<pre>' + preHtml
+ '</pre>';
1118 newBlock
.copyAttributes( temp
.getFirst() );
1119 newBlock
= temp
.getFirst().remove();
1122 newBlock
.setHtml( preHtml
);
1127 // Removes a style from an element itself, don't care about its subtree.
1128 function removeFromElement( style
, element
)
1130 var def
= style
._
.definition
,
1131 attributes
= CKEDITOR
.tools
.extend( {}, def
.attributes
, getOverrides( style
)[ element
.getName() ] ),
1132 styles
= def
.styles
,
1133 // If the style is only about the element itself, we have to remove the element.
1134 removeEmpty
= CKEDITOR
.tools
.isEmpty( attributes
) && CKEDITOR
.tools
.isEmpty( styles
);
1136 // Remove definition attributes/style from the elemnt.
1137 for ( var attName
in attributes
)
1139 // The 'class' element value must match (#1318).
1140 if ( ( attName
== 'class' || style
._
.definition
.fullMatch
)
1141 && element
.getAttribute( attName
) != normalizeProperty( attName
, attributes
[ attName
] ) )
1143 removeEmpty
= element
.hasAttribute( attName
);
1144 element
.removeAttribute( attName
);
1147 for ( var styleName
in styles
)
1149 // Full match style insist on having fully equivalence. (#5018)
1150 if ( style
._
.definition
.fullMatch
1151 && element
.getStyle( styleName
) != normalizeProperty( styleName
, styles
[ styleName
], true ) )
1154 removeEmpty
= removeEmpty
|| !!element
.getStyle( styleName
);
1155 element
.removeStyle( styleName
);
1160 !CKEDITOR
.dtd
.$block
[ element
.getName() ] || style
._
.enterMode
== CKEDITOR
.ENTER_BR
&& !element
.hasAttributes() ?
1161 removeNoAttribsElement( element
) :
1162 element
.renameNode( style
._
.enterMode
== CKEDITOR
.ENTER_P
? 'p' : 'div' );
1166 // Removes a style from inside an element.
1167 function removeFromInsideElement( style
, element
)
1169 var def
= style
._
.definition
,
1170 attribs
= def
.attributes
,
1171 styles
= def
.styles
,
1172 overrides
= getOverrides( style
),
1173 innerElements
= element
.getElementsByTag( style
.element
);
1175 for ( var i
= innerElements
.count(); --i
>= 0 ; )
1176 removeFromElement( style
, innerElements
.getItem( i
) );
1178 // Now remove any other element with different name that is
1179 // defined to be overriden.
1180 for ( var overrideElement
in overrides
)
1182 if ( overrideElement
!= style
.element
)
1184 innerElements
= element
.getElementsByTag( overrideElement
) ;
1185 for ( i
= innerElements
.count() - 1 ; i
>= 0 ; i
-- )
1187 var innerElement
= innerElements
.getItem( i
);
1188 removeOverrides( innerElement
, overrides
[ overrideElement
] ) ;
1195 * Remove overriding styles/attributes from the specific element.
1196 * Note: Remove the element if no attributes remain.
1197 * @param {Object} element
1198 * @param {Object} overrides
1200 function removeOverrides( element
, overrides
)
1202 var attributes
= overrides
&& overrides
.attributes
;
1206 for ( var i
= 0 ; i
< attributes
.length
; i
++ )
1208 var attName
= attributes
[i
][0], actualAttrValue
;
1210 if ( ( actualAttrValue
= element
.getAttribute( attName
) ) )
1212 var attValue
= attributes
[i
][1] ;
1214 // Remove the attribute if:
1215 // - The override definition value is null ;
1216 // - The override definition valie is a string that
1217 // matches the attribute value exactly.
1218 // - The override definition value is a regex that
1219 // has matches in the attribute value.
1220 if ( attValue
=== null ||
1221 ( attValue
.test
&& attValue
.test( actualAttrValue
) ) ||
1222 ( typeof attValue
== 'string' && actualAttrValue
== attValue
) )
1223 element
.removeAttribute( attName
) ;
1228 removeNoAttribsElement( element
);
1231 // If the element has no more attributes, remove it.
1232 function removeNoAttribsElement( element
)
1234 // If no more attributes remained in the element, remove it,
1235 // leaving its children.
1236 if ( !element
.hasAttributes() )
1238 if ( CKEDITOR
.dtd
.$block
[ element
.getName() ] )
1240 var previous
= element
.getPrevious( nonWhitespaces
),
1241 next
= element
.getNext( nonWhitespaces
);
1243 if ( previous
&& ( previous
.type
== CKEDITOR
.NODE_TEXT
|| !previous
.isBlockBoundary( { br
: 1 } ) ) )
1244 element
.append( 'br', 1 );
1245 if ( next
&& ( next
.type
== CKEDITOR
.NODE_TEXT
|| !next
.isBlockBoundary( { br
: 1 } ) ) )
1246 element
.append( 'br' );
1248 element
.remove( true );
1252 // Removing elements may open points where merging is possible,
1253 // so let's cache the first and last nodes for later checking.
1254 var firstChild
= element
.getFirst();
1255 var lastChild
= element
.getLast();
1257 element
.remove( true );
1261 // Check the cached nodes for merging.
1262 firstChild
.type
== CKEDITOR
.NODE_ELEMENT
&& firstChild
.mergeSiblings();
1264 if ( lastChild
&& !firstChild
.equals( lastChild
)
1265 && lastChild
.type
== CKEDITOR
.NODE_ELEMENT
)
1266 lastChild
.mergeSiblings();
1273 function getElement( style
, targetDocument
, element
)
1276 def
= style
._
.definition
,
1277 elementName
= style
.element
;
1279 // The "*" element name will always be a span for this function.
1280 if ( elementName
== '*' )
1281 elementName
= 'span';
1283 // Create the element.
1284 el
= new CKEDITOR
.dom
.element( elementName
, targetDocument
);
1286 // #6226: attributes should be copied before the new ones are applied
1288 element
.copyAttributes( el
);
1290 el
= setupElement( el
, style
);
1292 // Avoid ID duplication.
1293 if ( targetDocument
.getCustomData( 'doc_processing_style' ) && el
.hasAttribute( 'id' ) )
1294 el
.removeAttribute( 'id' );
1296 targetDocument
.setCustomData( 'doc_processing_style', 1 );
1301 function setupElement( el
, style
)
1303 var def
= style
._
.definition
,
1304 attributes
= def
.attributes
,
1305 styles
= CKEDITOR
.style
.getStyleText( def
);
1307 // Assign all defined attributes.
1310 for ( var att
in attributes
)
1312 el
.setAttribute( att
, attributes
[ att
] );
1316 // Assign all defined styles.
1318 el
.setAttribute( 'style', styles
);
1323 function replaceVariables( list
, variablesValues
)
1325 for ( var item
in list
)
1327 list
[ item
] = list
[ item
].replace( varRegex
, function( match
, varName
)
1329 return variablesValues
[ varName
];
1334 // Returns an object that can be used for style matching comparison.
1335 // Attributes names and values are all lowercased, and the styles get
1336 // merged with the style attribute.
1337 function getAttributesForComparison( styleDefinition
)
1339 // If we have already computed it, just return it.
1340 var attribs
= styleDefinition
._AC
;
1348 // Loop through all defined attributes.
1349 var styleAttribs
= styleDefinition
.attributes
;
1352 for ( var styleAtt
in styleAttribs
)
1355 attribs
[ styleAtt
] = styleAttribs
[ styleAtt
];
1359 // Includes the style definitions.
1360 var styleText
= CKEDITOR
.style
.getStyleText( styleDefinition
);
1363 if ( !attribs
[ 'style' ] )
1365 attribs
[ 'style' ] = styleText
;
1368 // Appends the "length" information to the object.
1369 attribs
._length
= length
;
1371 // Return it, saving it to the next request.
1372 return ( styleDefinition
._AC
= attribs
);
1376 * Get the the collection used to compare the elements and attributes,
1377 * defined in this style overrides, with other element. All information in
1379 * @param {CKEDITOR.style} style
1381 function getOverrides( style
)
1383 if ( style
._
.overrides
)
1384 return style
._
.overrides
;
1386 var overrides
= ( style
._
.overrides
= {} ),
1387 definition
= style
._
.definition
.overrides
;
1391 // The override description can be a string, object or array.
1392 // Internally, well handle arrays only, so transform it if needed.
1393 if ( !CKEDITOR
.tools
.isArray( definition
) )
1394 definition
= [ definition
];
1396 // Loop through all override definitions.
1397 for ( var i
= 0 ; i
< definition
.length
; i
++ )
1399 var override
= definition
[i
];
1404 // If can be a string with the element name.
1405 if ( typeof override
== 'string' )
1406 elementName
= override
.toLowerCase();
1410 elementName
= override
.element
? override
.element
.toLowerCase() : style
.element
;
1411 attrs
= override
.attributes
;
1414 // We can have more than one override definition for the same
1415 // element name, so we attempt to simply append information to
1416 // it if it already exists.
1417 overrideEl
= overrides
[ elementName
] || ( overrides
[ elementName
] = {} );
1421 // The returning attributes list is an array, because we
1422 // could have different override definitions for the same
1424 var overrideAttrs
= ( overrideEl
.attributes
= overrideEl
.attributes
|| new Array() );
1425 for ( var attName
in attrs
)
1427 // Each item in the attributes array is also an array,
1428 // where [0] is the attribute name and [1] is the
1430 overrideAttrs
.push( [ attName
.toLowerCase(), attrs
[ attName
] ] );
1439 // Make the comparison of attribute value easier by standardizing it.
1440 function normalizeProperty( name
, value
, isStyle
)
1442 var temp
= new CKEDITOR
.dom
.element( 'span' );
1443 temp
[ isStyle
? 'setStyle' : 'setAttribute' ]( name
, value
);
1444 return temp
[ isStyle
? 'getStyle' : 'getAttribute' ]( name
);
1447 // Make the comparison of style text easier by standardizing it.
1448 function normalizeCssText( unparsedCssText
, nativeNormalize
)
1451 if ( nativeNormalize
!== false )
1453 // Injects the style in a temporary span object, so the browser parses it,
1454 // retrieving its final format.
1455 var temp
= new CKEDITOR
.dom
.element( 'span' );
1456 temp
.setAttribute( 'style', unparsedCssText
);
1457 styleText
= temp
.getAttribute( 'style' ) || '';
1460 styleText
= unparsedCssText
;
1462 // Normalize font-family property, ignore quotes and being case insensitive. (#7322)
1463 // http://www.w3.org/TR/css3-fonts/#font-family-the-font-family-property
1464 styleText
= styleText
.replace( /(font-family:)(.*?)(?=;|$)/, function ( match
, prop
, val
)
1466 var names
= val
.split( ',' );
1467 for ( var i
= 0; i
< names
.length
; i
++ )
1468 names
[ i
] = CKEDITOR
.tools
.trim( names
[ i
].replace( /["']/g, '' ) );
1469 return prop
+ names
.join( ',' );
1472 // Shrinking white-spaces around colon and semi-colon (#4147).
1473 // Compensate tail semi-colon.
1474 return styleText
.replace( /\s*([;:])\s*/, '$1' )
1475 .replace( /([^\s;])$/, '$1;')
1476 // Trimming spaces after comma(#4107),
1477 // remove quotations(#6403),
1478 // mostly for differences on "font-family".
1479 .replace( /,\s+/g, ',' )
1480 .replace( /\"/g,'' )
1484 // Turn inline style text properties into one hash.
1485 function parseStyleText( styleText
)
1489 .replace( /"/g, '"' )
1490 .replace( /\s*([^ :;]+)\s*:\s*([^;]+)\s*(?=;|$)/g, function( match
, name
, value
)
1492 retval
[ name
] = value
;
1498 * Compare two bunch of styles, with the speciality that value 'inherit'
1499 * is treated as a wildcard which will match any value.
1500 * @param {Object|String} source
1501 * @param {Object|String} target
1503 function compareCssText( source
, target
)
1505 typeof source
== 'string' && ( source
= parseStyleText( source
) );
1506 typeof target
== 'string' && ( target
= parseStyleText( target
) );
1507 for( var name
in source
)
1509 if ( !( name
in target
&&
1510 ( target
[ name
] == source
[ name
]
1511 || source
[ name
] == 'inherit'
1512 || target
[ name
] == 'inherit' ) ) )
1520 function applyStyle( document
, remove
)
1522 var selection
= document
.getSelection(),
1523 // Bookmark the range so we can re-select it after processing.
1524 bookmarks
= selection
.createBookmarks( 1 ),
1525 ranges
= selection
.getRanges(),
1526 func
= remove
? this.removeFromRange
: this.applyToRange
,
1529 var iterator
= ranges
.createIterator();
1530 while ( ( range
= iterator
.getNextRange() ) )
1531 func
.call( this, range
);
1533 if ( bookmarks
.length
== 1 && bookmarks
[ 0 ].collapsed
)
1535 selection
.selectRanges( ranges
);
1536 document
.getById( bookmarks
[ 0 ].startNode
).remove();
1539 selection
.selectBookmarks( bookmarks
);
1541 document
.removeCustomData( 'doc_processing_style' );
1545 CKEDITOR
.styleCommand = function( style
)
1550 CKEDITOR
.styleCommand
.prototype.exec = function( editor
)
1554 var doc
= editor
.document
;
1558 if ( this.state
== CKEDITOR
.TRISTATE_OFF
)
1559 this.style
.apply( doc
);
1560 else if ( this.state
== CKEDITOR
.TRISTATE_ON
)
1561 this.style
.remove( doc
);
1568 * Manages styles registration and loading. See also {@link CKEDITOR.config.stylesSet}.
1570 * @augments CKEDITOR.resourceManager
1574 * // The set of styles for the <b>Styles</b> combo
1575 * CKEDITOR.stylesSet.add( 'default',
1578 * { name : 'Blue Title' , element : 'h3', styles : { 'color' : 'Blue' } },
1579 * { name : 'Red Title' , element : 'h3', styles : { 'color' : 'Red' } },
1582 * { name : 'Marker: Yellow' , element : 'span', styles : { 'background-color' : 'Yellow' } },
1583 * { name : 'Marker: Green' , element : 'span', styles : { 'background-color' : 'Lime' } },
1587 * name : 'Image on Left',
1591 * 'style' : 'padding: 5px; margin-right: 5px',
1598 CKEDITOR
.stylesSet
= new CKEDITOR
.resourceManager( '', 'stylesSet' );
1600 // Backward compatibility (#5025).
1601 CKEDITOR
.addStylesSet
= CKEDITOR
.tools
.bind( CKEDITOR
.stylesSet
.add
, CKEDITOR
.stylesSet
);
1602 CKEDITOR
.loadStylesSet = function( name
, url
, callback
)
1604 CKEDITOR
.stylesSet
.addExternal( name
, url
, '' );
1605 CKEDITOR
.stylesSet
.load( name
, callback
);
1610 * Gets the current styleSet for this instance
1611 * @param {Function} callback The function to be called with the styles data.
1613 * editor.getStylesSet( function( stylesDefinitions ) {} );
1615 CKEDITOR
.editor
.prototype.getStylesSet = function( callback
)
1617 if ( !this._
.stylesDefinitions
)
1620 // Respect the backwards compatible definition entry
1621 configStyleSet
= editor
.config
.stylesCombo_stylesSet
|| editor
.config
.stylesSet
|| 'default';
1623 // #5352 Allow to define the styles directly in the config object
1624 if ( configStyleSet
instanceof Array
)
1626 editor
._
.stylesDefinitions
= configStyleSet
;
1627 callback( configStyleSet
);
1631 var partsStylesSet
= configStyleSet
.split( ':' ),
1632 styleSetName
= partsStylesSet
[ 0 ],
1633 externalPath
= partsStylesSet
[ 1 ],
1634 pluginPath
= CKEDITOR
.plugins
.registered
.styles
.path
;
1636 CKEDITOR
.stylesSet
.addExternal( styleSetName
,
1638 partsStylesSet
.slice( 1 ).join( ':' ) :
1639 pluginPath
+ 'styles/' + styleSetName
+ '.js', '' );
1641 CKEDITOR
.stylesSet
.load( styleSetName
, function( stylesSet
)
1643 editor
._
.stylesDefinitions
= stylesSet
[ styleSetName
];
1644 callback( editor
._
.stylesDefinitions
);
1648 callback( this._
.stylesDefinitions
);
1652 * Indicates that fully selected read-only elements will be included when
1653 * applying the style (for inline styles only).
1654 * @name CKEDITOR.style.includeReadonly
1661 * Disables inline styling on read-only elements.
1662 * @name CKEDITOR.config.disableReadonlyStyling
1669 * The "styles definition set" to use in the editor. They will be used in the
1670 * styles combo and the Style selector of the div container. <br>
1671 * The styles may be defined in the page containing the editor, or can be
1672 * loaded on demand from an external file. In the second case, if this setting
1673 * contains only a name, the styles definition file will be loaded from the
1674 * "styles" folder inside the styles plugin folder.
1675 * Otherwise, this setting has the "name:url" syntax, making it
1676 * possible to set the URL from which loading the styles file.<br>
1677 * Previously this setting was available as config.stylesCombo_stylesSet<br>
1678 * @name CKEDITOR.config.stylesSet
1679 * @type String|Array
1680 * @default 'default'
1683 * // Load from the styles' styles folder (mystyles.js file).
1684 * config.stylesSet = 'mystyles';
1686 * // Load from a relative URL.
1687 * config.stylesSet = 'mystyles:/editorstyles/styles.js';
1689 * // Load from a full URL.
1690 * config.stylesSet = 'mystyles:http://www.example.com/editorstyles/styles.js';
1692 * // Load from a list of definitions.
1693 * config.stylesSet = [
1694 * { name : 'Strong Emphasis', element : 'strong' },
1695 * { name : 'Emphasis', element : 'em' }, ... ];