Permalink
Browse files

fix(zaudio): Convert zaudio JS to AMD modules

Fixes #8283
  • Loading branch information...
mrclay committed May 13, 2015
1 parent f6fa7b7 commit 674899e070273bc4915c32dbd21d2d4398d99321
View
@@ -13,6 +13,12 @@
function zaudio_init() {
elgg_extend_view('css/elgg', 'zaudio/css');
elgg_define_js('AudioPlayer', [
'src' => 'mod/zaudio/audioplayer/audio-player.js',
'exports' => 'AudioPlayer',
]);
// leave library registered for BC
$js_url = elgg_get_site_url() . 'mod/zaudio/audioplayer/audio-player.js';
elgg_register_js('elgg.zaudio', $js_url);
}
@@ -0,0 +1,30 @@
define(function (require) {
// dependencies
var AudioPlayer = require('AudioPlayer');
var $ = require('jquery');
var elgg = require('elgg');
// for unique IDs
var i = 0;
AudioPlayer.setup(elgg.get_site_url() + "mod/zaudio/audioplayer/player.swf", {width: 290});
function embed(element) {
var config = $(element).data().zaudioPlayer;
if (!element.id) {
element.id = "zaudio" + i;
i++;
}
AudioPlayer.embed(element.id, config);
}
// apply to those in page
$('[data-zaudio-player]').each(function () {
embed(this);
});
// embed can be used for new elements added to the page
return embed;
});
@@ -4,20 +4,16 @@
* @package ElggZAudio
*/
elgg_load_js('elgg.zaudio');
elgg_require_js('elgg/zaudio');
$swf_url = elgg_get_site_url() . 'mod/zaudio/audioplayer/player.swf';
$mp3_url = elgg_get_site_url() . "mod/file/download.php?file_guid={$vars['file_guid']}";
$player_options = [
'soundFile' => elgg_get_site_url() . "file/download/{$vars['file_guid']}",
// more options: http://wpaudioplayer.com/standalone/
];
?>
<?php //@todo JS 1.8: no ?>
<script>
AudioPlayer.setup("<?php echo $swf_url; ?>", {width: 290});
</script>
<div class="zaudio">
<p id="zaudioplayer"></p>
<script>
AudioPlayer.embed("zaudioplayer", {soundFile: "<?php echo $mp3_url; ?>"});
</script>
</div>
<?php echo elgg_format_element('div', [
'data-zaudio-player' => json_encode($player_options),
]); ?>
</div>

0 comments on commit 674899e

Please sign in to comment.