Last active
December 16, 2015 15:49
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pasteAsPlainTextWithNoFormatting() { | |
var cursorLocation = RTE.Cursor.get_range(); | |
var copiedData = window.self.clipboardData.getData('Text'); //Copy content from clipboard | |
var copiedDataSpan = document.createElement('span'); | |
copiedDataSpan.setAttribute('id', 'copiedData'); | |
copiedDataSpan.innerText = copiedData; //add clipboard content to new span element | |
cursorLocation.deleteContent(); | |
cursorLocation.insertBefore(copiedDataSpan); //add the content with the span element at the cursor location | |
var rawContent = $ribbon('#copiedData').html(); //find that span | |
var cleanContent = rawContent.replace(/<[^>]*>/gi, ''); //remove all the formatting | |
$ribbon('#copiedData').html(cleanContent);//add the content back | |
RTE.RteUtility.removeNodeAndKeepChildNodes(copiedDataSpan);//remove the span by keeping the data | |
RTE.Cursor.update(); //update the cursor position | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment