function galleria_add_js in Galleria 7
This function loads the required JavaScripts and settings for a Galleria instance.
1 call to galleria_add_js()
- template_preprocess_galleria_container in theme/
theme.inc - Template preprocess handler for 'galleria_container' theme.
File
- ./
galleria.module, line 670 - A light-weight, customizable image gallery plugin for Drupal based on jQuery
Code
function galleria_add_js($id, $optionset) {
// Static array to remember which scripts are already attached.
$cache =& drupal_static(__FUNCTION__, array());
// Library JavaScript
// Cache this filename to prevent multiple file_exists() calls.
if (!isset($cache['lib'])) {
$lib = galleria_get_library_file();
if ($lib === FALSE) {
drupal_set_message(t('The Galleria JavaScript file was not found in its path. Please refer to README.txt for installation instructions.'), 'error');
return;
}
$cache['lib'] = $lib;
}
drupal_add_js($cache['lib'], array(
'group' => JS_LIBRARY,
));
// Theme
// As it's only possible to use one theme per page, use the first one we get for everything.
if (empty($cache['theme'])) {
$theme = !empty($optionset->theme) ? $optionset->theme : 'classic';
$theme_file = galleria_get_theme_file($theme);
if ($theme_file === FALSE && $theme !== 'classic') {
// Try to fall back to classic theme, the other one might have been deleted.
$theme_file = galleria_get_theme_file('classic');
}
$cache['theme'] = $theme_file;
}
// Plugins
$plugins = empty($optionset->plugins) ? array() : $optionset->plugins;
foreach ($plugins as $plugin) {
if (empty($cache['plugins'][$plugin])) {
$plugin_file = galleria_get_plugin_file($plugin);
if ($plugin_file !== FALSE) {
$cache['plugins'][$plugin] = $plugin_file;
drupal_add_js($plugin_file);
}
}
}
// JavaScript settings
$js_settings = array(
'themepath' => file_create_url($cache['theme']),
'optionsets' => array(
$optionset->name => $optionset->options,
),
'instances' => array(
'galleria-' . $id => $optionset->name,
),
);
drupal_add_js(array(
'galleria' => $js_settings,
), 'setting');
// Loader JavaScript
drupal_add_js(drupal_get_path('module', 'galleria') . '/js/galleria.load.js');
}