trap paste command --urgent

Last post 01-23-2009, 9:21 AM by cutechat. 9 replies.
Sort Posts: Previous Next
  •  01-14-2009, 10:18 AM 47734

    trap paste command --urgent

       
     
    Hi Adam,
     
    The requirement is something like when user click on the paste button and try to paste some content which contains some string say "Position:absolute" then need to prompt some message saying the "this containspositionas absolute".
     
    Now for this I can trap the Paste command with
    CuteEditor_OnCommand(editor,command,ui,value).
     
    but how to get the content which user is about to paste.
     
    in above on debug I found value and ui is comming as null
     
     
     
    I'm using followin code to trap the command.
     

    <script language="JavaScript" type="text/javascript" >

    var editor1=document.getElementById("<%=Editor1.ClientID%>");

    if(editor1.IsReady)CuteEditor_OnInitialized(editor);

     

     

    function CuteEditor_OnCommand(editor,command,ui,value)

    {

    //handle the command by yourself

    if(command=="Paste")

    {
    //Some code--- IsContainsAbsoluteposition(Contentstring)???? how to get this Contentstring

    var answer = confirm("Click OK to stop this command.")

    if (answer){

    return true;

    }

    else{

    return false;

    }

    }

    }

     

     

    </script>
     
    Thanks
  •  01-14-2009, 1:35 PM 47741 in reply to 47734

    Re: trap paste command --urgent

  •  01-15-2009, 2:17 AM 47759 in reply to 47741

    Re: trap paste command --urgent

    Hi adam,
     
    I think you have not read properly what I've asked for.
     
    also the link you are refering is having same code that I've mentioned in my query.
     
    The thing I 'm asking for is
     
    1. a way to get the HTML content which is about to be pasted? might be in clipboard or some where else.
     
    2. how cute editor use these paste commands. means from where it gets the value(HTML content) to be pasted on editor?
     
     
     
     
  •  01-15-2009, 9:47 AM 47778 in reply to 47759

    Re: trap paste command --urgent

      function getSelectedHTML(){
          var rng=null,html="";

          if (document.selection && document.selection.createRange){
            rng=editdoc.selection.createRange();
            html=rng.htmlText||"";
          }else if (window.getSelection){
            rng=editwin.getSelection();

            if (rng.rangeCount > 0 && window.XMLSerializer){
              rng=rng.getRangeAt(0);
              html=new XMLSerializer().serializeToString(rng.cloneContents());
            }
          }
          return html;
        }
    You can use the above code to get the html code from the current selection or you can write your own.
     

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  01-19-2009, 4:10 AM 47849 in reply to 47778

    Re: trap paste command --urgent

    I need HTML content which is ABOUT TO BE PASTED(ITS IN CLIPBOARD not pasted on EDITOR)?
     
    IS THIS CLEAR WHAT I'M ASKING FOR?
     
    ALSO
     
    2. how cute editor use these paste commands. means from where it gets the value(HTML content) to be pasted on editor?
  •  01-19-2009, 9:38 AM 47857 in reply to 47849

    Re: trap paste command --urgent

    Hi,
     
    What action do you need ?
     
    1. click the paste button
     
    2. use CTRL+V key
     
    they are abosolute different.
     
    We did not provide event for CTRL+V yet.
     
    If you need, we will add it in a coming upgrate.
     
    Regards,
    Terry
  •  01-21-2009, 12:10 AM 47910 in reply to 47857

    Re: trap paste command --urgent

      Hi,
     
    When clicked on paste button,I want to check whether the HTML content that is about to paste contains some tags like "position:absolute". if yes then will discard past else allow paste.
     
    and to acheive this I amusing JS code as I pasted above in this thread itself. again I'm pasting it here.
     
    <script language="JavaScript" type="text/javascript" >
    var editor1=document.getElementById("<%=Editor1.ClientID%>");
    if(editor1.IsReady)CuteEditor_OnInitialized(editor);

    function CuteEditor_OnCommand(editor,command,ui,value)

    {        //handle the command by yourself

            if(command=="Paste")
           {
          //Some code--- IsContainsAbsoluteposition(Contentstring)???? how to
           get this Contentstring
              var answer = confirm("Click OK to stop this command.")
              if (answer)
              {
                      return true;
              }
              else{return false;}
           }
    }
    </script>
     
     this code is to trap the paste command which is working, but how to get the HTML content which is about to paste? so that I can check the content before it gets pasted on editor.
     
    Hopefully now you guys understand what I'm asking for.

    Do you have any chat/phone support for "cuteEditor for ASP.Net"? if yes please provide the details.
     
    Thanks.
     
     
  •  01-23-2009, 1:53 AM 47999 in reply to 47910

    Re: trap paste command --urgent

    Hi,
     
    this code may help you :
     
     var r = document.body.createTextRange() ;
     r.moveToElementText(element) ;
     r.execCommand("Paste") ;
     var data = element.innerHTML ;
     
    Regards,
    Terry
  •  01-23-2009, 3:55 AM 48003 in reply to 47999

    Re: trap paste command --urgent

    Please check the following code....its not working...saying "element is not defined"
     
    function CuteEditor_OnCommand(editor,command,ui,value
    {
        var editor1=document.getElementById("<%=Editor2.ClientID%>");
        if(command=="Paste")
        {
            var r = document.body.createTextRange() ;
            r.moveToElementText(element) ;
            r.execCommand("Paste") ;
            sHTML = element.innerHTML ;
            alert(sHTML);
            if (sHTML.search(/position: absolute/)!=-1 || sHTML.search(/position:absolute/)!=-1 || sHTML.search(/position : absolute/)!=-1 || sHTML.search(/position :absolute/)!=-1)
            {
                var answer = confirm("The Content you paste might not display properly. Click OK to continue.")
                if (answer)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return true;
            }
        }
    }
  •  01-23-2009, 9:21 AM 48010 in reply to 48003

    Re: trap paste command --urgent

    Hi,
     
    you need create that element at first.
     
    for example:
     
    var element=document.createElement("DIV");
    element.style.position="absolute";
    element.style.overflow="hidden";
    element.style.width="1px";
    element.style.height="1px";
    document.body.appendChild(element);
    var r = document.body.createTextRange() ;
    r.moveToElementText(element) ;
    r.execCommand("Paste") ;
    sHTML = element.innerHTML ;
    alert(sHTML);
    Note: this is IE only. other browsers have difference API for the TextRange
     
    Regards,
    Terry
     

     
     
View as RSS news feed in XML