X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fplugins%2Fstyles%2Fplugin.js;h=9a4f13d0948698c0a57ccfce2c733bb6b75ce3fc;hp=40dc6d18b85420f3e53ae3ae57940b31bf96a5b0;hb=4e90e78dc97789709ee7404359a5517540c27553;hpb=8f6c203fdaa543c3bca40baea6ae4ddcdf1a77f5 diff --git a/_source/plugins/styles/plugin.js b/_source/plugins/styles/plugin.js index 40dc6d1..9a4f13d 100644 --- a/_source/plugins/styles/plugin.js +++ b/_source/plugins/styles/plugin.js @@ -19,11 +19,11 @@ CKEDITOR.plugins.add( 'styles', }); /** - * Registers a function to be called whenever a style changes its state in the + * Registers a function to be called whenever the selection position changes in the * editing area. The current state is passed to the function. The possible * states are {@link CKEDITOR.TRISTATE_ON} and {@link CKEDITOR.TRISTATE_OFF}. * @param {CKEDITOR.style} style The style to be watched. - * @param {Function} callback The function to be called when the style state changes. + * @param {Function} callback The function to be called. * @example * // Create a style object for the <b> element. * var style = new CKEDITOR.style( { element : 'b' } ); @@ -61,17 +61,9 @@ CKEDITOR.editor.prototype.attachStyleStateChange = function( style, callback ) // callback. var currentState = callback.style.checkActive( ev.data.path ) ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF; - // If the state changed since the last check. - if ( callback.state !== currentState ) - { - // Call the callback function, passing the current - // state to it. - callback.fn.call( this, currentState ); - - // Save the current state, so it can be compared next - // time. - callback.state = currentState; - } + // Call the callback function, passing the current + // state to it. + callback.fn.call( this, currentState ); } }); } @@ -87,12 +79,14 @@ CKEDITOR.STYLE_OBJECT = 3; (function() { - var blockElements = { address:1,div:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1,p:1,pre:1 }; - 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}; + var blockElements = { address:1,div:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1,p:1,pre:1 }, + 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}; - var semicolonFixRegex = /\s*(?:;\s*|$)/; + var semicolonFixRegex = /\s*(?:;\s*|$)/, + varRegex = /#\((.+?)\)/g; - var notBookmark = CKEDITOR.dom.walker.bookmark( 0, 1 ); + var notBookmark = CKEDITOR.dom.walker.bookmark( 0, 1 ), + nonWhitespaces = CKEDITOR.dom.walker.whitespaces( 1 ); CKEDITOR.style = function( styleDefinition, variablesValues ) { @@ -107,7 +101,7 @@ CKEDITOR.STYLE_OBJECT = 3; var element = this.element = ( styleDefinition.element || '*' ).toLowerCase(); this.type = - ( element == '#' || blockElements[ element ] ) ? + blockElements[ element ] ? CKEDITOR.STYLE_BLOCK : objectElements[ element ] ? CKEDITOR.STYLE_OBJECT @@ -703,8 +697,10 @@ CKEDITOR.STYLE_OBJECT = 3; * them before removal. */ element.mergeSiblings(); - removeFromElement( this, element ); - + if ( element.getName() == this.element ) + removeFromElement( this, element ); + else + removeOverrides( element, getOverrides( this )[ element.getName() ] ); } } } @@ -813,26 +809,26 @@ CKEDITOR.STYLE_OBJECT = 3; } range.moveToBookmark( bookmark ); -} + } function applyObjectStyle( range ) { var root = range.getCommonAncestor( true, true ), - element = root.getAscendant( this.element, true ); + element = root.getAscendant( this.element, true ); element && setupElement( element, this ); } function removeObjectStyle( range ) { var root = range.getCommonAncestor( true, true ), - element = root.getAscendant( this.element, true ); + element = root.getAscendant( this.element, true ); if ( !element ) return; - var style = this; - var def = style._.definition; - var attributes = def.attributes; + var style = this, + def = style._.definition, + attributes = def.attributes; var styles = CKEDITOR.style.getStyleText( def ); // Remove all defined attributes. @@ -956,7 +952,6 @@ CKEDITOR.STYLE_OBJECT = 3; removeNoAttribsElement( newBlock ); } - var nonWhitespaces = CKEDITOR.dom.walker.whitespaces( 1 ); /** * Merge a
 block with a previous sibling if available.
 	 */
@@ -1025,6 +1020,7 @@ CKEDITOR.STYLE_OBJECT = 3;
 			} );
 		return headBookmark + str.replace( regexp, replacement ) + tailBookmark;
 	}
+
 	/**
 	 * Converting a list of 
 into blocks with format well preserved.
 	 */
@@ -1160,9 +1156,8 @@ CKEDITOR.STYLE_OBJECT = 3;
 		var def = style._.definition,
 			attribs = def.attributes,
 			styles = def.styles,
-			overrides = getOverrides( style );
-
-		var innerElements = element.getElementsByTag( style.element );
+			overrides = getOverrides( style ),
+			innerElements = element.getElementsByTag( style.element );
 
 		for ( var i = innerElements.count(); --i >= 0 ; )
 			removeFromElement( style,  innerElements.getItem( i ) );
@@ -1181,7 +1176,6 @@ CKEDITOR.STYLE_OBJECT = 3;
 				}
 			}
 		}
-
 	}
 
 	/**
@@ -1265,11 +1259,9 @@ CKEDITOR.STYLE_OBJECT = 3;
 
 	function getElement( style, targetDocument, element )
 	{
-		var el;
-
-		var def = style._.definition;
-
-		var elementName = style.element;
+		var el,
+			def = style._.definition,
+			elementName = style.element;
 
 		// The "*" element name will always be a span for this function.
 		if ( elementName == '*' )
@@ -1295,9 +1287,9 @@ CKEDITOR.STYLE_OBJECT = 3;
 
 	function setupElement( el, style )
 	{
-		var def = style._.definition;
-		var attributes = def.attributes;
-		var styles = CKEDITOR.style.getStyleText( def );
+		var def = style._.definition,
+			attributes = def.attributes,
+			styles = CKEDITOR.style.getStyleText( def );
 
 		// Assign all defined attributes.
 		if ( attributes )
@@ -1315,7 +1307,6 @@ CKEDITOR.STYLE_OBJECT = 3;
 		return el;
 	}
 
-	var varRegex = /#\((.+?)\)/g;
 	function replaceVariables( list, variablesValues )
 	{
 		for ( var item in list )
@@ -1327,7 +1318,6 @@ CKEDITOR.STYLE_OBJECT = 3;
 		}
 	}
 
-
 	// Returns an object that can be used for style matching comparison.
 	// Attributes names and values are all lowercased, and the styles get
 	// merged with the style attribute.
@@ -1543,6 +1533,37 @@ CKEDITOR.styleCommand.prototype.exec = function( editor )
 	return !!doc;
 };
 
+/**
+ * Manages styles registration and loading. See also {@link CKEDITOR.config.stylesSet}.
+ * @namespace
+ * @augments CKEDITOR.resourceManager
+ * @constructor
+ * @since 3.2
+ * @example
+ * // The set of styles for the Styles combo
+ * CKEDITOR.stylesSet.add( 'default',
+ * [
+ * 	// Block Styles
+ * 	{ name : 'Blue Title'		, element : 'h3', styles : { 'color' : 'Blue' } },
+ * 	{ name : 'Red Title'		, element : 'h3', styles : { 'color' : 'Red' } },
+ *
+ * 	// Inline Styles
+ * 	{ name : 'Marker: Yellow'	, element : 'span', styles : { 'background-color' : 'Yellow' } },
+ * 	{ name : 'Marker: Green'	, element : 'span', styles : { 'background-color' : 'Lime' } },
+ *
+ * 	// Object Styles
+ * 	{
+ * 		name : 'Image on Left',
+ * 		element : 'img',
+ * 		attributes :
+ * 		{
+ * 			'style' : 'padding: 5px; margin-right: 5px',
+ * 			'border' : '2',
+ * 			'align' : 'left'
+ * 		}
+ * 	}
+ * ]);
+ */
 CKEDITOR.stylesSet = new CKEDITOR.resourceManager( '', 'stylesSet' );
 
 // Backward compatibility (#5025).