You are here

function swftools_soundmanager2_add_js in SWF Tools 6.3

Adds SoundManager 2 audio JavaScript to the page.

2 calls to swftools_soundmanager2_add_js()
swftools_soundmanager2_init in soundmanager2/swftools_soundmanager2.module
Implementation of hook_init().
swftools_soundmanager2_swftools_preprocess_soundmanager2 in soundmanager2/swftools_soundmanager2.module
Implementation of hook_swftools_preprocess_[player]().

File

soundmanager2/swftools_soundmanager2.module, line 76
Enables SWF Tools support for SoundManager 2.

Code

function swftools_soundmanager2_add_js($profile = '', $player = '') {

  // We don't want to add things multiple times so we set some static variables
  static $everything_added = FALSE;
  static $global_settings_added = FALSE;
  static $ui360_settings_added = FALSE;

  // Get global settings
  $global_settings = _swftools_soundmanager2_global_settings();

  // Get profile settings
  $profile_settings = _swftools_soundmanager2_settings($profile);

  // Get library path (we will use this several times)
  $library = swftools_get_library('soundmanager2');

  // We use a profile name that we hope no-one ever picks to indicate we want to add all scripts flagged for every page
  if ($profile == '__add_everything__' && !$everything_added) {
    $everything_added = TRUE;
    foreach ($global_settings['addScripts'] as $add_player) {
      if ($add_player) {
        swftools_soundmanager2_add_js('', $add_player);
      }
    }
  }

  // See if we need to add global settings - do this once only
  if (!$global_settings_added) {
    $global_settings_added = TRUE;
    $settings = array(
      'soundManager.url' => base_path() . $library . '/swf/',
      'soundManager.debugMode' => $global_settings['debugMode'] ? TRUE : FALSE,
      'soundManager.useFlashBlock' => $global_settings['useFlashBlock'] ? TRUE : FALSE,
      'soundManager.flashVersion' => $global_settings['flashVersion'],
      'soundManager.useFastPolling' => $global_settings['useFastPolling'] ? TRUE : FALSE,
      'soundManager.useHighPerformance' => $global_settings['useHighPerformance'] ? TRUE : FALSE,
      'threeSixtyPlayer.config.imageRoot' => base_path() . $library . '/demo/360-player/',
    );
    drupal_add_js(array(
      'swftools_soundmanager2' => $settings,
    ), 'setting');
  }

  // Add main SoundManager2 script and SWF Tools script to load the defaults in to it
  $script = $global_settings['debugMode'] ? 'soundmanager2.js' : 'soundmanager2-nodebug-jsmin.js';
  drupal_add_js($library . '/script/' . $script);
  drupal_add_js(drupal_get_path('module', 'swftools_soundmanager2') . '/swftools_soundmanager2.js');
  if ($global_settings['useFlashBlock']) {
    drupal_add_css($library . '/demo/flashblock/flashblock.css');
  }

  // Add special IE canvas script - we have to add this ourselves as a conditional script
  $script = '<!--[if IE]><script type="text/javascript" src="' . base_path() . $library . '/demo/360-player/script/excanvas.js"></script><![endif]-->';
  drupal_set_html_head($script);

  // If the function was called with a specific player we are iterating to add all the scripts
  $player = $player ? $player : $profile_settings['player'];

  // Add the relevant scripts and css
  switch ($player) {
    case 'ui360':
      drupal_add_css($library . '/demo/360-player/360player.css');
      drupal_add_js($library . '/demo/360-player/script/berniecode-animator.js');
      drupal_add_js($library . '/demo/360-player/script/360player.js');
      break;
    case 'mp3_links':
      drupal_add_css($library . '/demo/play-mp3-links/css/inlineplayer.css');
      drupal_add_css(drupal_get_path('module', 'swftools_soundmanager2') . '/swftools_soundmanager2.inlineplayer.css');
      drupal_add_js($library . '/demo/play-mp3-links/script/inlineplayer.js');
      break;
    case 'mp3_button':
      drupal_add_css($library . '/demo/mp3-player-button/css/mp3-player-button.css');
      drupal_add_js($library . '/demo/mp3-player-button/script/mp3-player-button.js');
      break;
    case 'ui360_visualization':
      drupal_add_css($library . '/demo/360-player/360player.css');
      drupal_add_css($library . '/demo/360-player/360player-visualization.css');
      drupal_add_js($library . '/demo/360-player/script/berniecode-animator.js');
      drupal_add_js($library . '/demo/360-player/script/360player.js');

      // See if we need to add visualisation settings - do this once only
      if (!$ui360_settings_added) {
        $ui360_settings_added = TRUE;
        $settings = array(
          'useVisualisation' => TRUE,
          'threeSixtyPlayer.config.showHMSTime' => TRUE,
          'threeSixtyPlayer.config.useWaveformData' => TRUE,
          'threeSixtyPlayer.config.useEQData' => TRUE,
          'soundManager.flash9Options.useWaveformData' => TRUE,
          'soundManager.flash9Options.useEQData' => TRUE,
          'soundManager.flash9Options.usePeakData' => TRUE,
        );
        drupal_add_js(array(
          'swftools_soundmanager2' => $settings,
        ), 'setting');
      }
      break;
  }
}