[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/swftools/swfobject/ -> swfobject.module (source)

   1  <?php
   2  // $Id: swfobject.module,v 1.2 2008/09/07 19:42:15 stuartgreenfield Exp $
   3  
   4  /**
   5   * SWF Tools - SWFObject
   6   *
   7   * Enables the use of 's swfobject.js which provides image replacement
   8   * for Flash content. swfobject.js must be downloaded separately. (Add
   9   * the contents of the zip file to swftools/shared/
  10   *
  11   * Author's Site.
  12   * http://www.airtightinteractive.com/simpleviewer/
  13   */
  14  
  15  function swfobject_swftools_methods() {
  16    $methods = array();
  17    $methods[SWFTOOLS_EMBED_METHOD]['swfobject_replace'] = array(
  18      'name'        => 'swfobject_replace',
  19      'module'      => 'swfobject',
  20      'shared_file' => 'swfobject/swfobject.js',
  21      'title'       => t('SWFObject 1.5 - JavaScript'),
  22      'download'    => 'http://blog.deconcept.com/swfobject/#download',
  23    );
  24    return $methods;
  25  }
  26  
  27  /**
  28   * Implementation of swftools_embed hook
  29   * Returns the markup for the page, plus set necessary javascript.
  30   *
  31   * $methods and $vars should never be empty - unless the only reason for this call
  32   * is to push the javascript into the header of the page in which case you don't
  33   * add any paramters as all. This is useful for filtered nodes where the body is
  34   * not regenerated every time.
  35   */
  36  function swfobject_swftools_embed($action = 'add_js', $methods = FALSE, $vars = FALSE, $html_alt = '') {
  37  
  38    static $swfobject_has_run;
  39    static $swfobject_id = 0;
  40  
  41    // Output javascript to the header
  42    if (!$swfobject_has_run) {
  43      // Add swfobject.js
  44      drupal_add_js(swftools_get_player_path() .'/swfobject/swfobject.js');
  45      drupal_add_js(_swfobject_header_js(), 'inline', 'header');
  46      $swfobject_has_run = TRUE;
  47      if ($action == 'add_js') {
  48        // Exit early having put the javascript in the header.
  49        return;
  50      }
  51    }
  52    static $unique_id = 0;
  53    $unique_id++;
  54  
  55    // SWFObject needs an id so that the replacement script can take it as a parameter.
  56    // Use time() to prevent caching issues.
  57    $html = '<div id="swfobject-id-'. time() . $unique_id .'" class="swftools swfobject" '.
  58             swftools_json_params($vars->params, 'swftools') .' '.">\n".
  59             $html_alt .
  60             '</div>';
  61    return $html;
  62  }
  63  
  64  /**
  65   * The jQuery code that will try to replace all elements after the page loads.
  66   * This parses the JSON out of the 'swftools' attribute of all class="swfobject" divs.
  67   *
  68   */
  69  function _swfobject_header_js() {
  70    $js = "
  71    $(document).ready(function(){
  72      $('.swfobject').each(function(i){
  73        params = Drupal.parseJson($(this).attr('swftools'));
  74          var so = new SWFObject(params['src'], '', params['width'], params['height'], params['version'], params['bgcolor']);
  75        for (p in params) {
  76          so.addParam(p, params[p]);
  77        }
  78        so.addVariable('flashvars', '&'+ params['flashvars']);
  79        so.write(this.id);
  80      });
  81    });
  82    ";
  83    return $js;
  84  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7