Corrected addEvent function

Most of my unobtrusive DHTML scripts use the addEvent function, which has been copied from all over the place. The Opera people have very kindly dropped me a mail to tell me that it’s wrong; it uses the line

obj.addEventListener(evType, fn, true);

when instead that line should be

obj.addEventListener(evType, fn, false);

The “true” and “false” bits relate to whether the event is “capturing” or not. Firefox has a bug where it treats “capturing” and “non capturing” the same here, meaning that it doesn’t matter whether you use true or false. That’s wrong. The Opera people have got it right, but are understandably a bit worried that no-one will believe them, so they’re mailing people to ask them to update scripts. (Hallvord has more on this.)
So, I’ve updated all my old scripts to use the fixed addEvent. (Newer scripts use the better all-new addEvent and aren’t affected.) If you use any of my older scripts, in particular NiceTitles, aqdropshadow, JSES, or aqtree3) then please take an updated version from here.
Thanks to Opera for letting me know!

24 Responses to “Corrected addEvent function”

  1. Thanks a lot for fixing your scripts! :)

    Hallvord
  2. i want to change my mobile number in yahoo messenger

    nadeem
  3. Dear Sil,
    I am happy to inform you that I am using your aqtree3clickable script. and so far has saved me a lot of time developing my web application.

    One thing boggles my mind is everytime we do onmouseover over a leaf, the browser requests the bullet.gif image to the server. I observed this behavior using HTTPWATCH by simtec ltd.

    I’m not quite sure what is the cause of this traffic, back and forth the browser and webserver. is it CSS bug or anything else? have you experienced it?

    my environment is:
    browser:
    Windows xp sp 2
    Internet Explorer 6.0.2900.2180 sp2
    IE Cache setting: Automatically.
    server:
    IIS 6.0 in win2k3 server

    Raddy
  4. Raddy: re-requesting the background image every time is an IE thing; it shouldn’t happen in other browsers, and it’s not something I can fix in the script, I’m afraid :(

    sil
  5. Hi,

    I’m using your nicetitle, and it works great. I love transparency! However, it doesn’t pick up titles in image links. Not even the tooltip titles. On some of the images (mostly buttons), the tooltips show up, but no nice titles. See http://www.openleftbox.com.

    What’s also weird is that I had an older version of nicetitle that came with my WordPress theme, it didn’t have transparency, but did pick up titles in image links.

    Any advice would be appreciated. Great job!

    phong
  6. Hi, it’s me again with another question: is it possible to not show the URL information, and just show the title info? Most of my users don’t really care where the link actually points to, only what it does.

    thank you

    phong
  7. Phong: delete this bit from nicetitle.js:

    if (lnk.href) {
    tnd = document.createTextNode(lnk.href);
    pad = document.createElementNS(XHTMLNS,”p”);
    pad.className = “destination”;
    pad.appendChild(tnd);
    d.appendChild(pad);
    }

    sil
  8. sil,

    that worked great! thanks!

    phong

    phong co
  9. sil,

    some more info about the problem i mentioned earlier (nicetitles does not show up on image links). actually the titles do show up, but only when i click, not when i hover. i tested this on a clean page, so it’s not due to my blog theme. any hints you can offer on this would be much appreciated.

    phong co
  10. Nicetitles doesn’t properly support image links. I know how to fix it, I just don’t have time.

    sil
  11. In nicetitle.js change this:

    if (lnk.nodeType == 3) {

    to this:

    if (lnk.nodeType == 1) {

    3 is for text node, but the

    lnk = getParent(lnk,”A”);

    command should be executed if lnk is not a text node but another element like an image, I think. It works this way correctly. To display the nice title right under the images like they appear to the texts, a bit more code needed to handle this in findPosition() function.

    Change this:

    for( var posX = 0, posY = 0; oLink.offsetParent; oLink = oLink.offsetParent ) {

    to this:

    var posY = 0;
    var posX = 0;
    if( oLink.hasChildNodes ) {
    children = oLink.childNodes;
    // now we assume only one image may be in a link
    child = children[0];
    if ( child.src ) {
    posY += child.offsetHeight;
    posX += child.offsetLeft;
    }
    }
    if( oLink.offsetParent ) {
    for(; oLink.offsetParent; oLink = oLink.offsetParent ) {

    You can check it working on my site.

    Gábor
  12. gabor,

    thanks for your help. your first fix worked great, it gave me nicetitles on my images. however, your second fixed got me back to regular popups. admittedly i don’t know javascript at all, so i just cut and paste your code. also i visited your site, but it doesn’t seem to have nicetitles at all?

    anyways, thanks for your ideas so far!

    phong co
  13. Hm it’s interesting. Which browser/platform you had tested on? In Firefox it works correctly. IE somehow displays original title over images. In Opera it works too but popups “Address” title even if there was no title defined. It’s a feature I’m afraid.

    Gábor
  14. gabor,

    i use firefox on windows xp. ie works kinda ok, but there’s no transparency, opera shows the address title as you say, and that “feature” sucks, but i don’t think any of my readers use it so it’s irrelevant. i guess i’ll live with what i have, and maybe poke around a bit when i have time. thanks!

    phong co
  15. Hi… I’ve been looking at the agtree3clickable script. Clever consept. In an attempt top include this on a site I discovered that the menu will not remember its state/which branch(es) of the list were expanded on the previous page. Any easy way to make this happen? I included a page with the list on using php’s include into several pages. My hope was the the script would “remember” its last state for the visitor browsing the site.

    Tore
  16. Tore: to remember status, you’d need to set cookies. It would be a useful addition to the script, and not too complex for a decent JavaScript hacker.

    sil
  17. Dear Friends,

    a lot of thanks for your great efforts something to give for the other people..

    I tried your aqtree3clickable.
    In Mozilla 1.5.02 I found a problem. The second UL with
    other UL nested is displayed with one error after opening the first UL.It has a bullet. The following LI´s of UL nested have a minus sign. The IE6 works without problems.

    The HTML code is as follows:

    About

    History

    Web Design
    Internet Marketing
    Hosting
    Domain Names
    Broadband

    Team
    Offices

    Services

    Web Design
    Internet Marketing
    Hosting
    Domain Names
    Broadband

    Contact Us

    United Kingdom
    France
    USA
    Australia

    Best regards Jiri.

    Jiri
  18. I myself found in the basic tree in HTML small error in the nesting. Now the tree is working without problem in Mozilla too.

    Jiri
  19. I would like to know how to put breaks in to knock down seperate lines.

    Anonymous
  20. Hey all — was hoping that someone could clue me in on a total n00b CSS issue:

    I’m trying to customize the Random Image Theme for Wordpress, and I’m running into a small — but *incredibly annoying* — problem.

    I’m trying to make the background of the content area white. The background of navigation column that runs down the right side is not plain white (FFFFFF). Rather Photoshop’s color picker claims that it’s F9F9F9 — but this isn’t anywhere in the style.css file. There is a .alt that has a background set at F8F8F8, but when I change that to FFFFFF, it doesn’t help.

    Where is that shading coming from?

    many thanks…

    dj
  21. Phong,

    If you add back in the bit Sil said to take out, then put in the bits that Gabor said nicetitle should work correctly with image links.
    Although your positions might be a bit off. To fix them find d.style.left = (mx+..) + px;
    &
    d.style.top = (my+..) + ‘px’;
    and play around with the numbers in .. untill it looks right to you.

    Steve

    Steve
  22. We are using nicetitles and we love it! Can you give us a fix for allowing html tags like , , to format the text?

    Ryan Lewis
  23. err I mean things like (i) and (b) and especially (br) replace the ( and ) with the appriate less than/greater than signs :P

    Ryan Lewis
  24. I am trying to use nicetitle on my website (I really like it!), but I seem to be having a problem with using on graphic links. In FF it only displays the titlebox when the mouse is at the bottom of the graphic and in IE it doesn’t display at all. In both it works fine on text links. Does anyone have any suggestions?

    Tony Brown