You are here

function jw_player_process_jw_player in JW Player 7

Same name and namespace in other branches
  1. 7.2 jw_player.module \jw_player_process_jw_player()

Implements hook_process_HOOK().

Add the JW Player Javascript according to the method selected.

File

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

Code

function jw_player_process_jw_player(&$variables) {

  // If inline option is selected, add the js code inline. It will be printed
  // in the tpl file. This is needed so that the videos still have their config
  // after page is cached. In this case the player itself is loaded on all pages
  // via hook_init().
  if (variable_get('jw_player_inline_js', TRUE)) {
    $variables['jw_player_inline_js_code'] = stripslashes(json_encode($variables['config']));
  }
  else {

    // Add library.
    drupal_add_js(libraries_get_path('jwplayer') . '/jwplayer.js');

    // Attaches JW Player element.
    drupal_add_js(drupal_get_path('module', 'jw_player') . '/jw_player.js');
    drupal_add_js(array(
      'jw_player' => array(
        $variables['html_id'] => $variables['config'],
      ),
    ), 'setting');

    // Player settings
    // Add key if available.
    // @todo: Is added multiple times if there are multiple players on one page.
    if ($key = variable_get('jw_player_key', NULL)) {
      drupal_add_js('jwplayer.key="' . $key . '"', array(
        'type' => 'inline',
        'scope' => 'header',
        'weight' => 5,
      ));
    }
  }

  // Add js file that enables url based seeking.
  drupal_add_js(drupal_get_path('module', 'jw_player') . '/jw_player_seek.js');
}