You are here

function quicktabs_ajax_js_css in Quick Tabs 6.2

Same name and namespace in other branches
  1. 6.3 quicktabs.module \quicktabs_ajax_js_css()

This function is based on the ctools_ajax_render() function in the CTools AJAX framework. It allows us to pull js/css files and js settings for content that will be loaded via ajax.

1 call to quicktabs_ajax_js_css()
quicktabs_ajax in ./quicktabs.module
Ajax callback for tab content.

File

./quicktabs.module, line 724

Code

function quicktabs_ajax_js_css() {
  $query_string = '?' . substr(variable_get('css_js_query_string', '0'), 0, 1);
  $scripts = drupal_add_js(NULL, NULL);
  foreach ($scripts as $type => $data) {
    switch ($type) {
      case 'setting':
        $settings = $data;
        break;
      case 'inline':

        // currently we ignore inline javascript.
        break;
      default:

        // If JS preprocessing is off, we still need to output the scripts.
        // Additionally, go through any remaining scripts if JS preprocessing is on and output the non-cached ones.
        foreach ($data as $path => $info) {
          $js_files[] = base_path() . $path . ($info['cache'] ? $query_string : '?' . time());
        }
    }
  }
  $css = drupal_add_css();
  foreach ($css as $media => $types) {

    // If CSS preprocessing is off, we still need to output the styles.
    // Additionally, go through any remaining styles if CSS preprocessing is on and output the non-cached ones.
    foreach ($types as $type => $files) {
      if ($type == 'module') {

        // Setup theme overrides for module styles.
        $theme_styles = array();
        foreach (array_keys($css[$media]['theme']) as $theme_style) {
          $theme_styles[] = basename($theme_style);
        }
      }
      foreach ($types[$type] as $file => $preprocess) {

        // If the theme supplies its own style using the name of the module style, skip its inclusion.
        // This includes any RTL styles associated with its main LTR counterpart.
        if ($type == 'module' && in_array(str_replace('-rtl.css', '.css', basename($file)), $theme_styles)) {

          // Unset the file to prevent its inclusion when CSS aggregation is enabled.
          unset($types[$type][$file]);
          continue;
        }

        // Only include the stylesheet if it exists.
        if (file_exists($file)) {
          $css_files[] = array(
            'file' => base_path() . $file . $query_string,
            'media' => $media,
          );
        }
      }
    }
  }
  $js_css = array();
  if (!empty($settings)) {
    $js_css['js_settings'] = call_user_func_array('array_merge_recursive', $settings);
  }
  if (!empty($js_files)) {
    $js_css['js_files'] = $js_files;
  }
  if (!empty($css_files)) {
    $js_css['css_files'] = $css_files;
  }
  return $js_css;
}