Created
July 26, 2008 02:12
-
-
Save juno/2577 to your computer and use it in GitHub Desktop.
Image preloading helper for symfony.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Returns a html to preload images using jQuery. | |
* | |
* @param array $urls An array of image URLs | |
* @return string HTML contents | |
*/ | |
function preload_images($urls) | |
{ | |
if (!is_array($urls)) { | |
$urls = array($urls); | |
} | |
$lines = array(); | |
$lines[] = '<script type="text/javascript">'; | |
$lines[] = '//<![CDATA['; | |
foreach ($urls as $url) { | |
$lines[] = "jQuery('<img>').attr('src', '{$url}');"; | |
} | |
$lines[] = '//]]>'; | |
$lines[] = '</script>'; | |
return implode("\n", $lines); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment