You are here

function swfobject_swftools_embed in SWF Tools 6

Same name and namespace in other branches
  1. 5 swfobject/swfobject.module \swfobject_swftools_embed()
  2. 6.2 swfobject/swfobject.module \swfobject_swftools_embed()

Implementation of swftools_embed hook Returns the markup for the page, plus set necessary javascript.

$methods and $vars should never be empty - unless the only reason for this call is to push the javascript into the header of the page in which case you don't add any paramters as all. This is useful for filtered nodes where the body is not regenerated every time.

File

swfobject/swfobject.module, line 35

Code

function swfobject_swftools_embed($action = 'add_js', $methods = FALSE, $vars = FALSE, $html_alt = '') {
  static $swfobject_has_run;
  static $swfobject_id = 0;

  // Output javascript to the header
  if (!$swfobject_has_run) {

    // Add swfobject.js
    drupal_add_js(swftools_get_player_path() . '/swfobject/swfobject.js');
    drupal_add_js(_swfobject_header_js(), 'inline', 'header');
    $swfobject_has_run = TRUE;
    if ($action == 'add_js') {

      // Exit early having put the javascript in the header.
      return;
    }
  }
  static $unique_id = 0;
  $unique_id++;

  // SWFObject needs an id so that the replacement script can take it as a parameter.
  // Use time() to prevent caching issues.
  $html = '<div id="swfobject-id-' . time() . $unique_id . '" class="swftools swfobject" ' . swftools_json_params($vars->params, 'swftools') . ' ' . ">\n" . $html_alt . '</div>';
  return $html;
}