sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    WebDialogs and JavaScript events

    Scheduled Pinned Locked Moved Developers' Forum
    2 Posts 2 Posters 90 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R Offline
      RickW
      last edited by

      Developers:

      While developing my CameraControls plugin, I discovered some irritating differences between browsers and JavaScript reporting of events (such as onmousemove, onmousedown, etc). That shouldn't be surprising, but it was unexpected.

      In my particular case, the issue was with collecting a left mouse button event. The real issue (IMHO) is that the W3C spec is to blame. Here's why:

      Per W3C specs, event.button returns a value of 0-2 based on the button pushed.
      LMB returns 0
      MMB returns 1
      RMB returns 2
      These are not bit-coded, so there's no way to handle concurrent clicks (if you wanted to do that for some reason).

      In IE, event.button returns a value of 0,1,2, or 4, or combination thereof:
      No mouse button returns 0
      LMB returns 1
      RMB returns 2
      MMB returns 4
      These ARE bit-coded, so a concurrent LMB+RMB (for example) would return 3.

      The W3C spec is crazy (to me), because the default value is the same as the LMB value, making it impossible with event.button to determine a left click. However, most non-IE browsers also return event.which:
      LMB returns 1
      MMB returns 2
      RMB returns 3

      That's fine, except I ran into problems trying to call document.onmousedown=function in Safari(!). The defined method would fire once at load, and would refuse to fire subsequently no matter how many times I pressed my mouse button. Irritating.

      The workaround for that issue was to add onmousedown events to specific objects in the document (in my case, the slider buttons). That required additional code to handle other issues that in the PC version were handled more simply with event.button.

      Anyway, just some things to be aware of when trying to use DHTML+JS in WebDialogs...

      RickW
      [www.smustard.com](http://www.smustard.com)

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        I'm using jQuery to take care of such things.

        Thomas Thomassen — SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Buy SketchPlus
        Buy SUbD
        Buy WrapR
        Buy eBook
        Buy Modelur
        Buy Vertex Tools
        Buy SketchCuisine
        Buy FormFonts

        Advertisement