Loading ...
Sorry, an error occurred while loading the content.

mousdown event overrides/ignores click event

Expand Messages
  • Francis Hemsher
    environment: ASV3 in IE5.5+ It seems that an addEventListener( mousedown , myMouseDownFunction, false) and addEventListener( click , myClickFunction, false) on
    Message 1 of 8 , May 30, 2003
    View Source
    • 0 Attachment
      environment: ASV3 in IE5.5+


      It seems that an addEventListener("mousedown", myMouseDownFunction,
      false)
      and addEventListener("click", myClickFunction, false) on the same
      element causes the mousedown to override/ignore the click event.

      To overcome this I place my functions on the HTML side, and use a
      setTimeout to prevent the mousedown event from occurring if the
      element has already been clicked.


      Has anyone a better solution?

      Thanks,
      Francis Hemsher
    • Jim Ley
      Francis Hemsher wrote in message news:bb8kpv+afdk@eGroups.com... ... I don t see this in any environment... Are you sure you re
      Message 2 of 8 , May 30, 2003
      View Source
      • 0 Attachment
        "Francis Hemsher" <francishemsher@...> wrote in message
        news:bb8kpv+afdk@......
        > It seems that an addEventListener("mousedown", myMouseDownFunction,
        > false)
        > and addEventListener("click", myClickFunction, false) on the same
        > element causes the mousedown to override/ignore the click event.

        I don't see this in any environment...

        Are you sure you're not seeing this due to raising an alert or other thing
        which moves the click event to a different object or otherwise disables it?

        <rect id="moo" height="100" width="100"/>
        <script>
        function init() {
        moo=document.getElementById('moo')
        global=""
        moo.addEventListener("mousedown",function() {global+='mdown'}, false)
        moo.addEventListener("click",function() {global+='click'}, false)
        setInterval('alert(global)',6000)
        }
        </script>

        Acts as I would expect.

        Jim.
      • Francis Hemsher
        ... myMouseDownFunction, ... other thing ... disables it? ... Yes, I was using an alert that didn t give me the valid ouput :( So I set up a textarea to
        Message 3 of 8 , May 31, 2003
        View Source
        • 0 Attachment
          > "Francis Hemsher" <francishemsher@c...> wrote in message
          > news:bb8kpv+afdk@e...
          > > It seems that an addEventListener("mousedown",
          myMouseDownFunction,
          > > false)
          > > and addEventListener("click", myClickFunction, false) on the same
          > > element causes the mousedown to override/ignore the click event.
          >
          > I don't see this in any environment...
          >
          > Are you sure you're not seeing this due to raising an alert or
          other thing
          > which moves the click event to a different object or otherwise
          disables it?
          >
          > Jim.

          Yes, I was using an alert that didn't give me the valid ouput :(

          So I set up a textarea to monitor the output of both the mousedown
          and click functions. Here is what happens:

          MouseDown and then moving the cursor off the element provides
          the "MouseDown" output. MouseDown then a mouse up while over the
          element(not a valid click) provides a "MouseDown" + "Click" output.

          A Click provides both the "MouseDown" + "Click" output.

          This is why I have to provide a setTimeout for the MouseDown function
          and some other logic to prevent these two events from stepping on
          each other. I think ASV3 needs some improvement in order to
          correctly handle these events.

          Francis
        • Jim Ley
          Francis Hemsher wrote in message news:bba8d8+eage@eGroups.com... ... This is correct I believe. ... That sounds like a valid
          Message 4 of 8 , Jun 1, 2003
          View Source
          • 0 Attachment
            "Francis Hemsher" <francishemsher@...> wrote in message
            news:bba8d8+eage@......

            > MouseDown and then moving the cursor off the element provides
            > the "MouseDown" output.

            This is correct I believe.

            > MouseDown then a mouse up while over the
            > element(not a valid click) provides a "MouseDown" +
            > "Click" output.

            That sounds like a valid click to me, or do you mean the mousedown was over
            a different element to the mouse up?

            From http://www.w3.org/TR/SVG/interact.html
            "A click is defined as a mousedown and mouseup over the same screen
            location."
            (which is somewhat nasty definition because it means that the mousedown and
            click events can fire on different elements, which has some nasty
            consequences for scripting too.)

            Jim.
          • Francis Hemsher
            ... mousedown and ... I guess I expect the click to have priority over mousedown. My application requires that the element have onclick, onmousedown, and
            Message 5 of 8 , Jun 1, 2003
            View Source
            • 0 Attachment
              Jim Ley Wrote:
              > "A click is defined as a mousedown and mouseup over the same screen
              > location."
              > (which is somewhat nasty definition because it means that the
              mousedown and
              > click events can fire on different elements, which has some nasty
              > consequences for scripting too.)
              >

              I guess I expect the click to have priority over mousedown.

              My application requires that the element have onclick, onmousedown,
              and onmouseup, where onclick has priority, with both onmousedown and
              onmouseup working together yet independent of onclick.

              FYI, the following works OK and will give me what I need:

              functions contained as attributes in an element:

              setAttribute("onmousedown","top.tryMouseDown(evt)")
              setAttribute("onclick","top.clickEvt(evt)")
              setAttribute("onmouseup","top.mouseUpEvt()")

              with the following script on the HTML side, outputting the function
              performance to a textarea:

              var clicked=false
              var down=false
              function tryMouseDown(evt)
              {
              setTimeout("mouseDownEvt()", 300)
              down=false
              }
              function clickEvt(evt)
              {
              if(down==false)
              {
              svgTextarea.value+="click\n\r"
              clicked=true
              setTimeout("clicked=false",800)
              }
              down=false
              }
              function mouseDownEvt()
              {
              if(clicked==false && down==false)
              {
              svgTextarea.value+="mousedown\n\r"
              down=true
              }
              }
              function mouseUpEvt()
              {
              if(down==true)
              svgTextarea.value+="mouseup\n\r"
              }


              Francis
            • Jim Ley
              Francis Hemsher wrote in message news:bbdcdb+814v@eGroups.com... ... What do you mean by priority? Do you mean you expect that
              Message 6 of 8 , Jun 1, 2003
              View Source
              • 0 Attachment
                "Francis Hemsher" <francishemsher@...> wrote in message
                news:bbdcdb+814v@......
                > Jim Ley Wrote:
                > > "A click is defined as a mousedown and mouseup over the same screen
                > > location."
                > > (which is somewhat nasty definition because it means that the
                > mousedown and
                > > click events can fire on different elements, which has some nasty
                > > consequences for scripting too.)
                > >
                >
                > I guess I expect the click to have priority over mousedown.

                What do you mean by priority? Do you mean you expect that when click fires,
                mousedown shouldn't? I'm afraid that's incorrect to the spec, and very much
                not what I want. (for example you can make buttons which seperate the
                animation to make them appear depressed, with the code that activates
                onclick.)

                > functions contained as attributes in an element:
                >
                > setAttribute("onmousedown","top.tryMouseDown(evt)")
                > setAttribute("onclick","top.clickEvt(evt)")
                > setAttribute("onmouseup","top.mouseUpEvt()")

                Please don't do stuff in HTML when there is absolutely no need, especially
                using TOP! when you have no knowledge if your site is framed or not (ie top
                is not what you think it is)

                > {
                > setTimeout("mouseDownEvt()", 300)
                > down=false

                Nowhere does it say that click has to fire within 300ms of onmousedown
                firing, so whilst this may work for certain clicks there's no guarantee it
                will work any more than any other system.

                I'm still intrigued as to what it is you're doing that requires this.

                Jim.
              • Francis Hemsher
                ... screen ... nasty ... click fires, ... very much ... the ... activates ... especially ... (ie top ... onmousedown ... guarantee it ... this. The application
                Message 7 of 8 , Jun 1, 2003
                View Source
                • 0 Attachment
                  > > Jim Ley Wrote:
                  > > > "A click is defined as a mousedown and mouseup over the same
                  screen
                  > > > location."
                  > > > (which is somewhat nasty definition because it means that the
                  > > mousedown and
                  > > > click events can fire on different elements, which has some
                  nasty
                  > > > consequences for scripting too.)
                  > > >
                  > >
                  > > I guess I expect the click to have priority over mousedown.
                  >
                  > What do you mean by priority? Do you mean you expect that when
                  click fires,
                  > mousedown shouldn't? I'm afraid that's incorrect to the spec, and
                  very much
                  > not what I want. (for example you can make buttons which seperate
                  the
                  > animation to make them appear depressed, with the code that
                  activates
                  > onclick.)
                  >
                  > > functions contained as attributes in an element:
                  > >
                  > > setAttribute("onmousedown","top.tryMouseDown(evt)")
                  > > setAttribute("onclick","top.clickEvt(evt)")
                  > > setAttribute("onmouseup","top.mouseUpEvt()")
                  >
                  > Please don't do stuff in HTML when there is absolutely no need,
                  especially
                  > using TOP! when you have no knowledge if your site is framed or not
                  (ie top
                  > is not what you think it is)
                  >
                  > > {
                  > > setTimeout("mouseDownEvt()", 300)
                  > > down=false
                  >
                  > Nowhere does it say that click has to fire within 300ms of
                  onmousedown
                  > firing, so whilst this may work for certain clicks there's no
                  guarantee it
                  > will work any more than any other system.
                  >
                  > I'm still intrigued as to what it is you're doing that requires
                  this.

                  The application requires drag/drop for the element, plus a means to
                  access the element to dynamically change/delete it via an onclick
                  event. MouseDown=start drag, MouseMove=drag It,
                  MouseUp=end drag. The OnClick event exposes the elements attributes
                  and children so the user can dynamically make changes to them.

                  As for "TOP!": Recently on this list it was stated that IE6 does not
                  recognize the traditional "parent" as the means to access the
                  function on the HTML side and that "TOP" was a workaround. Since the
                  site has to work in IE5.5+, and since top also works in IE5.5, I
                  chose to go with it at this time. (Generally, functions are preferred
                  to be located on the HTML side, rather than CDATA in the svg, in
                  order to facilitate troubleshooting and maintain a seamless
                  development environment).

                  The site is more for an Intranet environment rather than something
                  for the general public. It is not intended to be accessed by
                  nonconforming environments or operating systems. This allows for a
                  good idea of the parameters that have to be addressed before it is
                  launched.

                  Francis
                • Jim Ley
                  Francis Hemsher wrote in message news:bbdffc+fj6m@eGroups.com... ... I do this without problem, I always end drag on a
                  Message 8 of 8 , Jun 1, 2003
                  View Source
                  • 0 Attachment
                    "Francis Hemsher" <francishemsher@...> wrote in message
                    news:bbdffc+fj6m@......
                    > The application requires drag/drop for the element, plus a means to
                    > access the element to dynamically change/delete it via an onclick
                    > event. MouseDown=start drag, MouseMove=drag It,
                    > MouseUp=end drag. The OnClick event exposes the elements attributes
                    > and children so the user can dynamically make changes to them.

                    I do this without problem, I always end drag on a "background rectangle"
                    aswell as the element, and since onclick guarantees that a mouseup is firing
                    somewhere within the document, which means it doesn't matter if
                    startDrag/endDrag are performed during a click event firing other than a
                    slight extra demand in processing, which probably wouldn't cost 1/3rd of
                    second in any case.

                    > (Generally, functions are preferred
                    > to be located on the HTML side, rather than CDATA in the svg, in
                    > order to facilitate troubleshooting and maintain a seamless
                    > development environment).

                    I fail to see why this is really the case, since all you're really doing is
                    adding complication to the development environment and adding potential
                    sources of errors, an external script escapes the need for having CDATA
                    sections.

                    > The site is more for an Intranet environment rather than something
                    > for the general public. It is not intended to be accessed by
                    > nonconforming environments or operating systems.

                    I guess being in an environment without strong disabled rights legislation,
                    for me that certainly wouldn't be an option (discriminating against an
                    employee or potential employee isn't a good idea.) Also of course being in a
                    situation where your application is so important to the environment that
                    you'll have the power to dictate the environment, and prevent MS upgrades -
                    as you note parent/top behaviour changed with the IE6 upgrade.

                    Jim.
                  Your message has been successfully submitted and would be delivered to recipients shortly.