Use $.ready and $.when instead of nesting callbacks

Follows-up I0278575038.

Change-Id: I12fc8d717d812cfa57784e2e1b0a52861f157452
Merge "Use $.ready and $.when instead of nesting callbacks"