You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Chris Norris <CN...@widen.com> on 2007/01/16 23:34:02 UTC

script initializtion calls and event binding

Please bear with me though this explanation.  We have some code that is
broken, I believe, by the inclusion of all script initialization code in
a dojo.addOnLoad call.

The code this is being broken is a call to Scriptaculous' Event.observe:
Event.observe(this.picture, "load",
this.onLoad.bindAsEventListener(this));

Even after this.picture loads, the this.onLoad function is never called.
If, however, we take this code out of an <initialize> block in a script
file and just include it in the html template in a normal Javascript
block, it works fine.  Something about dojo.addOnLoad is breaking the
Scriptaculous Event handling.  Has anyone ran into anything like this?
If I didn't make the problem clear, let me know.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: script initializtion calls and event binding

Posted by Jesse Kuhnert <jk...@gmail.com>.
The context of "this" is probably what is breaking. That particular
keyword is deceptively similar to java this but much more specific.

in a block like :

dojo.addOnLoad(function(){

});

"this" refers to the closest containing object. In this case that
would be the anonymous function(){} object. If you want to bind to
something like the window being loaded reference
window.onLoad.bindAs.... If it's the document you want to do it on do
document.onLoad.bindAs<blah bah> ...Etc.. etc..

On 1/16/07, Chris Norris <CN...@widen.com> wrote:
> Please bear with me though this explanation.  We have some code that is
> broken, I believe, by the inclusion of all script initialization code in
> a dojo.addOnLoad call.
>
> The code this is being broken is a call to Scriptaculous' Event.observe:
> Event.observe(this.picture, "load",
> this.onLoad.bindAsEventListener(this));
>
> Even after this.picture loads, the this.onLoad function is never called.
> If, however, we take this code out of an <initialize> block in a script
> file and just include it in the html template in a normal Javascript
> block, it works fine.  Something about dojo.addOnLoad is breaking the
> Scriptaculous Event handling.  Has anyone ran into anything like this?
> If I didn't make the problem clear, let me know.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Jesse Kuhnert
Tapestry/Dojo team member/developer

Open source based consulting work centered around
dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org