/[drupal]/contributions/modules/swftools/swfobject/swfobject.module
ViewVC logotype

Contents of /contributions/modules/swftools/swfobject/swfobject.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.4 - (show annotations) (download) (as text)
Fri Mar 6 19:48:00 2009 UTC (8 months, 2 weeks ago) by stuartgreenfield
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +9 -6 lines
File MIME type: text/x-php
Accidentally committed a version that wasn't intended. This (hopefully) reverses the error.
1 <?php
2 // $Id: swfobject.module,v 1.3 2009/03/06 16:45:48 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 /**
16 * Implementation of hook_swftools_methods().
17 */
18 function swfobject_swftools_methods() {
19
20 $methods = array();
21
22 $methods[SWFTOOLS_EMBED]['swfobject_replace'] = array(
23 'name' => 'swfobject_replace',
24 'module' => 'swfobject',
25 'shared_file' => 'swfobject/swfobject.js',
26 'title' => t('SWFObject 1.5 - JavaScript'),
27 'download' => 'http://blog.deconcept.com/swfobject/#download',
28 );
29
30 return $methods;
31 }
32
33 /**
34 * Implementation of hook_swftools_embed().
35 * Returns the markup for the page, plus set necessary javascript.
36 *
37 * $methods and $vars should never be empty - unless the only reason for this call
38 * is to push the javascript into the header of the page in which case you don't
39 * add any paramters as all. This is useful for filtered nodes where the body is
40 * not regenerated every time.
41 */
42 function swfobject_swftools_embed($action = 'add_js', $methods = FALSE, $vars = FALSE, $html_alt = '') {
43
44 static $swfobject_has_run;
45 static $swfobject_id = 0;
46
47 // Output javascript to the header
48 if (!$swfobject_has_run) {
49 // Add swfobject.js
50 drupal_add_js(swftools_get_player_path() .'/swfobject/swfobject.js');
51 drupal_add_js(_swfobject_header_js(), 'inline', 'header');
52 $swfobject_has_run = TRUE;
53 if ($action == 'add_js') {
54 // Exit early having put the javascript in the header.
55 return;
56 }
57 }
58 static $unique_id = 0;
59 $unique_id++;
60
61 // SWFObject needs an id so that the replacement script can take it as a parameter.
62 // Use time() to prevent caching issues.
63 $html = '<div id="swfobject-id-'. time() . $unique_id .'" class="swftools swfobject" '.
64 swftools_json_params($vars->params, 'swftools') .' '.">\n".
65 $html_alt .
66 '</div>';
67 return $html;
68 }
69
70 /**
71 * The jQuery code that will try to replace all elements after the page loads.
72 * This parses the JSON out of the 'swftools' attribute of all class="swfobject" divs.
73 *
74 */
75 function _swfobject_header_js() {
76 $js = "
77 $(document).ready(function(){
78 $('.swfobject').each(function(i){
79 params = Drupal.parseJson($(this).attr('swftools'));
80 var so = new SWFObject(params['src'], '', params['width'], params['height'], params['version'], params['bgcolor']);
81 for (p in params) {
82 so.addParam(p, params[p]);
83 }
84 so.addVariable('flashvars', '&'+ params['flashvars']);
85 so.write(this.id);
86 });
87 });
88 ";
89 return $js;
90 }

  ViewVC Help
Powered by ViewVC 1.1.2