Calling a custom function from xul tree's onselect() event

76 views
Skip to first unread message

APinter

unread,
Jun 19, 2009, 1:50:34 PM6/19/09
to Firebug
Hello there,

I've already asked for your help once, and got perfect help. So I hope
you can help me again.

I'm still working on the same project and want to react on a
"onselect" event of my XUL-tree.
This works fine, as long as I'm not trying to do any productive.

The following works great:
tree.setAttribute("onselect", "alert(currentIndex);");

This one:
tree.setAttribute("onselect", "foo(currentIndex);");
and this one:
tree.setAttribute("onselect",
"Firebug.Cocoon3ProfilingModule.alertStuff(currentIndex);");
do not work.

"foo" is a custom method, which does nothing special at the moment. It
just don't get called.
Same for "alertStuff"

You can find my Plugin in the "net" tab. When you open a request you
should get another tab called "Cocoon 3 Profiling".

I attached my XPI to provide you with as much information as
possible.
I hope you are able to help me again.

Kind regards,
Andreas

johnjbarton

unread,
Jun 19, 2009, 1:58:05 PM6/19/09
to Firebug
Just a generic guess: foo is not in the scope of the onselect event
hander. alert means "window.alert" which always exists. "foo" means
"look up 'foo' here". I suggest you try
alert(foo)
and when that comes up "undefined"
try
alert(window.location)
and compare the value to the point where foo is defined.

(Maybe you can use tree.addEventListener('select', foo, true)
instead?)

jjb

APinter

unread,
Jun 19, 2009, 2:00:11 PM6/19/09
to Firebug
Sadly I wasn't able to attach the file (couldn't find the option)

so I uploaded it:

http://rapidshare.com/files/246365049/Cocoon3Profiling3.0.0-alpha-2-SNAPSHOT.xpi.html
MD5: F49B3FA64078F1F0D2795B644E1A4B2D

(just 10 downloads, please tell me, if these 10 are exceeded!)

Kind regards,
Andreas

APinter

unread,
Jun 19, 2009, 2:15:05 PM6/19/09
to Firebug
I'm pretty sure, you are right with your suggestion.
But i have failed to tell the event, where to find my "foo". That's
the reason why i came up with Firebug.Cocoon3ProfilingModule.alertStuff
(currentIndex);");

alert(foo); or alert(Firebug.Cocoon3ProfilingModule.alertStuff);
doesn't result in any output at ally.
alert(window.location) writes "chrome://firebug/content/panel.html".

But the good news:
the eventHandler-thingie works great!

I'm curious why onselect does not know where to look, while
addEventListener does.

Last thing to look at is passing arguments to the EventListener, which
shouldn't be that much of a problem, should it?

Thank you very much again!

Kind regards,
Andreas

johnjbarton

unread,
Jun 19, 2009, 2:54:22 PM6/19/09
to Firebug


On Jun 19, 11:15 am, APinter <pinter.andr...@gmail.com> wrote:
> I'm pretty sure, you are right with your suggestion.
> But i have failed to tell the event, where to find my "foo". That's
> the reason why i came up with Firebug.Cocoon3ProfilingModule.alertStuff
> (currentIndex);");

But Firebug is an object in the scope of browser.xul...

>
> alert(foo); or alert(Firebug.Cocoon3ProfilingModule.alertStuff);
> doesn't result in any output at ally.
> alert(window.location) writes "chrome://firebug/content/panel.html".

...and you are in the scope of panel.html when you run the select
handler.

>
> But the good news:
> the eventHandler-thingie works great!
>
> I'm curious why onselect does not know where to look, while
> addEventListener does.

Because onselect takes a string expression which is evaluated in the
other window (and fails), while the addEventListener takes a function
compiled in the window of the 'foo'.

>
> Last thing to look at is passing arguments to the EventListener, which
> shouldn't be that much of a problem, should it?

On the contrary, it's not possible. The event listener has fixed
argument: 'event'. Rather you have to "close" over values in the scope
of the addEventListener call.
var bar = 5;
function handler(event) {
alert("Meet me in the bar at "+bar); // bar is bound from one
scope and used in another.
}
elt.addEventListener('select', handler, true);

jjb
Reply all
Reply to author
Forward
0 new messages