Using jQuery

I'm writing a widget which uses a jQuery plugin, and I need to place a call inside of

$(document).ready(function(){ 


// ...


});

Does the framework provide a way to do this?

Do you know what is the difference between placing js code inside this ready function and directly at the end of the page?

Currently, all js registered using $this->clientScript->registerScript() will be placed at the end of the page without this ready function. But we can change this behavior if necessary.

Quote

Do you know what is the difference between placing js code inside this ready function and directly at the end of the page?

As I understand from here, the [tt]ready[/tt] function is similar to calling [tt]window.onload[/tt], just better. This means, code located inside the [tt]ready[/tt] function is executed when the DOM tree is fully loaded, which may not be the case when you place code on the bottom of the page.

Quote

Currently, all js registered using $this->clientScript->registerScript() will be placed at the end of the page without this ready function. But we can change this behavior if necessary.

I think it'd be good to have something like in Prado: [tt]registerEndScript[/tt], [tt]registerBeginScript[/tt], [tt]registerHeadScript[/tt], [tt]registeronloadScript[/tt] (for things which doesn't need/work with jQuery but work with window.onload) and [tt]registerJqueryonloadScript[/tt] (or something like that, for jQuery's [tt]ready[/tt] function)

I agree with you. Will add more functions to CClientScript. This will break BC. :frowning:

Quote

I agree with you. Will add more functions to CClientScript. This will break BC. :-(

Thanks Qiang. IMHO, better now that is RC, than later when it goes gold ;)

Yeah, I checked in the changes this morning. I think it is in better shape now, though BC is broken.