/**
 * Implements hook_js_alter().
 */
function color_glass_js_alter(&$js)
{
    // Exclude specified JavaScript files from theme.
    $excludes = _bootstrap_get_theme_info(NULL, 'exclude][js');
    $theme_path = drupal_get_path('theme', 'color_glass');
    // Add or replace JavaScript files when matching paths are detected.
    // Replacement files must begin with '_', like '_node.js'.
    $files = _bootstrap_file_scan_directory($theme_path . '/js', '/\\.js$/');
    foreach ($files as $file) {
        $path = str_replace($theme_path . '/js/', '', $file->uri);
        // Detect if this is a replacement file.
        $replace = FALSE;
        if (preg_match('/^[_]/', $file->filename)) {
            $replace = TRUE;
            $path = dirname($path) . '/' . preg_replace('/^[_]/', '', $file->filename);
        }
        $matches = array();
        if (preg_match('/^modules\\/([^\\/]*)/', $path, $matches)) {
            if (!module_exists($matches[1])) {
                continue;
            } else {
                $path = str_replace('modules/' . $matches[1], drupal_get_path('module', $matches[1]), $path);
            }
        }
        // Path should always exist to either add or replace JavaScript file.
        if (!empty($js[$path])) {
            // Replace file.
            if ($replace) {
                $js[$file->uri] = $js[$path];
                $js[$file->uri]['data'] = $file->uri;
                unset($js[$path]);
            } else {
                $js[$file->uri] = drupal_js_defaults($file->uri);
                $js[$file->uri]['group'] = JS_THEME;
            }
        }
    }
    // Ensure jQuery Once is always loaded.
    // @see https://drupal.org/node/2149561
    if (empty($js['misc/jquery.once.js'])) {
        $jquery_once = drupal_get_library('system', 'jquery.once');
        $js['misc/jquery.once.js'] = $jquery_once['js']['misc/jquery.once.js'];
        $js['misc/jquery.once.js'] += drupal_js_defaults('misc/jquery.once.js');
    }
    // Always add bootstrap.js last.
    $bootstrap = $theme_path . '/js/bootstrap.js';
    $js[$bootstrap] = drupal_js_defaults($bootstrap);
    $js[$bootstrap]['group'] = JS_THEME;
    $js[$bootstrap]['scope'] = 'footer';
    if (!empty($excludes)) {
        $js = array_diff_key($js, drupal_map_assoc($excludes));
    }
    // Add Bootstrap settings.
    $js['settings']['data'][]['bootstrap'] = array('anchorsFix' => _bootstrap_setting('anchors_fix'), 'anchorsSmoothScrolling' => _bootstrap_setting('anchors_smooth_scrolling'), 'formHasError' => (int) _bootstrap_setting('forms_has_error_value_toggle'), 'popoverEnabled' => _bootstrap_setting('popover_enabled'), 'popoverOptions' => array('animation' => (int) _bootstrap_setting('popover_animation'), 'html' => (int) _bootstrap_setting('popover_html'), 'placement' => _bootstrap_setting('popover_placement'), 'selector' => _bootstrap_setting('popover_selector'), 'trigger' => implode(' ', array_filter(array_values((array) _bootstrap_setting('popover_trigger')))), 'triggerAutoclose' => (int) _bootstrap_setting('popover_trigger_autoclose'), 'title' => _bootstrap_setting('popover_title'), 'content' => _bootstrap_setting('popover_content'), 'delay' => (int) _bootstrap_setting('popover_delay'), 'container' => _bootstrap_setting('popover_container')), 'tooltipEnabled' => _bootstrap_setting('tooltip_enabled'), 'tooltipOptions' => array('animation' => (int) _bootstrap_setting('tooltip_animation'), 'html' => (int) _bootstrap_setting('tooltip_html'), 'placement' => _bootstrap_setting('tooltip_placement'), 'selector' => _bootstrap_setting('tooltip_selector'), 'trigger' => implode(' ', array_filter(array_values((array) _bootstrap_setting('tooltip_trigger')))), 'delay' => (int) _bootstrap_setting('tooltip_delay'), 'container' => _bootstrap_setting('tooltip_container')));
    if ($bscdn_js = _bootstrap_setting('bscdn_js')) {
        $cdn_weight = -99.98999999999999;
        $js[$bscdn_js] = drupal_js_defaults($bscdn_js);
        $js[$bscdn_js]['type'] = 'external';
        $js[$bscdn_js]['every_page'] = TRUE;
        $js[$bscdn_js]['weight'] = $cdn_weight;
    }
}
Exemple #2
0
 /**
  * Discovers files relevant to theme hooks.
  *
  * @param array $cache
  *   The theme registry, as documented in
  *   \Drupal\Core\Theme\Registry::processExtension().
  * @param \Drupal\Core\Theme\ActiveTheme $theme
  *   Current active theme.
  *
  * @see \Drupal\Core\Theme\Registry::processExtension()
  */
 protected function discoverFiles(array &$cache, ActiveTheme $theme)
 {
     $name = $theme->getName();
     $path = $theme->getPath();
     // Find theme hook files.
     foreach (_bootstrap_file_scan_directory($path, '/(\\.func\\.php|\\.vars\\.php|\\.html\\.twig)$/') as $file) {
         // Transform "-" in file names to "_" to match theme hook naming scheme.
         $hook = strtr($file->name, '-', '_');
         // Strip off the extension.
         if (($pos = strpos($hook, '.')) !== FALSE) {
             $hook = substr($hook, 0, $pos);
         }
         // File to be included by core when a theme hook is invoked.
         if (isset($cache[$hook])) {
             // Due to the order in which templates are discovered, a theme's
             // templates are first discovered while in the twig engine's
             // hook_theme() invocation. Correct the path to the template here.
             if (preg_match('/twig$/', $file->uri)) {
                 $cache[$hook]['path'] = dirname($file->uri);
             } else {
                 include_once DRUPAL_ROOT . '/' . $file->uri;
                 if (!isset($cache[$hook]['includes'])) {
                     $cache[$hook]['includes'] = array();
                 }
                 if (!in_array($file->uri, $cache[$hook]['includes'])) {
                     $cache[$hook]['includes'][] = $file->uri;
                 }
             }
             if (!isset($cache[$hook]['preprocess functions'])) {
                 $cache[$hook]['preprocess functions'] = array();
             }
             if (isset($cache[$hook]['template']) && function_exists($name . '_preprocess')) {
                 $cache[$hook]['preprocess functions'][] = $name . '_preprocess';
             }
             if (function_exists($name . '_preprocess_' . $hook)) {
                 $cache[$hook]['preprocess functions'][] = $name . '_preprocess_' . $hook;
                 $cache[$hook]['theme path'] = $path;
             }
         }
     }
 }