You are here

protected function QuickQuicktabs::add_attached in Quick Tabs 7.3

Add any necessary js, css and libraries for the render array.

1 call to QuickQuicktabs::add_attached()
QuickQuicktabs::render in plugins/QuickQuicktabs.inc
The only method that renderer plugins must implement.

File

plugins/QuickQuicktabs.inc, line 104

Class

QuickQuicktabs
Renders the content using the original Quicktabs mechanism of previous versions. Includes support for ajax rendered content.

Code

protected function add_attached() {
  $attached = array(
    'css' => array(
      array(
        'data' => drupal_get_path('module', 'quicktabs') . '/css/quicktabs.css',
      ),
    ),
    'js' => array(
      array(
        'data' => drupal_get_path('module', 'quicktabs') . '/js/quicktabs.js',
      ),
      array(
        'data' => 'misc/progress.js',
        'weight' => JS_LIBRARY,
      ),
    ),
  );
  $settings = $this->quickset
    ->getSettings();

  // Add the custom style css if a custom style has been set.
  $style_css = quicktabs_get_css($settings['style']);
  if (!empty($style_css)) {
    $attached['css'][] = $style_css;
  }

  // Prepare a tab_settings array for passing the tab info to our JavaScript.
  $tab_settings = array();
  foreach ($this->quickset
    ->getContents() as $i => $content) {
    if (!empty($content)) {
      $tab_settings[$i] = $content
        ->getSettings();
    }
  }

  // Add our JS settings
  $javascript = drupal_add_js();
  if (isset($javascript['settings']['data'])) {
    foreach ($javascript['settings']['data'] as $key => $settings) {
      if (key($settings) == 'quicktabs') {
        $qtkey = $key;
        break;
      }
    }
  }
  $name = $this->quickset
    ->getName();
  if (!isset($qtkey) || isset($javascript['settings']['data'][$qtkey]['quicktabs']) && !array_key_exists('qt_' . $name, $javascript['settings']['data'][$qtkey]['quicktabs'])) {
    $quicktabs_array = array_merge(array(
      'name' => $name,
      'tabs' => $tab_settings,
    ), $settings);
    $attached['js'][] = array(
      'data' => array(
        'quicktabs' => array(
          'qt_' . $name => $quicktabs_array,
        ),
      ),
      'type' => 'setting',
    );
  }
  return $attached;
}