Opened 6 years ago

Closed 6 years ago

#7387 closed New Feature (fixed)

Allow styleDefinitions that can be applied to a set of elements

Reported by: alfonsoml Owned by: alfonsoml
Priority: Normal Milestone: CKEditor 3.6.1
Component: Core : Styles Version:
Keywords: Cc:

Description

The current style system is based on defining which element is going to be used for that "Style", but there are times when it's desirable to have a Style that can be applied to a set of elements.

This means of course, that in this situation the element must exist, it won't be created and so it's behavior is more along the current STYLE_OBJECT system

The patch enhances the style system to allow an "elements" property in the style definition to specify the set of allowed tags, and also allows to specify the type of the style to override the default behavior so even if a single element like "p" is specified it can work in this way instead of having the default "block" behavior.

Attachments (2)

7387.patch (3.7 KB) - added by alfonsoml 6 years ago.
Proposed patch
7387_2.patch (3.5 KB) - added by alfonsoml 6 years ago.
Revised patch

Download all attachments as: .zip

Change History (7)

Changed 6 years ago by alfonsoml

Proposed patch

comment:1 Changed 6 years ago by alfonsoml

  • Status changed from new to review

I'm not really proud of the "getAscendantInHash" name, so if there's any suggestion I'll gladly accept it.

As you can see, the patch is quite simple as it's based mostly on calling that function.

I've used an object to store the possible element names instead of a regexp because I think that some time ago Fred said that such lookups performed better that way.

comment:2 Changed 6 years ago by fredck

  • Status changed from review to review_failed

Instead of creating an additional function, let's enlarge getAscendant, making it accept a String or an Object for the "name" parameter. typeof performs very fast and even if this means joining both functions code, it'll give a clearer API.

As for the possibility of defining the type in the style definition, while it sounds interesting at a first glance, it may bring confusion. That's because the only acceptable value for it is CKEDITOR.STYLE_OBJECT. Any other value would break things (like trying to make inline elements to behave like blocks and vice-versa). Because of this, it would be better to have a boolean property for it. Something like "changeOnly:true". This will also help to make it easier to use (the "object" term may not be easy to understand and associate to inline or block elements).

Additionally, is there any chance to reuse the "element" property instead of adding the new "elements"? This would help to make the definition simpler and cleaner.

Changed 6 years ago by alfonsoml

Revised patch

comment:3 Changed 6 years ago by alfonsoml

  • Status changed from review_failed to review

I've simplified the patch to address all the comments.

The main reason to allow to specify the 'type' in the style definition was in order to allow for example that 'a' styles could be applied like inline styles or other things like that, in fact if someone wants some style to be applied in 'changeOnly' mode after this patch it's enough to specify the element like an object with a single property instead of a string: element = { p:1 } vs element = 'p' and that will do the magic.

The patch can be tested by adding something like this to the styles definition:

	// Can be applied to P or H3 elements
	{ name : 'green'		, element : {p:1, h3:1}, styles : { 'color' : 'green' } },
	{ name : 'brown'		, element : {p:1, h3:1}, styles : { 'color' : 'brown' } },

comment:4 Changed 6 years ago by fredck

  • Milestone set to CKEditor 3.6.1
  • Status changed from review to review_passed

comment:5 Changed 6 years ago by alfonsoml

  • Resolution set to fixed
  • Status changed from review_passed to closed

Fixed with [6984]

Note: See TracTickets for help on using tickets.
© 2003 – 2016 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy