function theme_lazyloader_image in Image Lazyloader 7.2
Returns HTML for an image.
Parameters
$variables: An associative array containing:
- path: Either the path of the image file (relative to base_path()) or a full URL.
- width: The width of the image (if known).
- height: The height of the image (if known).
- alt: The alternative text for text-based browsers. HTML 4 and XHTML 1.0 always require an alt attribute. The HTML 5 draft allows the alt attribute to be omitted in some cases. Therefore, this variable defaults to an empty string, but can be set to NULL for the attribute to be omitted. Usually, neither omission nor an empty string satisfies accessibility requirements, so it is strongly encouraged for code calling theme('image') to pass a meaningful value for this variable.
- title: The title text is displayed when the image is hovered in some popular browsers.
- attributes: Associative array of attributes to be placed in the img tag.
Return value
string HTML for a lazyloaded image
2 string references to 'theme_lazyloader_image'
- lazyloader_theme in ./
lazyloader.module - Implements hook_theme().
- lazyloader_theme_registry_alter in ./
lazyloader.module - Implements hook_theme_registry_alter().
File
- ./
lazyloader.module, line 130 - Lazyloader Module
Code
function theme_lazyloader_image($variables) {
$theme_image = theme_image($variables);
// Use theme_image if lazyloader is not enabled.
if ($variables['theme_hook_original'] !== 'lazyloader_image') {
if (!_lazy_loader_enabled() || _lazyloader_excluded_by_filename($variables) || _lazyloader_excluded_by_image_style($variables)) {
return $theme_image;
}
}
static $rdwimages_enabled, $image_placeholder_src;
$attributes = $variables['attributes'];
// Set the data source and placeholder image.
$attributes['data-echo'] = file_create_url($variables['path']);
$attributes['data-icon'] = _lazyloader_icon_path();
if (!isset($image_placeholder_src)) {
// Path to dummy placeholder image, to be replaced by actual image.
$image_placeholder = trim(variable_get('lazyloader_placeholder', LAZYLOADER_PLACEHOLDER));
$image_placeholder_src = $image_placeholder ? base_path() . $image_placeholder : file_create_url(drupal_get_path('module', 'lazyloader') . '/image_placeholder.gif');
}
// Integrate with Responsive Webdesign module.
if (!isset($rdwimages_enabled)) {
global $_rwdimages_set;
$rdwimages_enabled = module_exists('rdwimages') && $_rwdimages_set['enabled'];
}
if ($rdwimages_enabled) {
$attributes['class'] = isset($attributes['class']) ? $attributes['class'] + array(
'rwdimage',
) : array(
'rdwimage',
);
}
// Add noscript as a fallback.
$noscript = "<noscript>{$theme_image}</noscript>";
$arguments = array(
'path' => $image_placeholder_src,
'attributes' => $attributes,
);
foreach (array(
'width',
'height',
'alt',
'title',
) as $key) {
if (isset($variables[$key])) {
$arguments[$key] = $variables[$key];
}
}
// Get the icon width and height for use in the javascript.
$icon_path = substr(_lazyloader_icon_path(), strlen(base_path()));
// The path will be empty if the user configured the option to show no icon.
list($icon_width, $icon_height) = !empty($icon_path) ? getimagesize($icon_path) : array(
0,
0,
);
$settings['lazyloader'] = array(
'throttle' => variable_get('lazyloader_load_image_delay', LAZYLOADER_LOAD_IMAGE_DELAY),
'offset' => variable_get('lazyloader_distance', LAZYLOADER_DISTANCE),
'debounce' => variable_get('lazyloader_debounce', LAZYLOADER_DEBOUNCE),
'unload' => variable_get('lazyloader_unload', LAZYLOADER_UNLOAD),
'icon' => _lazyloader_icon_path(),
'offsetX' => $icon_width > 0 ? floor($icon_width / 2) : 0,
'offsetY' => $icon_height > 0 ? floor($icon_height / 2) : 0,
);
drupal_add_js($settings, array(
'type' => 'setting',
));
// Load the Echo library.
$variant = variable_get('lazyloader_debugging', LAZYLOADER_DEBUGGING) ? NULL : 'minified';
libraries_load_files(libraries_load('echo', $variant));
// Render the image.
return theme_image($arguments) . $noscript;
}