Change JS expression to also wait for jQuery to be present

I noticed that we have had a number of failures where an exception is thrown when we check for `jQuery.active == 0` because `jQuery` is not defined. It seems like maybe we are checking too quickly, and jQuery is not available in the DOM yet.  This patch simply changes the logic so that we are checking if `jQuery` is defined *and* if `jQuery.active == 0`. The first check should short-circuit the second check, so we wouldn't check if `jQuery.active == 0` unless `jQuery` is defined.

As this change was made in a number of places this should be tested via a complete run of the desktop suite.