Code review

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Winter

    Code review

    Out of curiosity, did anyone review the second attempt I made at the DOM 2
    Events wrapper, posted at the end of last month? I posted it in the
    previous thread rather than a new one and I have the feeling that it might
    have been missed (either that, or it's so dire that no-one wants to touch
    it :)

    Subject: DOM 2 Events emulator (was: Executing in the context of
    calling function)
    Date: Wed, 31 Mar 2004 00:15:01 GMT
    Msg-ID: <opr5o9qxtd5vkl cq@news-text.blueyonder .co.uk>

    By the way, stripping whitespace and comments (many thanks to Douglas
    Crockford for his JSMIN program) reduces the combined file size by half.

    Though I state that all five files are required, that's not technically
    true; core.js and domEvents.js are required, whereas the other three are
    plug-ins. However, mouseEvents.js is dependent on uiEvents.js.

    Mike

    --
    Michael Winter
    M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
  • Reply Via Newsgroup

    #2
    Re: Code review

    Michael Winter wrote:
    [color=blue]
    > Out of curiosity, did anyone review the second attempt I made at the DOM
    > 2 Events wrapper, posted at the end of last month? I posted it in the
    > previous thread rather than a new one and I have the feeling that it
    > might have been missed (either that, or it's so dire that no-one wants
    > to touch it :)
    >
    > Subject: DOM 2 Events emulator (was: Executing in the context of
    > calling function)
    > Date: Wed, 31 Mar 2004 00:15:01 GMT
    > Msg-ID: <opr5o9qxtd5vkl cq@news-text.blueyonder .co.uk>
    >
    > By the way, stripping whitespace and comments (many thanks to Douglas
    > Crockford for his JSMIN program) reduces the combined file size by half.
    >
    > Though I state that all five files are required, that's not technically
    > true; core.js and domEvents.js are required, whereas the other three are
    > plug-ins. However, mouseEvents.js is dependent on uiEvents.js.
    >
    > Mike
    >[/color]

    I can't say I'd be good enough to make an opinion, but I was curious to
    have a look - I did a search on google for the msg id and it didn't
    return... Have I done something wrong?



    randelld

    Comment

    • Michael Winter

      #3
      Re: Code review

      On Sat, 17 Apr 2004 02:24:02 GMT, Reply Via Newsgroup
      <reply-to-newsgroup@pleas e.com> wrote:

      [snip]
      [color=blue]
      > I can't say I'd be good enough to make an opinion, but I was curious to
      > have a look - I did a search on google for the msg id and it didn't
      > return... Have I done something wrong?[/color]

      You have to enter the message ID as a special field (easiest in advanced
      search). Try

      <URL:http://groups.google.c a/groups?safe=ima ges&ie=UTF-8&oe=UTF-8&as_ugroup=com p.lang.javascri pt&as_umsgid=op r5o9qxtd5vklcq@ news-text.blueyonder .co.uk&lr=&hl=e n>

      Enjoy! :D

      Mike

      --
      Michael Winter
      M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

      Comment

      • optimistx

        #4
        Re: Code review


        "Michael Winter" <M.Winter@bluey onder.co.invali d> kirjoitti viestissä
        news:opr6kqapgc 5vklcq@news-text.blueyonder .co.uk...[color=blue]
        > Out of curiosity, did anyone review the second attempt I made at the DOM 2
        > Events wrapper, posted at the end of last month?[/color]

        I was interested, but (the famous, frightening 'but' : ( )

        the code was so long that started thinking that loading so large a library
        always makes my pages too clumsy.

        There is a need to have a good simple template for cross browser event
        handling without needing to think and create everything from scratch every
        time.

        What about



        especially the code snippet in the end:

        // shared function
        function getTargetElemen t(evt) {
        var elem
        if (evt.target) {
        elem = (evt.target.nod eType == 3) ? evt.target.pare ntNode :
        evt.target
        } else {
        elem = evt.srcElement
        }
        return elem

        }

        function functionName(ev t) {
        evt = (evt) ? evt : ((window.event) ? window.event : "")
        if (evt) {
        var elem = getTargetElemen t(evt)
        if (elem) {
        // process event here
        }
        }
        }




        Comment

        • Reply Via Newsgroup

          #5
          Re: Code review

          Michael Winter wrote:[color=blue]
          > On Sat, 17 Apr 2004 02:24:02 GMT, Reply Via Newsgroup
          > <reply-to-newsgroup@pleas e.com> wrote:
          >
          > [snip]
          >[color=green]
          >> I can't say I'd be good enough to make an opinion, but I was curious
          >> to have a look - I did a search on google for the msg id and it didn't
          >> return... Have I done something wrong?[/color]
          >
          >
          > You have to enter the message ID as a special field (easiest in advanced
          > search). Try
          >
          > <URL:http://groups.google.c a/groups?safe=ima ges&ie=UTF-8&oe=UTF-8&as_ugroup=com p.lang.javascri pt&as_umsgid=op r5o9qxtd5vklcq@ news-text.blueyonder .co.uk&lr=&hl=e n>
          >
          >
          > Enjoy! :D
          >
          > Mike
          >[/color]

          Thanks for that - I found the original post but don't think I can really
          comment on the code (though I can learn from it) due to my lack of
          experience. I do understand your objective though, and for that, I
          applaud your efforts.

          I know the code had to be purged of comments, and abbreviations used
          where possible to help with its overall physical file size but that
          makes life more difficult for someone like me to understand its proper
          usage... I always prefer comments to be part of my code, not seperate as
          it helps when I read/learn from someone elses code as I can follow the
          full program flow without seperate pages/windows.

          I am going to try and learn from your code - I am not talking about
          robbing your code, but specifically, learning from its structure and
          function/method usage.

          As a side note - I might get flamed for this however I would think your
          code might prove very useful with intranets, as opposed to over the
          internet as generally I have found intranet bandwidth, while not open to
          abuse, is generally more plentiful and an 18k size is manageable on most
          networks...

          Anyway... I do hope your hard work gets some constructive comments...

          cheers
          randelld

          Comment

          • Michael Winter

            #6
            Re: Code review

            On Sat, 17 Apr 2004 08:38:06 +0300, optimistx
            <optimistxPoist a@hotmail.com> wrote:
            [color=blue]
            > "Michael Winter" <M.Winter@bluey onder.co.invali d> kirjoitti viestissä
            > news:opr6kqapgc 5vklcq@news-text.blueyonder .co.uk...
            >[color=green]
            >> Out of curiosity, did anyone review the second attempt I made at the
            >> DOM 2 Events wrapper, posted at the end of last month?[/color]
            >
            > I was interested, but (the famous, frightening 'but' : ( )
            >
            > the code was so long that started thinking that loading so large a
            > library always makes my pages too clumsy.[/color]

            I know. The sheer enormity of the script is of major concern, but I don't
            see how to reduce its size but still maintain its functionality. The
            script is currently the only way to use event capturing with IE. I also
            recently discovered that Mozilla and IE mishandle event propagation when a
            listener causes changes to the document along the event path. The latter
            means that I'll have to *add* code to the current set to bring them into
            line with the specification.
            [color=blue]
            > There is a need to have a good simple template for cross browser event
            > handling without needing to think and create everything from scratch
            > every time.[/color]

            The script, as posted, is well-suited for complex interaction, but it is
            over-kill for simple listener registration. All that should be needed is a
            way to add multiple listeners to, and remove said listeners from, the same
            element (for the same event type), and to normalise the event interfaces.
            The former won't take that much code, but the latter makes up the bulk of
            the current script. If normalisation is made optional (if you only want to
            add and remove listeners), you still might be looking at about 4KBs
            (guess).

            I'll see if I can break it down into smaller modules.
            [color=blue]
            > What about
            >
            > http://developer.apple.com/internet/...entmodels.html[/color]

            [snipped code]

            Going by what they're talking about (rather than what they're coding),
            that could be simplified to

            function functionName( evt ) {
            if( evt = evt || window.event ) {
            /* Use "this" in place of "elem" */
            }
            }

            Though by some bizarre twist of fate, you can't do that when you use
            element.attachE vent() as IE doesn't set the this operator correctly, which
            is why I avoid it in my code (though it can be rectified with additional
            code).

            Mike

            --
            Michael Winter
            M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

            Comment

            • Michael Winter

              #7
              Re: Code review

              On Sat, 17 Apr 2004 21:17:28 GMT, Reply Via Newsgroup
              <reply-to-newsgroup@pleas e.com> wrote:

              [snip]
              [color=blue]
              > Thanks for that - I found the original post but don't think I can really
              > comment on the code (though I can learn from it) due to my lack of
              > experience. I do understand your objective though, and for that, I
              > applaud your efforts.
              >
              > I know the code had to be purged of comments, and abbreviations used
              > where possible to help with its overall physical file size but that
              > makes life more difficult for someone like me to understand its proper
              > usage... I always prefer comments to be part of my code, not seperate as
              > it helps when I read/learn from someone elses code as I can follow the
              > full program flow without seperate pages/windows.[/color]

              It's not for the faint of heart, is it. :) As I need to make some hefty
              revisions due to some browser quirks I found yesterday, I'll see about
              making the code more readable.
              [color=blue]
              > I am going to try and learn from your code - I am not talking about
              > robbing your code, but specifically, learning from its structure and
              > function/method usage.[/color]

              Go right ahead. Most of the structure uses stardard patterns that take
              advantage of common language features. Furthermore, part of the code is
              based on Richard Cornford's first post in the original thread (thank's
              again Richard), which I've since modified[1].
              [color=blue]
              > As a side note - I might get flamed for this however I would think your
              > code might prove very useful with intranets, as opposed to over the
              > internet as generally I have found intranet bandwidth, while not open to
              > abuse, is generally more plentiful and an 18k size is manageable on most
              > networks...[/color]

              Depending on what's actually used, the total size should vary between 6.7
              and 9.1KBs. However, as the library is extensible (event groups, such as
              keyboard events, can be added) a larger module would change that.

              Mike


              [1] I don't believe there were any strings attached to it. My
              acknowledgments to Lasse and Richard were out of genuine thanks, as well
              as courtesy.

              --
              Michael Winter
              M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

              Comment

              Working...