Opened 7 years ago

Closed 6 years ago

#7387 closed New Feature (fixed)

Allow styleDefinitions that can be applied to a set of elements

Reported by: Alfonso Martínez de Lizarrondo Owned by: Alfonso Martínez de Lizarrondo
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 Alfonso Martínez de Lizarrondo 7 years ago.
Proposed patch
7387_2.patch (3.5 KB) - added by Alfonso Martínez de Lizarrondo 7 years ago.
Revised patch

Download all attachments as: .zip

Change History (7)

Changed 7 years ago by Alfonso Martínez de Lizarrondo

Attachment: 7387.patch added

Proposed patch

comment:1 Changed 7 years ago by Alfonso Martínez de Lizarrondo

Status: newreview

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 7 years ago by Frederico Caldeira Knabben

Status: reviewreview_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 7 years ago by Alfonso Martínez de Lizarrondo

Attachment: 7387_2.patch added

Revised patch

comment:3 Changed 7 years ago by Alfonso Martínez de Lizarrondo

Status: review_failedreview

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 Frederico Caldeira Knabben

Milestone: CKEditor 3.6.1
Status: reviewreview_passed

comment:5 Changed 6 years ago by Alfonso Martínez de Lizarrondo

Resolution: fixed
Status: review_passedclosed

Fixed with [6984]

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