Active
Project:
swfobject
Version:
4.7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
17 Oct 2006 at 16:57 UTC
Updated:
4 Apr 2007 at 14:25 UTC
It would be great if this module included an API for other modules to leverage the swfobject library so that there isn't code duplication. You could implement this into your blocks pretty easily. Here's how I did it in a module I pulled together:
/**
* generate javasript code
* @$url is a web accessible address
* @$params is an array of parameters to build the html
*/
function swfobject_create($url, $params = null, $load_js = true) {
static $swf_loaded;
if (!($load_js)) {
if ( !(file_exists(drupal_get_path('module','swfobject') . "/swfobject.js")) ) {
// display error if javascript isn't present
drupal_set_message(t("You need to download the swfobject.js file and place it in the swfobject module directory. Please see the README.txt"), 'error');
$swf_loaded = false;
} else {
drupal_add_js(drupal_get_path('module','swfobject') . "/swfobject.js");
$swf_loaded = true;
}
}
$width = $params['width'] ? $params['width'] : "100%" ;
$height = $params['height'] ? $params['height'] : "100%" ;
$message = $params['no_flash'] ? $params['no_flash'] : t('Sorry, you need to install flash to see this content.');
$name = str_replace(".swf", "", basename($url));
$html = "<div id='flashcontent_". $name . "'>$message</div>\n";
$html .= "<script>var so = new SWFObject('". $url . "', 'movie', '". $width ."','" . $height ."','" . $name . "'); \n";
if ($params) {
foreach ($params as $key => $value) {
if (($key != "width") && ($key != "height") && ($key != "no_flash")) {
$html .= " so.addParam('$key', '$value'); \n";
}
}
}
$html .= " so.write('flashcontent_". $name . "'); \n</script>";
return $html;
}
Then developers can call it with:
$params = array('width' => '100', 'height' => '200', 'no_flash' => 'Sorry, you need flash installed to view this content');
print swfobject_create($url, $params);
Comments
Comment #1
zroger commentedThis seems like a good idea. I am pretty busy at work so it may take a little while to get this in.
Thanks
Comment #2
arthurf commentedI've added my swfobject_api module to cvs. I think it would make sense to merge these modules. I'd be willing to do the work to integrate them if you'd like. I've also talked with Geoff (creator of swfobject) and he is going to dual license swfobject so that it can be included in the drupal repo.
Comment #3
zroger commentedI am currently working on a 5.0 release for swfobject that will include more ways to use swfobject. I am planning on implementing:
All of these features will also be backported to the 4.7 branch.
Comment #4
arthurf commentedsounds great. anything i can do to help you in this process? I'd be glad to help out if you'd like.
Comment #5
arthurf commentedI've done a 5.0 port of the swfobject_api module which implements:
Which makes the theming easier. I'd be happy to port this to or integrate it with your module.
Comment #6
Zen commentedWhat is the status of the API functionality and the D5 port? @rz If you do not have the time to maintain this module, please commit any work you've done to HEAD and let arthurf assume co-maintainership, if he is still interested.
Thanks,
-K