Ticket #207 (closed New Feature: fixed)

Opened 8 years ago

Last modified 7 years ago

Wrap an arbitrary html tag around a selection

Reported by: adamann2@… Owned by: fredck
Priority: Normal Milestone: FCKeditor 2.5 Beta
Component: Core : Styles Version:
Keywords: Cc:

Description

I would like to request a feature that would wrap html tags, with attributes, around a user's selection. For instance, if the user selects some text in the edit pane and presses a button, I want to wrap the selection in a span, with a class and title. We need this feature for adding instructor comments to student writing assignments.

I have found and tried several examples, and they work fine as long as the selection is just text. However, to be useful, the inserted tags need to work properly with other tags in the text.

A simple example, starting with this:

<p>Here's some text</p> <p>Here's some more text</p>

Now, if the user's selection starts with the word 'text' in the first paragraph, and ends with the word 'more' in the second paragraph, here's what I'd expect to see:

<p>Here's some <span class="foo" title="bar">text</span></p> <p><span class="foo" title="bar">Here's some more</span> text</p>

What I'm actually getting with the examples I've tried is something like this:

<p>Here's some <span class="foo" title="bar">textHere's some more</span> text</p>

I'd be happy to help work on this, if someone can help me out or point me in the right direction, or let me know anyone is already working on something similar.

Change History

comment:1 Changed 8 years ago by fredck

  • Component changed from General to Core : Styles
  • Milestone set to FCKeditor 2.5

This one is supposed to be fixed with the new style system planned for the 2.5.

comment:2 Changed 7 years ago by fredck

  • Status changed from new to assigned
  • Owner set to fredck

comment:3 Changed 7 years ago by fredck

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

As a result of [774], we were able to provide this feature with [844]. It introduced the FCK.Selection.ApplyStyle( styleDefinition ) function, which applies an arbitrary style definition to the selection.

The style definition to be passed to this function is an object with the same structure used for the styles in the configuration file (see Components/Styles?).

So, for the example provided, we should have something like this (when called from outside FCKeditor):

editorInstance.Selection.ApplyStyle( 
	{ 
		Element : 'span', 
		Attributes : 
		{
			'class' : "foo",
			'title' : "bar"
		}
	} ) ;
Note: See TracTickets for help on using tickets.
© 2003 – 2012 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy