469,915 Members | 2,457 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,915 developers. It's quick & easy.

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: <op**************@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.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #1
6 1451
Michael Winter wrote:
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: <op**************@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


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/groups?hl=en...uk&btnG=Search

randelld
Jul 23 '05 #2
On Sat, 17 Apr 2004 02:24:02 GMT, Reply Via Newsgroup
<re****************@please.com> wrote:

[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/gr************************************************ ********************************************@news-text.blueyonder.co.uk&lr=&hl=en>

Enjoy! :D

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #3

"Michael Winter" <M.******@blueyonder.co.invalid> kirjoitti viestissä
news:op**************@news-text.blueyonder.co.uk...
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/...entmodels.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
}
}
}


Jul 23 '05 #4
Michael Winter wrote:
On Sat, 17 Apr 2004 02:24:02 GMT, Reply Via Newsgroup
<re****************@please.com> wrote:

[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/gr************************************************ ********************************************@news-text.blueyonder.co.uk&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
Jul 23 '05 #5
On Sat, 17 Apr 2004 08:38:06 +0300, optimistx
<op*************@hotmail.com> wrote:
"Michael Winter" <M.******@blueyonder.co.invalid> kirjoitti viestissä
news:op**************@news-text.blueyonder.co.uk...
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.


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

http://developer.apple.com/internet/...entmodels.html


[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

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #6
On Sat, 17 Apr 2004 21:17:28 GMT, Reply Via Newsgroup
<re****************@please.com> wrote:

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

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Arvie | last post: by
reply views Thread by gs-code-review-bounces | last post: by
18 posts views Thread by Ben Hanson | last post: by
3 posts views Thread by Filippo | last post: by
239 posts views Thread by Eigenvector | last post: by
3 posts views Thread by JeanDean | last post: by
10 posts views Thread by Jo | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.