Re: How to get SelectionStart, SelectionEnd and SelectionRange

  •  08-21-2007, 12:47 PM

    Re: How to get SelectionStart, SelectionEnd and SelectionRange

    Adam,
     
    We are not clever enough to understand the code at this URL, but I'm sure you are: http://dev.plone.org/collective/browser/PloneStickies/branches/multi-stickies-branch/skins/stickies/kupuhelpers.js?rev=8343.
     
    Open it and go to Line 373: function MozillaSelection(document) {
     
    It contains everything we need to get and set the focus using Mozilla browsers and start/end integers. We've figured out almost everything except the final piece of the puzzle - calling focus to display the cursor at its new position.
     
    Have a look at the code below and see if you can figure out the final piece:
     
     
    var editor1 = document.getElementById('');
    var editwin = editor1.GetWindow();
    var editwinsel=editwin.getSelection();
     
    //get the range
    var range;
    try { range=editwinsel.getRangeAt(0); } catch (e) { }
     
    //notify the start and end offsets
    alert(range.startOffset);
    alert(range.endOffset);
     
    and how to collapse the range and set the focus:
     
    //collapse to a single point
    try { editwinsel.collapseToStart(); } catch (e) {}
    try { editwinsel.collapseToEnd(); } catch (e) {}
     
    //and set the focus
    editwin.focus();
     
    //get the container
    var startNode = range.startContainer;//This is probably where the error is
     
    And this resets the range to absolute positions 15 and 30
     
    //reset the range positions
    range.setStart(startNode,15);
    range.setEnd(startNode,30);
     
    //report the new range:
    alert(range.startOffset);
    alert(range.endOffset);
     
    ??? How to now set the focus in the window?
     
    Can you give us the answer, please?
View Complete Thread