Thanks for the reply.  I think that's possible and I'll check it out,
but I wanted to post a little more code.  The example I gave was perhaps
too simplified.

Here's the line that is called in the <initialization> block:

var cropper = new Cropper.Picture('${imageId}', options);


and here's the constructor from the cropper.js file:
Cropper.Picture.prototype = {
  initialize: function(element, options) {
    this.options = options || {handle: 'handle'};
    this.picture = $(element);
    this.picContainer = this.picture.parentNode.parentNode;
    this.picContainer.style.cursor = "crosshair";
    this.dragging = false;
    
    Event.observe(this.picture, "load",
this.onLoad.bindAsEventListener(this));
  },

 onLoad: function(event){
   alert("I've been called!");
},

I would think that in the context of the initialize function in the
prototype that the "this" would be referring to the correct thing. 

-----Original Message-----
From: Jesse Kuhnert [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, January 16, 2007 4:42 PM
To: Tapestry users
Subject: Re: script initializtion calls and event binding

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 <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


-- 
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to