how can my page recognise which "div" is selected

Last post 09-09-2009, 3:00 AM by goh6613. 2 replies.
Sort Posts: Previous Next
  •  09-04-2009, 10:37 PM 55385

    how can my page recognise which "div" is selected

    hi all
     
    i got a problem now in using cute editor.....
     
    for example i add 1 layer "div1" ....
     
    and i wanna add another layer "div2" .......
     
    the problem is
     
    if "div1" is selected, and "add layer" button is click.....it will replace "div1" to "div2" instead of add new layer "div2" to it
     
    my idea is i would like to block the user to click on the "add layer" button, if there is any "div" , "button", "image" is selected
     
    is it possible ?
     
    thanks
  •  09-06-2009, 2:57 AM 55396 in reply to 55385

    Re: how can my page recognise which "div" is selected

    HI goh6613,
     
    Try this way
     
    1. <%@ Page Language="C#" %>   
    2.   
    3. <%@ Register Namespace="CuteEditor" Assembly="CuteEditor" TagPrefix="CE" %>   
    4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   
    5.   
    6. <script runat="server">   
    7.       
    8. </script>   
    9.   
    10. <html xmlns="http://www.w3.org/1999/xhtml">   
    11. <head id="Head1" runat="server">   
    12.     <title>Untitled Page</title>   
    13. </head>   
    14. <body>   
    15.     <form id="form1" runat="server">   
    16.         <CE:Editor ID="Editor1" runat="server">   
    17.         </CE:Editor>   
    18.     </form>   
    19. </body>   
    20. </html>   
    21.   
    22. <script>   
    23. var editor1=document.getElementById('<%= Editor1.ClientID %>');   
    24. function getSelectedHTML(){   
    25.       // get the active editor window   
    26.       var editwin = editor1.GetWindow();   
    27.       // get the active editor document   
    28.       var editdoc = editor1.GetDocument();   
    29.       var rng=null,html="";    
    30.       if (document.selection && document.selection.createRange){   
    31.         rng=editdoc.selection.createRange();   
    32.         html=rng.htmlText||"";   
    33.       }else if (window.getSelection){   
    34.         rng=editwin.getSelection();   
    35.   
    36.         if (rng.rangeCount > 0 && window.XMLSerializer){   
    37.           rng=rng.getRangeAt(0);   
    38.           html=new XMLSerializer().serializeToString(rng.cloneContents());   
    39.         }   
    40.       }   
    41.       return html;   
    42.  }   
    43.     
    44.  function CuteEditor_OnCommand(editor,command,ui,value)   
    45.  {   
    46.  var editdoc = editor1.GetDocument();   
    47.   if(command=="InsertLayer")   
    48.         {   
    49.         if(editdoc.selection.type=="Control")   
    50.           {   
    51.              return true;   
    52.           }   
    53.         }   
    54.   }   
    55. </script>  
    Regards,
     
    ken
  •  09-09-2009, 3:00 AM 55457 in reply to 55396

    Re: how can my page recognise which "div" is selected

    hi kenneth
     
    right now my problem is......
     
    i try not allow the user to add new layer when one of the layer in cute editor panel is selected....
     
    i try to control like this
     

    var str = getSelectedHTML(); where the getSelectedHTML() function is follow your previous post
    if(str.toLowerCase().substring(0,4)!='<div')

    {

    addInput();

    }

    else

    {

    alert('Please make sure that no text is selected !');

    }

    return false;

    }
     
    but it still will replace selected layer with new layer....
     
    can u help me in this ?
     
    thanks
View as RSS news feed in XML