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

[Solved] onpaste AttachEventHandler in Prometheus

3 Answers 256 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Bryon
Top achievements
Rank 1
Bryon asked on 02 Jan 2008, 07:23 PM
I am trying to attach an event handler for onpaste to the prometheus radeditor.   The  alert('client load') pops up as expected.  However, I anticipate the attached event handler for onpaste to popup alert('paste') when a user pastes. 

alert('paste') never appears to be executing.  How can I get the following code to work with the prometheus editor control?

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ContentFilterTest.aspx.cs" Inherits="Editor_ContentFilterTest" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager id="ScriptManager" runat="server"/>   
       
    <telerik:radeditor runat="server" ID="RadEditor1" SkinID="BasicSetOfTools" StripFormattingOnPaste="NoneSupressCleanMessage" OnClientLoad="OnClientLoad">
        <Content>
            <strong><br />&nbsp;Switch to Html mode to run the content filter.<br />&nbsp;You will see that the casing is changed to upper case.</strong>
        </Content>
    </telerik:radeditor>
    <script type="text/javascript">
    function OnClientLoad(editor)
    {
        alert('client load');
        editor.AttachEventHandler ("onpaste", function ()
        {
            alert('paste');
            //the event is called before the paste but we need to execute after that
            window.setTimeout("cleanUpText()", 100);
        });
    }
    function cleanUpText()
    {
        var text = editor.GetHtml();
        alert('the text we have from edxitor is: ' + text);
        var clean = text.replace(/<div[^>]*>(.*?)<\/div[^>]*>/ig, "$1")
        editor.SetHtml(clean);
    }
    </script>




    </form>
</body>
</html>

3 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 03 Jan 2008, 01:46 PM
Hi Bryon,

Here is how to convert the code to work with RadEditor "Prometheus":

  <asp:ScriptManager id="ScriptManager" runat="server"/>
  <script type="text/javascript">
  function OnClientLoad(editor, args)
  {
     Telerik.Web.DomElement.addExternalHandler(editor.get_document().body, "beforepaste",
     function(e)
     {
         window.setTimeout(function()
         {
                  cleanUpText();
         }, 100);
      }         
    );
 
      function cleanUpText()
      {
            var text = editor.get_Html();
            //alert('the text we have from edxitor is: ' + text);
            var clean = text.replace(/<div[^>]*>(.*?)<\/div[^>]*>/ig, "$1")
            editor.set_Html(clean);
      }
  }
  </script>
 
 
  <telerik:radeditor runat="server" ID="RadEditor1" OnClientLoad="OnClientLoad" StripFormattingOptions="NoneSupressCleanMessage">
    <Content>
        <strong><br />&nbsp;Switch to Html mode to run the content filter.<br />&nbsp;You will see that the casing is changed to upper case.</strong>
    </Content>
  </telerik:radeditor>


Kind regards,
Rumen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Bryon
Top achievements
Rank 1
answered on 03 Jan 2008, 04:44 PM

Thank you for the help.  I have IE6 on my machine and had to modify the code a little to get it to work.  The following now works in IE6.  However, it needs to work in Firefox 2.x also.  What is needed to get this to work in Firefox?

<%

@ Control Language="C#" AutoEventWireup="true" CodeBehind="ContentEditor.ascx.cs"

Inherits="FalconWeb.UserControls.ContentEditor" %>

<%

@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>

<%

@ Register src="ContentEditImageUploadControl.ascx" tagname="UploadControl" tagprefix="upload" %>

<

telerik:radeditor runat="server" ID="SectionEditor"

SkinID="DefaultSetOfTools"

Skin="Monochrome"

BackColor="white"

Height="589px"

Width="589px"

EditModes="Design"

StripFormattingOnPaste="NoneSupressCleanMessage"

OnClientLoad="OnClientLoad"

>

<Content>

</Content>

</

telerik:radeditor>

<

script type="text/javascript">

function OnClientLoad(editor, args)

{

Telerik.Web.DomElement.addExternalHandler(editor.get_document().body, "paste",

function(e)

{

window.setTimeout(function()

{

cleanUpText();

}, 100);

});

function cleanUpText()

{

var text = editor.get_Html();

//alert('the text we have from edxitor is: ' + text);

var clean = text.replace(/<img.*?>/ig, "");

editor.set_Html(clean);

}

}

</

script>

 

0
Rumen
Telerik team
answered on 03 Jan 2008, 05:30 PM
Hello Bryon,

Firefox and the rest of Gecko browsers' do not offer the onPaste event, due to security restrictions: the clipboard operations are forbidden and they prevent to execute paste/copy/cut commands from a script. You can see the following Mozilla's article on the topic: Setting Prefs for the Mozilla Rich Text Editing Demo.

As a workaround you can clean the img tags in the content on the server by using the String.Replace method.

Best regards,
Rumen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Editor
Asked by
Bryon
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Bryon
Top achievements
Rank 1
Share this question
or