| 1 |
<?php
|
| 2 |
// $Id: lutman.module,v 1.6 2009/03/06 19:48:00 stuartgreenfield Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* SWF Tools - Luke Lutman Flash Replacement
|
| 6 |
*
|
| 7 |
* Enables the use of Luke Lutman's jquery.flash.js which ships with
|
| 8 |
* the SWF Tools module. jquery.flash.js provides Flash replacement
|
| 9 |
* techniques.
|
| 10 |
*
|
| 11 |
* Author's Site.
|
| 12 |
* http://jquery.lukelutman.com/plugins/flash/
|
| 13 |
*/
|
| 14 |
|
| 15 |
/**
|
| 16 |
* Implementation of hook_swftools_methods().
|
| 17 |
*/
|
| 18 |
function lutman_swftools_methods() {
|
| 19 |
|
| 20 |
$methods = array();
|
| 21 |
|
| 22 |
$methods[SWFTOOLS_EMBED]['lutman_replace'] = array (
|
| 23 |
'name' => 'lutman_replace',
|
| 24 |
'module' => 'lutman',
|
| 25 |
'shared_file' => 'lutman/jquery.flash.js',
|
| 26 |
'title' => t('jQuery Flash plugin - JavaScript'),
|
| 27 |
'download' => 'http://jquery.lukelutman.com/plugins/flash/',
|
| 28 |
);
|
| 29 |
|
| 30 |
return $methods;
|
| 31 |
}
|
| 32 |
|
| 33 |
/**
|
| 34 |
* Implementation of hook_swftools_embed().
|
| 35 |
*/
|
| 36 |
function lutman_swftools_embed($action = 'add_js', $methods = FALSE, $vars = FALSE, $html_alt = '') {
|
| 37 |
|
| 38 |
static $lutman_has_run;
|
| 39 |
|
| 40 |
// Output javascript to the header
|
| 41 |
if (!$lutman_has_run) {
|
| 42 |
// Add jquery.flash.js
|
| 43 |
drupal_add_js(swftools_get_player_path() .'/lutman/jquery.flash.js');
|
| 44 |
drupal_add_js(_lutman_header_js(), 'inline', 'header');
|
| 45 |
$lutman_has_run = TRUE;
|
| 46 |
if ($action == 'add_js') {
|
| 47 |
// Exit early having put the javascript in the header.
|
| 48 |
return;
|
| 49 |
}
|
| 50 |
}
|
| 51 |
|
| 52 |
// Initialise a counter to give each div a unique id
|
| 53 |
static $unique_id = 0;
|
| 54 |
$unique_id++;
|
| 55 |
|
| 56 |
// Construct a unique id for each div by using time() combined with $unique_id
|
| 57 |
// This is necessary to prevent clashes between cached content
|
| 58 |
$id = time() . $unique_id;
|
| 59 |
|
| 60 |
// Use time() to prevent caching issues.
|
| 61 |
$html = '<div id="swfobject-id-' . $id . '" class="swftools lutman" ' .
|
| 62 |
swftools_json_params($vars->params, 'swftools') . ' ' . ">\n" .
|
| 63 |
$html_alt .
|
| 64 |
'</div>';
|
| 65 |
return $html;
|
| 66 |
}
|
| 67 |
|
| 68 |
/**
|
| 69 |
* The jQuery code that will try to replace all elements after the page loads.
|
| 70 |
* This parses the JSON out of the 'data' attribute of all swftools-embed divs.
|
| 71 |
*
|
| 72 |
*/
|
| 73 |
function _lutman_header_js() {
|
| 74 |
$js = "
|
| 75 |
$(document).ready(function(){
|
| 76 |
$('.lutman').flash(null, {version:7}, function(htmlOptions) {
|
| 77 |
htmlOptions = Drupal.parseJson($(this).attr('swftools'));
|
| 78 |
$(this).parent().prepend($.fn.flash.transform(htmlOptions));
|
| 79 |
$(this).remove();
|
| 80 |
});
|
| 81 |
});
|
| 82 |
";
|
| 83 |
return $js;
|
| 84 |
}
|