function javascript_libraries_block_view_alter in JavaScript Libraries Manager 7
Implements hook_block_view_alter().
File
- ./
javascript_libraries.module, line 366 - Toggle the inclusion of Drupal system libraries. Upload and reference custom libraries as well.
Code
function javascript_libraries_block_view_alter(&$data, $block) {
if (user_access('view the administration theme') && path_is_admin(current_path())) {
// Don't load any custom JS when administrators are viewing an admin page.
return;
}
$module = $block->module;
$delta = $block->delta;
$options = array();
$options['scope'] = 'footer';
$settings = variable_get('javascript_libraries_block_settings', array());
if (!empty($settings[$module][$delta])) {
foreach ($settings[$module][$delta] as $id) {
$library = javascript_libraries_custom_load($id);
// Only libraries that are not otherwise loaded will be loaded for this block.
if (!empty($library) && $library['scope'] == 'disabled') {
// Use a script loader inline to avoid breaking block cache, since
// drupal_add_js() won't run when the cached version is served.
$inline = javascript_libraries_add_inline(file_create_url($library['uri']));
// Use #suffix if content is a renderable array; otherwise append the
// output string.
if (is_array($data['content'])) {
$data['content']['#suffix'] = $inline;
}
elseif (is_string($data['content'])) {
$data['content'] .= $inline;
}
}
}
}
}