[dev] [horde-soc] [cvs] commit: incubator/Horde_Form/js eventlistener.js
Matt Warden
mwarden at gmail.com
Sat Jul 30 12:25:39 PDT 2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Chuck Hagenbuch wrote:
> Quoting Matt Warden <mwarden at gmail.com>:
>
>
>> Added files:
>> Horde_Form/js eventlistener.js
>> Log:
>> Saw this kind of code all over Horde's JS files, so just wrote a
>>couple functions to make things easier. I prefer the method used in
>>initBody with an array of functions, but I can't assume that there is
>>not already an attached listener, so I had to use the 'recursive'
>>method as well
>
>
> Since you're being unobtrusive, don't need to generally go with the
> addObjectEventListener() method anyway?
I don't see where you're saying unobtrusive js is being violated.
Further, addObjectEventListener is what I'm using to assign initBody
to window.onload.
> Given this, I'd encourage you
> to use the implementation in horde/js/form_helpers.js (the addEvent()
> function) instead, since it takes either a string of javascript or a
> function reference.
I've added code to optionally accept a string parameter instead of a
function name. The code in horde/js/form_helpers.js uses regular
expressions just to remove the initial 'on' in an "event" like
'onload'. The event in that instance is 'load'. Viewing things this
way both makes things a little more correct and avoids the need to use
the regular expression engine (although a simple substring() would
ahve worked just as well).
> The only reason I haven't broken this out into a seperate file is the
> lack of "require" in javascript. Ideas on dealing with that are very
> welcome. :)
It's very complicated. Jan suggested to use document.write() to add
dependencies. There are other ways that avoid document.write(). This
is one of the the things OpenJSAN (http://openjsan.org/) is working on
right now, especially in trying to avoid circular depencies. I think
they ended up using a server written in Perl to resolve the
dependencies and write the correct <script> tags to output (just to
give you an idea of how difficult and hackish it is to do such
resolving on the client-side).
- --
Matt Warden
Miami University
Oxford, OH, USA
http://mattwarden.com
This email proudly and graciously contributes to entropy.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFC69QzAQ0d4HGyPE8RAmzNAJ0QOCY9MNZnFl/S16R+bAugG1+yhQCeJV9t
KazVsiPAnI6MNoJjCV9lz7w=
=ROdI
-----END PGP SIGNATURE-----
More information about the dev
mailing list