zooming-8.x-1.0/zooming.module
zooming.module
<?php
/**
* @file
* Provides Zooming integration.
*/
/**
* Implements hook_library_info_alter().
*/
function zooming_library_info_alter(&$libraries, $extension) {
// Supports other location such as distros, etc.
if ($extension === 'zooming'
&& $path = blazy()->getLibrariesPath('zooming')) {
$libraries['zooming']['js'] = ['/' . $path . '/build/zooming.min.js' => []];
}
}
/**
* Implements hook_blazy_attach_alter().
*/
function zooming_blazy_attach_alter(array &$load, array $attach = []) {
if (!empty($attach['zooming'])) {
$load['library'][] = 'zooming/load';
}
}
/**
* Implements hook_blazy_lightboxes_alter().
*/
function zooming_blazy_lightboxes_alter(array &$lightboxes) {
$lightboxes[] = 'zooming';
}
/**
* Overrides variables for theme_blazy().
*/
function zooming_preprocess_blazy(array &$variables) {
$settings = &$variables['settings'];
$blazies = $settings['blazies'];
$switch = $settings['media_switch'] ?? '';
$type = $blazies->get('media.type');
$box_url = $blazies->get('lightbox.url');
$embed_url = $blazies->get('media.embed_url');
$is_video = $type == 'video';
$is_video = $blazies->is('remote_video') ?: $is_video;
$url = $variables['url'] ?? NULL;
$url = $url ?: $box_url;
// Zooming is registered as lightbox, but we'll make it a hybrid of media
// and lightbox switcher in order to support video which is inline by nature
// of Zooming. This also fixes erratic behavior with clicked-through links.
if ($switch == 'zooming' && $url) {
// Removes regular lightbox icon, except for inline remote video.
if (!$embed_url || $blazies->is('lightbox')) {
$variables['icon'] = '';
}
// Copy lightbox URL attributes into the main attributes as we drop it.
$url_attributes = $variables['url_attributes'];
$variables['attributes']['data-media'] = $url_attributes['data-media'];
// Disable lightbox (A tag) for the hybrid of media and quasi-lightbox.
$variables['url'] = '';
// Support video thumbnail for the lightbox.
if ($is_video && $box_url) {
$url = $box_url;
}
// Provides the expected attributes for JS.
// The library only works with IMG, not CSS background.
if (!empty($variables['image'])) {
$variables['image']['#attributes']['data-original'] = $url;
$variables['image']['#attributes']['class'][] = 'zooming';
}
}
}
/**
* Implements hook_blazy_item_alter().
*/
function zooming_blazy_item_alter(array &$settings, array &$attributes, array &$item_attributes) {
$blazies = $settings['blazies'];
// Zooming is registered as lightbox, but we'll make it a hybrid of media
// and lightbox switcher in order to support video which is inline by nature
// of Zooming. This also fixes erratic behavior with clicked-through links.
$is_video = $blazies->get('media.embed_url');
$is_local = $blazies->is('local_media');
if ($blazies->get('zooming') && ($is_video || $is_local)) {
$blazies->set('switch', 'media')
->set('is.player', $is_video)
->set('is.lightbox', FALSE)
->set('use.player', $is_video);
}
}
/**
* Implements hook_help().
*/
function zooming_help($route_name) {
if ($route_name == 'help.page.zooming') {
$output = file_get_contents(dirname(__FILE__) . '/README.md');
return blazy()->markdown($output);
}
return '';
}
