World number two Novak Djokovic recovered from an ankle injury to reach the third round of the Shanghai Masters.