Inserting an image at current cursor position.

  •  09-09-2007, 5:15 PM

    Inserting an image at current cursor position.

    Hi Adam,
     
    How do I retrieve the current cursor position of CE (so I can save it) and then set CE's cursor position?
    Im aware that .PasteHtml uses the current cursor position but I seem to be losing this position somewhere along the line as my code will only paste at the beginning of the Editor's document.
     
    My page has a ce which I use as an Image selector. Also, I have wrapped CE as a webpart control so users can add as many CE objects to their page as they wish. I then pass in the client side ID of the CE object that I want to paste an image in to. This all works perfectly apart from always inserting the images at the top of the CE document.
     
    I have looked at the demo code "function Window_GetDialogArguments(win)" and don't fully understand how this works or how I can taylor it for my project.

    Hope you can help? My client side function as it stands is inserted below...

    Paul.

     

    // Public Image Gallery

    function callShowPublicImageGallery(strCEID)

    {

    var editor1 = document.getElementById('<%=ceImageSelector.ClientID%>');

    editor1.FocusDocument();

    var editdoc = editor1.GetDocument();

    editor1.ExecCommand('new');

    editor1.ExecCommand('ImageGalleryByBrowsing');

    InputURL(strCEID);

    }

     

    function InputURL(str_CEID)

    {

     

    var editor1 = document.getElementById('<%=ceImageSelector.ClientID%>');

    var activeEditor = document.getElementById(str_CEID);

    var editdoc = editor1.GetDocument();

    var imgs = editdoc.images;

    if(imgs.length>0)

    {

    // Strip everything up to the third "/" -1 character to make development environment friendly. lastIndexOf() works its way backwords through string

    var imgurl = imgs[imgs.length-1].src;

    var strImageGallery = imgurl.lastIndexOf("/ImageGallery/");

    var urllength = imgurl.length;

    var newurl = imgurl.substring(strImageGallery, urllength);

    activeEditor.PasteHTML("<img src='" + newurl + "' />");

    document.getElementById(str_CEID).focus();

    }

    else

    {

    setTimeout(InputURL,500);

    }

     

    }

View Complete Thread