Monthly Archives: September 2012

Paste as Plain Text for Rich Text editor in SharePoint

I got an opportunity to figure out how the Paste functionality can be extracted out with all the markups that it normally does for the Rich Text editor. There are basically 2 ways of doing it.

1. The blog of Waldek Mastykarz , which suggests to override the RTE functionality. i.e,

RTE.Cursor.paste(true)

Here, you might face a problem while delaying the script to load after SP.js. I had experiences like the site displaying “loading” notification for the ribbon and it stayed for error, due to the script.

2. I found a much easier solution, which does not need jquery or waiting for SP.js to load.

//Script to strip down the clipboard for Paste functionality.
var preKey = null;
function getKeyDown(evnt)
{
var oEvnt = evnt? evnt:window.event;
var content = clipboardData.getData("Text");
window.clipboardData.setData("text",content );
preKey = oEvnt.keyCode;
}
function cleanPreKey()
{
preKey = null;
}
document.onkeydown = getKeyDown;
document.onmousedown = getKeyDown;
document.onkeyup = cleanPreKey;

This piece of code put inside a script tag will make sure that all text copied into the clipboard are stripped away with the markups, allowing to have a paste similar to Paste as Plaintext from the Ribbon.

Advertisements