You are here

function _jplayer_js_attach in jPlayer 7.2

Add core JS and CSS needed for jPlayer instances.

Return value

array Form API attach.

2 calls to _jplayer_js_attach()
template_preprocess_jplayer in includes/jplayer.theme.inc
Preprocess function for a player.
template_preprocess_jplayer_view_playlist in includes/jplayer.theme.inc
Preprocess function for jplayer.tpl.php when displaying a view as a playlist.

File

./jplayer.module, line 341
Provides an HTML5-compatible with Flash-fallback audio player.

Code

function _jplayer_js_attach() {
  $added =& drupal_static(__FUNCTION__, FALSE);
  if ($added) {

    // JS is already loaded.
    return array();
  }

  // Add global settings.
  $settings = array(
    'jPlayer' => array(
      'swfPath' => _jplayer_get_swf(),
      'showHour' => (bool) variable_get('jplayer_showHour', FALSE),
      'showMin' => (bool) variable_get('jplayer_showMin', TRUE),
      'showSec' => (bool) variable_get('jplayer_showSec', TRUE),
      'padHour' => (bool) variable_get('jplayer_padHour', FALSE),
      'padMin' => (bool) variable_get('jplayer_padMin', TRUE),
      'padSec' => (bool) variable_get('jplayer_padSec', TRUE),
      'sepHour' => variable_get('jplayer_sepHour', ':'),
      'sepMin' => variable_get('jplayer_sepMin', ':'),
      'sepSec' => variable_get('jplayer_sepSec', ''),
    ),
  );
  drupal_add_js($settings, array(
    'type' => 'setting',
  ));
  $path = drupal_get_path('module', 'jplayer');
  $return = array(
    '#attached' => array(
      // Base library.
      'library' => array(
        array(
          'jplayer',
          'jplayer',
        ),
      ),
      // Drupal specific JS.
      'js' => array(
        $path . '/theme/jplayer.js' => array(
          'type' => 'file',
          'scope' => 'footer',
          'group' => JS_DEFAULT,
        ),
      ),
      // CSS of skin.
      'css' => _jplayer_get_css(),
    ),
  );

  // Allow other modules to add resources to the page when a jPlayer is
  // embedded.
  if ($additional_resources = module_invoke_all('jplayer_add_js')) {
    $return['additional_resources'] = $additional_resources;
  }
  $added = TRUE;
  return $return;
}