Issues

ZF-11048: View helper binds onload scripts to jQuery's ready event

Description

Onload scripts registered using JQuery view helper are bound to jQuery's ready event, which is wrong. Even the documentation for ZendX jQuery component says that the view helper handles "$(document).onLoad() events", while it actually uses $(document).ready().

I think that the view helper should use $(window).load() instead of $(document).ready(). Using load event is safer solution, since at onload stage all document resources (including javascript files) are loaded, which is not necessary the case with the ready event.

This suggested solution is unfortunately not fully backwards compatible. See following example, which would be OK in current implementation (not tested): $this->jQuery()->addOnLoad('$(window).load(alert("Registered window onload callback"););');

Comments

bq. Using load event is safer solution, since at onload stage all document resources (including javascript files) are loaded, which is not necessary the case with the ready event.

This is not quite true, see [http://api.jquery.com/ready/].

Documentation should be clarified so that ready() event is used instead of onLoad(). I think it would be sufficient if

"Handling $(document).onLoad() events."

is replaced by

"Handling $(document).ready() events."

Patch added.

Fixed in 24980(trunk) and 24981(release-1.12)