code: function waitFor(testFx, onReady, timeout) {
      var maxTimeout = timeout ? timeout : 3000; //< Default Max Timout is 3s
      var start = new Date().getTime();
      var condition = false;
      var interval = setInterval(function() {
        if ((new Date().getTime() - start < maxTimeout) && !condition) {
          // If not time-out yet and condition not yet fulfilled.
          condition = (typeof(testFx) === 'string' ? eval(testFx) : testFx());
        }
        else {
          if (!condition) {
            // Condition still not fulfilled after timeout.
            throw new Error('waitFor() timed out.');
          }
          else {
            // Condition fulfilled (timeout and/or condition is 'true')
            typeof(onReady) === "string" ? eval(onReady) : onReady(); //< Do what it's supposed to do once the condition is fulfilled
            clearInterval(interval); //< Stop this interval
          }
        }
      }, 250); //< repeat check every 250ms
    }
docs: Wait until the test condition is true or a timeout occurs. Useful for waiting
  on a server response or for a ui change (fadeIn, etc.) to occur.
  
  Borrowed from the phantomjs examples library.
  
  @param testFx javascript condition that evaluates to a boolean,
  it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
  as a callback function.
  @param onReady what to do when testFx condition is fulfilled,
  it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
  as a callback function.
  @param timeout the max amount of time to wait in milliseconds.
  Defaults to 3000.