Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    IBM
    IBM is offline
    New Coder
    Join Date
    Jul 2002
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Using a Range object

    *sigh*...
    Well, I'd like to say I fully understand the range object..but I don't.

    At the moment I'm having trouble figuring out how to get a selection using mousedown and mouseup. I can't use the selection object, it won't work in opera.. at least not in the examples I came across.

    So my theory was to use the range object for selections use mouse events.
    At the moment I have a pitiful theory for a function that will be called on window.load.

    It should essentially capture onmousedown and then set the start of the range, then onmouseup set the range end. The problem is, if I understand setStart() and setEnd() properly, they require paramaters..but I don't know what paramters to pass setStart and setEnd.

    Ok, what do you guys think about something like:

    1) add mousedown and mouseup event handlers to the textarea
    maybe something like textarea.addEventListener("mousedown"); etc.

    2) On mousedown create a range, setStart(this.mousedown);
    //at this point it's guess work for me, I'm not sure how to tell the range
    //to start at the mousedown position. I'm not sure what paramater to pass.

    3) On mouseup end the range, setEnd(this.mouseup);
    //Same thing goes for this part of the script,
    //I'm not sure how to tell the range to end at the mouseup position.

    4) Use startContainer to make sure actions can only be performed when the
    parent container is a textarea.
    //I'm guessing this part won't be to difficult, I just hope most browsers
    //understand startContainer();.

    5) If it was as easy as pseudo code I'd be done by now..

    Any help is appreciated...
    At the moment I'm just kind of stuck.. don't know where to go from here. And everywhere I look browser compatibility is a big issue. I had hoped to use the selection object.. too bad opera doesn't like it...

  • #2
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    Opera does not support DOM2 Range... nor does it expose any selection objects as a range (as it doesn't support DOM2 Range.... afterall). You're only get Mozilla compatibility with this script, as it is the only browser which implements that much DOM.

  • #3
    IBM
    IBM is offline
    New Coder
    Join Date
    Jul 2002
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    arg... :P

    There's just no winning is there..

    Sigh...fine.
    Forget Opera, I'm not going to bother to fight my way through this.
    I'll instead just have this work on explorer and mozilla.

    But what do you think about the steps I've recorded above?
    Do they sound like I'm on the right track?

    If yes or no, could you or someone with range object experience help me in getting this started. Specifically I would like to figure out how to define the start of a range on mouse down. Mouse up I'm guess will be very similar so I won't need much help there.

    Thanks for responding and for letting me know opera doesn't suporrt the range object.
    heh heh..opera really doesn't make it easy to create an editor does it.. you can't create a rich text editor because designmode isn't supported, and you can't use the range object..what else is there aside from java and the sort?

    once again thanks


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •