You are here

function jw_player_library in JW Player 7.2

Implements hook_library().

File

./jw_player.module, line 901
Adds a theme function which allows theme developers to use the JW Player.

Code

function jw_player_library() {
  $libraries = array();
  $info = libraries_detect('jwplayer');
  $libraries['jwplayer'] = array(
    'title' => 'JW Player',
    'website' => $info['vendor url'],
    'version' => $info['installed'] ? $info['version'] : 'cloud-hosted',
    'js' => array(),
  );
  if ($cloud_hosted_default = variable_get('jw_player_cloud_player_default', FALSE)) {

    // Cloud hosted player, use external JavaScript.
    $libraries['jwplayer']['js'][$cloud_hosted_default] = array(
      'type' => 'external',
    );
  }
  else {
    if ($info['installed']) {

      // Self hosted player, use files from library definition.
      if (!empty($info['files']['js'])) {
        foreach ($info['files']['js'] as $data => $option) {
          if (is_numeric($data)) {
            $option = "{$info['library path']}/{$option}";
          }
          else {
            if (empty($option['type']) || $option['type'] == 'file') {
              $data = "{$info['library path']}/{$data}";
            }
          }
          $libraries['jwplayer']['js'][$data] = $option;
        }
      }
    }
  }
  if ($key = jw_player_get_key()) {
    $libraries['jwplayer']['js']['jwplayer.key=' . drupal_json_encode((string) $key)] = array(
      'type' => 'inline',
      'scope' => 'header',
      'weight' => 5,
    );
  }

  // Use integration files from library definition.
  foreach ($info['integration files'] as $module => $files) {
    foreach (array_keys($files) as $type) {
      $module_path = drupal_get_path('module', $module);
      foreach ($files[$type] as $data => $option) {
        if (is_numeric($data)) {
          $option = "{$module_path}/{$option}";
        }
        else {
          if (empty($option['type']) || $option['type'] == 'file') {
            $data = "{$module_path}/{$data}";
          }
        }
        $libraries['jwplayer'][$type][$data] = $option;
      }
    }
  }
  return $libraries;
}