Ticket #856 (closed New Feature: fixed)

Opened 7 years ago

Last modified 5 months ago

Provision for a custom onPaste code cleanup function

Reported by: moonpool99@… Owned by:
Priority: Normal Milestone:
Component: General Version:
Keywords: SF Cc: fredck, alfonsoml

Description

Can you please add a custom code cleanup function (callback) that would be executed onPaste being fired into the main editor text area.

Reason: Many implementations of FCKEditor in an application would require end-users to create their own web pages (CMS). Consequently, if a end-user pastes in HTML from a 3rd party web site, the code would need to be cleaned in some way before being saved in a content repository (on the server) - for example to remove javascript onclick handlers or form elements. While this is is easy to do on the server side, the saved html would not be what the end-user had pasted into the editor, and thus confuse the end user.

It would be better if the cleanup could be done on the client side using the onPaste event before being displayed in the editor, so the user knows exactly what he/she is getting.

However, each implementing application's requirements for the cleaning algorithm would be different.

Thus, the requirements are:

  1. Provide a custom cleanup function callback that is

executed onPaste. The function can be an empty stub, that returns the raw html if not modified by the implementer. (maybe with a commented out regex example inside)

  1. Provide a config setting for turning this feature on

and off

  1. Obviously this would only work for browsers that

support access to the clipboard (Gecko browsers (firefox) currently do not - but would be there for when it does!)


Moved from SF:
http://sourceforge.net/tracker/index.php?func=detail&aid=1403554&group_id=75348&atid=543656

Change History

comment:1 Changed 7 years ago by martinkou

  • Cc fredck, alfonsoml added
  • Reporter changed from martinkou to moonpool99@…

I understood the request... just a way to use the FCKeditor Word Cleanup feature and interface, but calling a custom cleaning code.


Moved from SF. Original poster: fredck

You define a function and make it listen to OnPaste. Inside that function you read the clipboard (you can even use FCK.GetClipboardHTML), clean up however you like, put it inside the editor with FCK.InsertHtml and then return false so the event doesn't follow its normal processing.

There's no need at all to touch FCK internals as you can see.


Moved from SF. Original poster: alfonsoml

There is an OnPaste event, but nothing coded for the user to easily define a custom cleanup algorithm withou hacking the fck internals.

I am suggesting attaching a stub call from the onPaste event which the user can easily populate with some regexes to clean the pasted HTML with..


Moved from SF. Original poster: moonpool99

doesn't the OnPaste event work like that?


Moved from SF. Original poster: alfonsoml

comment:2 Changed 6 years ago by arczi

  • Keywords Confirmed added
function myOnPaste(fck){
	var data = fck.GetClipboardHTML();
	fck.InsertHtml(data.length +'"'+ data +'"');
	return false;
}
FCK.Events.AttachEvent( 'OnPaste', myOnPaste ) ;

This code works only in IE, in FF inserts 0"" because of:

FCK.GetClipboardHTML = function()
{
	return '' ;
}

comment:3 Changed 5 months ago by j.swiderski

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

Consequently, if a end-user pastes in HTML from a 3rd party web site, the code would need to be cleaned in some way before being saved in a content repository (on the server)

This can currently be achieved from CKEditor 4.1 with usage of ACF and inserHTml or setData functions.

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