Control.Modal - Trouble setting content of modal based on event

Hello,

I'm trying to use modal to display tooltips on a selection of elements in a nested list. I pick out all elements in the list with a given class, and define a modal to each, which is all fine.

However, I wish to pick up the content for the modal from a separate source (lets say the function call_content) based on the ID of the element which the mouse hovers over. So I need to set up an observer which will catch that event pass the event onto a function, and set the content of the tooltip to the value returned.

I'm rather stuck with this second bit! I've tried a number of methods to little avail. The block of code below demonstrates how I would like it to work but its all wrong :).


function tooltip(item)
{
var tooltip = new Control.Modal($(item),
{
    hover: true,
    position: 'relative',
    offsetLeft: 50,
    offsetTop: -30,
    containerClassName: 'tooltip',
    contents: function()
    {
        return(beforeOpen: function(event)
        {
            return(call_content(Event.element(event).id));
        });
    }
});
}
$$('li.test').each(tooltip);

One method I've tried is to use something like:


function tooltip(item)
{
    item.observe('mouseover',function(event)
    {
        Control.Modal.open(call_content(Event.element(event).id),
        {
            hover: true,
            position: 'relative',
            offsetLeft: 50,
            offsetTop: -30,
            containerClassName: 'tooltip'
        }
        );
    });
}

This worked in drawing the right content in but then there seemed to be some confusion between the 'mouseover' status and the 'hover' status. I don't get a tooltip opening but the content is set in the DOM for modal_container! However, modal_container isn't reset when the mouse is removed and if I hover a second time I get an error message.

I'm sure there is a way I should be doing this, can someone please point me in the right direction?!

Will I have to use Object.Event? How does it tie in with the Modal event observers?

Posted August 31st, 2007 at 10:31am by craigloftus

Login or Register to Post