hey there, I noticed that the swfobject_api module doesn't work when using a theme that puts $scripts right before $closure
considering this makes ur page load a lot faster and since there's no reason why the swfobject_api script should be placed inline right where the swfobject should come, I figured I'd migrate the script to the footer ($closure)
thanks to the awesomeness that is theme functions, it was fairly easy
stuff this in ur template.php and u won't be forced to have $scripts in the header anymore!
/**
* Implementation of theme
* @param $url
* a web accessible url to the flash file
* @param $params
* An associative array of parameters that describe the SWF
* @param $flashvars
* An associative array of variables to pass through to the SWF flashvars value
* @return
* themed html
*/
function phptemplate_swfobject_api($url, $params = null, $flashvars = null, $id = null) {
static $id_count;
// get the path to thje swf object library
drupal_add_js(drupal_get_path('module', 'swfobject_api') .'/swfobject.js');
$base_params = array(
'width' => '100%',
'height' => '100%',
'no_flash' => t('Sorry, you need to install flash to see this content.'),
'version' => variable_get('swfoa_version', '5'),
'type' => 'movie',
'bg_color' => '#FFFFFF'
);
$params = array_merge($base_params, $params);
// Express install redirect URL: as per the SWFObject docs, this should
// actually be xiRedirectUrl; variable name changed for simplicity.
if (isset($param['express_redirect'])) {
$redirect = $param['express_redirect'];
}
// create a unique id, use what's passed in, what has been saved locally
if ($id) { $id_count = $id; }
else {
$id_count = $id_count ? $id_count : 1;
}
// set the name of the swf file
$name = form_clean_id(str_replace('.swf', '', basename($url))) .'_'. $id_count;
// set the div id to the params
if ($params['div_id']) {
$div_id = $params['div_id'];
unset($params['div_id']);
}
else {
$div_id = 'flashcontent_'. $name;
}
// build the class
// @TODO should use drupal attributes here to better deal with this
if ($params['class']) {
$class = ' class="'. $params['class'] .'"';
unset($params['class']);
}
// build the div structure
$html[] = '<div id="'. $div_id .'" '. $class .'>'. $params['no_flash'] .'</div>';
// build the javascript output - ommitted, inline script added to $closure - doesn't require script tags
// $html[] = '<script type="text/javascript"><!-- ';
// Express install redirect URL: as per the SWFObject docs, this should
// actually be xiRedirectUrl; variable name changed for simplicity.
if (! $params['express_redirect']) {
$params['express_redirect'] = variable_get('swfoa_express', true) ? base_path() . drupal_get_path('module', 'swfobject_api') .'/expressinstall.swf' : 'false';
}
// Set the minimum version of flash expected
if (! $params['version']) {
$params['version'] = variable_get('swfoa_version', 9) ? variable_get('swfoa_express', "9.0.0") : 'false';
}
// get the parameters for this object
$script[] = swfobject_api_build_variables($flashvars, $params, $attributes);
// build the swfobject the swfojbect
$script[] = " swfobject.embedSWF('$url', '$div_id', '". $params['width'] ."', '". $params['height'] ."', '". $params['version'] ."', '". $params['express_redirect'] ."', flashvars, params, attributes );";
// build the complete output - changed var name to keep it separated from the inline code in $html
$htmlfooter[] = ' $(document).ready(function () {';
$htmlfooter[] = implode("\n", $script);
$htmlfooter[] = '}); ';
/* ommitted because $closure doesn't need script tags
$html[] = "--></script>\n"; */
// increment the id count
$id_count ++;
// adding script to footer instead of inline
drupal_add_js(implode("\n", $htmlfooter), 'inline', 'footer');
return implode("\n", $html);
}
Comments
Comment #1
arthurf commentedThe newer code is using drupal_add_js, and using the 'footer' parameter- can you give this a test and see if this works for you? The footer location is working for me, but I don't have much JS on my test beds.
Comment #2
seutje commentedconfirmed that the issue is fixed
sorry it took so long to reply but I was kinda busy on the big deadlines :P