converted preloadImages function to directive