SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Member Zanicar's Avatar
    Join Date
    Aug 2006
    Location
    Pretoria, South Africa
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Data Application: Disabling text select in Opera

    Hi,

    I am creating a data application where users must be able to select table rows to perform actions on it... Think in terms of Yahoo Mail. I have written a script to select clicked rows and to deselect them when clicked again. I also added shift button functionality and 'escape' to deselect all.

    However my problem arise with my click and drag to select multiple rows. It works fine in FF and IE, I have managed to disable text select in these browsers because it looks awry, but have not managed to achieve the same effect in Opera.

    Anyone know how perhaps?

    Here's my JavaScript code:
    Code:
    function init() {
      if (!document.getElementById) return;
      addEvent(document, 'keydown', aKeyWasPressed, false);
      addEvent(document, 'keyup', aKeyWasReleased, false);
      addEvent(document, 'mousedown', setMouseDown, false);
      addEvent(document, 'mouseup', setMouseUp, false);
      
      var browseTable = document.getElementById('browse');
      for (var i = 0; i < browseTable.rows.length; i++) {
        browseTable.rows[i].onselectstart = function() {return false;};
        browseTable.rows[i].unselectable = "on";
        browseTable.rows[i].style.MozUserSelect = "none";
        browseTable.rows[i].style.cursor = "default";
        addEvent(browseTable.rows[i], 'mousedown', selectRow, false);
        addEvent(browseTable.rows[i], 'mouseover', getMouseDown, false);
        selectedRows[i] = false;
      }
    }
    Thanks

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,154
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)

    scripts in Opera

    I'm no expert so I can only offer ideas.
    What are you "addEvent"ing to? Maybe the Fx and IE browsers add to "window" by default, but Opera needs "window.opera" ??
    Maybe instead of having the events bubble, the "false", try having them capture, "true", instead.

  3. #3
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    window.opera is only used to detect Opera and to differentiate between different versions of Opera.

    I've run into this problem with Opera before and still do not know the solution. Walter Zorn seems to have solved it in this script, but I could not figure out what fixed it and he did not respond to the email I sent him asking how he did it.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  4. #4
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try event.preventDefault() in the mousedown listener

    Btw... window.opera has some other very cool uses, such as "UserJavascript"

  5. #5
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does that work in Opera 7.x?
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  6. #6
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Surely you are not still using O7 ?!?!

  7. #7
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I still test in it. Don't worry, I have Opera 8.01, 8.54, and 9.02 installed too. My primary browser is Firefox, though.

    So will you answer my question now?
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  8. #8
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


    Surprisingly, I still have a copy of O7.54. And no, this technique does not work in it.
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Template</title>
    <style type='text/css'>
    </style>
    <script type='text/javascript'>
    window.onload = function()
    {
      var ele = document.getElementById('unselectable');
      // This works in Opera9 and FireFox1.5, but not IE6:
      ele.onmousedown = xPreventDefault;
      // This works in IE6:
      ele.onmousemove = xPreventDefault;
      // Neither of the above work in Opera7.54
    }
    function xPreventDefault(e)
    {
      if (e && e.preventDefault) e.preventDefault();
      else if (window.event) window.event.returnValue = false;
    }
    </script>
    </head>
    <body>
    
    <h2>But I must explain...</h2>
    <div id='unselectable'>
    <p>This paragraph is <b>not</b> selectable.</p>
    </div>
    <h2>Sed ut perspiciatis</h2>
    <p>This paragraph <b>is</b> selectable.</p>
    
    </body>
    </html>
    So, together, we have definitely answered Zanicar's question

  9. #9
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    At least I didn't make some silly mistake so that it wouldn't work.

    I don't worry too much about it since it's an older version of Opera, but I'm still interested in hearing about it if anyone figures out how to do that in Opera 7.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  10. #10
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,810
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Older versions of Opera don't allow you to prevent your visitor from selecting text. Most of the options to handle those types of things were added in version 8.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  11. #11
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, well Walter Zorn somehow managed it in Opera 7.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  12. #12
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,810
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Is there a page where he provides an example?
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  13. #13
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's this one that I linked to in my first reply.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.


Bookmarks

Posting Permissions

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