Code review

M

Michael Winter

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: <[email protected]>

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
 
R

Reply Via Newsgroup

Michael said:
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: <[email protected]>

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

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?

http://groups.google.ca/[email protected]&btnG=Search

randelld
 
O

optimistx

Michael Winter said:
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 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

http://developer.apple.com/internet/webcontent/eventmodels.html

especially the code snippet in the end:

// shared function
function getTargetElement(evt) {
var elem
if (evt.target) {
elem = (evt.target.nodeType == 3) ? evt.target.parentNode :
evt.target
} else {
elem = evt.srcElement
}
return elem

}

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

Reply Via Newsgroup

Michael said:
On Sat, 17 Apr 2004 02:24:02 GMT, Reply Via Newsgroup

[snip]
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?


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

<URL:http://groups.google.ca/[email protected]&lr=&hl=en>


Enjoy! :D

Mike

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
 
M

Michael Winter

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.

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.
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.

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.

[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.attachEvent() 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
 
M

Michael Winter

On Sat, 17 Apr 2004 21:17:28 GMT, Reply Via Newsgroup

[snip]
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.

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.
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.

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].
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...

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,951
Messages
2,570,113
Members
46,698
Latest member
alexxx

Latest Threads

Top