support for different versions of jQuery.  avoid calling $apply within an $apply cycle.