juno (owner)

Revisions

  • 003aa4 juno Fri Jul 25 19:12:09 -0700 2008
gist: 2577 Download_button fork
public
Description:
Image preloading helper for symfony.
Public Clone URL: git://gist.github.com/2577.git
Embed All Files: show embed
PreloadHelper.php #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?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);
}