This is a migrated thread and some comments may be shown as answers.

Paste Consistancy in all main browsers

4 Answers 155 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Diane
Top achievements
Rank 1
Diane asked on 23 Feb 2011, 04:50 PM
We would like our application to work the same in all the different browsers. The RadEditor behaves differently in different browsers when pasting. How can we make the RadEditor's pastes behave the same in IE8,Firefox, Chrome and Safari?

1 - We are using the "Paste From Word,Strip Font" and the "Paste Plain Text" buttons on the RadEditor menu bar. And we would like ONLY those paste options to be available to our users. In IE, how do we stop the RadEditor's RightClick context menu from showing all of the other paste options? How do we make it only show the "Paste From Word,Strip Font" and "Paste Plain Text" paste options? or show only "Paste", "Paste From Word,Strip Font" and the "Paste Plain Text".

2- Is there a way to control the RightClick context menu that appears in IE? How can we make that context menu appear in Firefox, Safari and Chrome? Also how do we make that context menu Not appear in IE?

3 - Is there a way to prevent the paste dialog from opening in Firefox, Chrome and Safari? Or, is there a way to make the paste dialog Open in IE? We would like the paste action to be consistent. If there is a way to do both, that would be great to know.

4 - We use the xml tools file to define what buttons will appear on the RadEditor tool bar. Is there a way in the code behind to change which buttons appear on the RadEditor tool bar?
 
btw, we are using C#.

4 Answers, 1 is accepted

Sort by
0
Alexander
Top achievements
Rank 1
answered on 23 Feb 2011, 11:04 PM
Why does StripFormattingOptions.AllExceptNewLines not function as we expect? Why does it not preserve new lines?
For example, new lines are not preserved when the new lines are created with paragraph tags, or with list item tags, or when the content is copied from a formatted word document. The new lines should be preserved, but they are not.

Is there a StripFormattingOptions setting that would result in the same pasted output as the "Paste Plain Text" paste button? That would be ideal.
0
Rumen
Telerik team
answered on 28 Feb 2011, 02:57 PM
Hi Alexander,

Straight to the points:
1) The browser's context menu in Firefox, Chrome and Safari is enabled on purpose so that the users can directly spellcheck the content using the built-in browser's spellchecker.
Another important reason to display the browser's context menu in these browsers is that the Cut, Copy and Paste commands could not be executed via script (JavaScript) and the context menu of RadEditor are partially unusable in these browsers. The Cut, Copy and Paste buttons of the browser's context menu work fine.

If you want to enable the PasteFromWordNoFontsNoSizes and PastePlainText items in the context menus for body / p elements use the following markup:
<telerik:RadEditor ID="RadEditor1" runat="server">
    <ContextMenus>
        <telerik:EditorContextMenu TagName="BODY">
            <telerik:EditorTool Name="PasteFromWordNoFontsNoSizes" />
            <telerik:EditorTool Name="PastePlainText" />
        </telerik:EditorContextMenu>
        <telerik:EditorContextMenu TagName="P">
            <telerik:EditorTool Name="PasteFromWordNoFontsNoSizes" />
            <telerik:EditorTool Name="PastePlainText" />
        </telerik:EditorContextMenu>
    </ContextMenus>
</telerik:RadEditor>

You can see how to define the context menus in the toolsfile in this article: Context Menus.

2) see above points. If you would like you can disable the editor's content menus in IE using the following code:

<script type="text/javascript">
    function OnClientLoad(editor) {
        if ($telerik.isIE) editor.get_toolAdapter().enableContextMenus(false);
    }
</script>
<telerik:RadEditor ID="RadEditor" OnClientLoad="OnClientLoad" runat="server"/>

3) To protect users' private information, unprivileged scripts cannot invoke the Cut, Copy, and Paste commands in the Mozilla rich text editor as well as to obtain the content from the clipboard. For this reason RadEditor pops up a dialog box where the user can paste the content to be stripped. IE does not expose such limitation and for this reason the dialog is not needed. Nevertheless, if you like to show the PasteFromWordNoFontsNoSizes and PastePlainText dialogs in IE put the following JavaScript code under the RadEditor's declaration:

<telerik:RadEditor ID="RadEditor" runat="server" ... />
<script type="text/javascript">
    Telerik.Web.UI.Editor.CommandList.PasteFromWord =
    Telerik.Web.UI.Editor.CommandList.PasteFromWordNoFontsNoSizes =
    Telerik.Web.UI.Editor.CommandList.PasteAsHtml = function (commandName, editor, commandArgs) {
        var cleanAndPaste = function (content, restorePoint) {
            var cleanedText = "";
            var stripOptions = editor.get_stripFormattingOptions();
            if (commandName == "PasteFromWord") {
                if (stripOptions == Telerik.Web.UI.StripFormattingOptions.None || (stripOptions & Telerik.Web.UI.StripFormattingOptions.ConvertWordLists))
                    content = Telerik.Web.UI.Editor.Utils.convertWordLists(content);
                cleanedText = Telerik.Web.UI.Editor.Utils.stripFormatting(content, "WORD");
            }
            else if (commandName == "PasteFromWordNoFontsNoSizes") {
                if (stripOptions == Telerik.Web.UI.StripFormattingOptions.None || (stripOptions & Telerik.Web.UI.StripFormattingOptions.ConvertWordLists))
                    content = Telerik.Web.UI.Editor.Utils.convertWordLists(content);
                cleanedText = Telerik.Web.UI.Editor.Utils.stripFormatting(content, "WORD_ALL");
            }
            else {
                cleanedText = Telerik.Web.UI.Editor.Utils.convertText2Html(content);
            }
 
            //Problem with paste from word - sets cursor in beginning of editor and "eats" one letter from the existing text eachtime
            if (restorePoint) {
                restorePoint.select();
            }
            if (cleanedText) {
                editor.pasteHtml(cleanedText, commandName);
            }
        }
         
         
            var callbackFunction = Telerik.Web.UI.Editor.CommandList.getCallbackFunction(commandArgs, function (sender, args) {
                cleanAndPaste(args.get_content());
            });
            editor.showDialog("CleanPasteHtmlContent", { dialogTitle: editor.getLocalizedString(commandName) }, callbackFunction);
        }
 
        Telerik.Web.UI.Editor.CommandList.PastePlainText = function (commandName, editor, commandArgs) {
            var cleanAndPaste = function (content) {
                if (content) {
                    var plainText = content.replace(/\&/g, "&").replace(/</g, "<").replace(/>/g, ">");
                    plainText = Telerik.Web.UI.Editor.Utils.replaceNewLineWithBr(plainText);
                    if (plainText) editor.pasteHtml(plainText, commandName);
                }
            }
 
                //NEW: Developer Callback Function support
                var callbackFunction = Telerik.Web.UI.Editor.CommandList.getCallbackFunction(commandArgs, function (sender, args) {
                    cleanAndPaste(args.get_content());
                });
                editor.showDialog("CleanPasteTextContent", {}, callbackFunction);
                return false;
             
        }
</script>

4) See these articles: http://www.telerik.com/help/aspnet-ajax/addingstandardbuttons.html and http://www.telerik.com/help/aspnet-ajax/removingtoolbarbuttons.html.

5) The StripFormattingOptions.AllExceptNewLines option preserves only <br/> tags, not <p>, /n or other symbols and tags. If you need more precise stripping you can write your own content filter or attach to the OnClientPasteHtml event and implement the needful stripping mechanism.

All the best,
Rumen
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
rutika
Top achievements
Rank 1
answered on 26 Jun 2014, 05:35 AM
Hello  Rumen,
  Thanks for posting alternative to what Mozilla supports but not IE. I used your script to get popup for copy paste  . Its working as i wanted . but the only thing i want now is when i copy paste in rad editor it clears the matter its consisting. I want previous text as it is even after i paste new code in editor.Any kind of help is highly appreciated. Looking forward to reply asap.
thanks and regards.
0
Ianko
Telerik team
answered on 27 Jun 2014, 03:42 PM
Hi Rutika,

I am not sure if I understand exactly the encountered problem. If the content is stripped with some custom logic on paste, how does preserving of the original text would be implemented and used in the RadEditor control?

It would be better if you could open a proper support ticket to us with some code sample attached or simple project and further details, so that we could be able to recreate the problem and investigate it properly.

Regards,
Ianko
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Editor
Asked by
Diane
Top achievements
Rank 1
Answers by
Alexander
Top achievements
Rank 1
Rumen
Telerik team
rutika
Top achievements
Rank 1
Ianko
Telerik team
Share this question
or