SitePoint Sponsor

User Tag List

Results 1 to 1 of 1

Thread: Event Objects

  1. #1
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Event Objects

    Hi there

    I am slowly working my way through Kevan Yank & Cameron Adams' book Simply JavaScript which incidentally is so good I have bought a couple of other books.

    However I have come unstuck on the concept of the Event Object.

    The book uses creating rich tool tips as an example which I have included below (albeit not indented - sorry)

    I understand everything up until the following statement:
    showTip: function (link)

    My question is where did the link argument come from?

    Is it simply naming the event object that gets passed into the function link and therefore could it have been named anything e.g bob

    What I mean is could you place anything in the brackets following that function, and is that what the event object would then be known as, so you can easily reference it inside your function?

    Also...what is an event function?

    Any clarification gratefully appreciated from Matt in NZ

    Here is the full script below:


    var Tooltips =
    {
    init: function()
    {
    var links = document.getElementsByTagName("a");
    for (var i = 0; i < links.length; i++)
    {
    var title = links[i].getAttribute("title");
    if (title && title.length > 0)

    {
    Core.addEventListener(
    links[i], "mouseover", Tooltips.showTipListener);
    Core.addEventListener(
    links[i], "focus", Tooltips.showTipListener);
    Core.addEventListener(
    links[i], "mouseout", Tooltips.hideTipListener);
    Core.addEventListener(
    links[i], "blur", Tooltips.hideTipListener);
    }
    }
    },
    showTip: function(link)
    {
    Tooltips.hideTip(link);
    var tip = document.createElement("span");
    tip.className = "tooltip";
    var tipText = document.createTextNode(link.title);
    tip.appendChild(tipText);
    link.appendChild(tip);
    link._tooltip = tip;
    link.title = "";
    // Fix for Safari2/Opera9 repaint issue
    document.documentElement.style.position = "relative";
    },
    hideTip: function(link)
    {
    if (link._tooltip)
    {
    link.title = link._tooltip.childNodes[0].nodeValue;
    link.removeChild(link._tooltip);
    link._tooltip = null;
    // Fix for Safari2/Opera9 repaint issue
    document.documentElement.style.position = "static";
    }
    },
    showTipListener: function(event)
    {
    Tooltips.showTip(this);
    Core.preventDefault(event);
    },
    hideTipListener: function(event)
    {
    Tooltips.hideTip(this);
    }
    };
    Core.start(Tooltips);
    Last edited by unchartedtravel; Sep 28, 2008 at 09:51. Reason: No answer


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •