swfobject.module in SWF Tools 6
File
swfobject/swfobject.module
View source
<?php
function swfobject_swftools_methods() {
$methods = array();
$methods[SWFTOOLS_EMBED_METHOD]['swfobject_replace'] = array(
'name' => 'swfobject_replace',
'module' => 'swfobject',
'shared_file' => 'swfobject/swfobject.js',
'title' => t('SWFObject 1.5 - JavaScript'),
'download' => 'http://blog.deconcept.com/swfobject/#download',
);
return $methods;
}
function swfobject_swftools_embed($action = 'add_js', $methods = FALSE, $vars = FALSE, $html_alt = '') {
static $swfobject_has_run;
static $swfobject_id = 0;
if (!$swfobject_has_run) {
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') {
return;
}
}
static $unique_id = 0;
$unique_id++;
$html = '<div id="swfobject-id-' . time() . $unique_id . '" class="swftools swfobject" ' . swftools_json_params($vars->params, 'swftools') . ' ' . ">\n" . $html_alt . '</div>';
return $html;
}
function _swfobject_header_js() {
$js = "\n \$(document).ready(function(){\n \$('.swfobject').each(function(i){\n params = Drupal.parseJson(\$(this).attr('swftools'));\n\t var so = new SWFObject(params['src'], '', params['width'], params['height'], params['version'], params['bgcolor']);\n for (p in params) {\n so.addParam(p, params[p]);\n }\n so.addVariable('flashvars', '&'+ params['flashvars']);\n so.write(this.id);\n });\n });\n ";
return $js;
}
Functions
Name |
Description |
swfobject_swftools_embed |
Implementation of swftools_embed hook
Returns the markup for the page, plus set necessary javascript. |
swfobject_swftools_methods |
SWF Tools - SWFObject |
_swfobject_header_js |
The jQuery code that will try to replace all elements after the page loads.
This parses the JSON out of the 'swftools' attribute of all class="swfobject" divs. |