wordpress.builder.es6.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * @file
  3. * Audiofield build WordPress audio player.
  4. */
  5. (($, Drupal) => {
  6. 'use strict';
  7. Drupal.AudiofieldWordpress = {};
  8. /**
  9. * Generate a wordpress player.
  10. *
  11. * @param {jQuery} context
  12. * The Drupal context for which we are finding and generating this player.
  13. * @param {array} file
  14. * The audio file for which we are generating a player.
  15. * @param {jQuery} settings
  16. * The Drupal settings for this player.
  17. */
  18. Drupal.AudiofieldWordpress.generate = (context, file, settings) => {
  19. let autostartSetting = 'no';
  20. if (!!settings.autoplay) {
  21. autostartSetting = 'yes';
  22. }
  23. $.each($(context).find(`#wordpressaudioplayer_${file.unique_id}`).once('generate-waveform'), (index, item) => {
  24. AudioPlayer.embed($(item).attr('id'), {
  25. soundFile: file.file,
  26. titles: file.title,
  27. autostart: autostartSetting,
  28. loop: 'no',
  29. initialvolume: settings.volume,
  30. checkpolicy: 'yes',
  31. animation: settings.animate,
  32. });
  33. });
  34. };
  35. /**
  36. * Attach the behaviors to generate the audio player.
  37. *
  38. * @type {Drupal~behavior}
  39. *
  40. * @prop {Drupal~behaviorAttach} attach
  41. * Attaches generation of Wordpress audio players.
  42. */
  43. Drupal.behaviors.audiofieldwordpress = {
  44. attach: function buildWordpressPlayers(context, settings) {
  45. $.each(settings.audiofieldwordpress, (key, settingEntry) => {
  46. // Initialize the audioplayer.
  47. AudioPlayer.setup('/libraries/wordpress-audio/player.swf', {
  48. width: 400,
  49. initialvolume: settingEntry.volume,
  50. transparentpagebg: 'yes',
  51. });
  52. // Loop over the files.
  53. $.each(settingEntry.files, (key2, fileEntry) => {
  54. // Generate the player for each file.
  55. Drupal.AudiofieldWordpress.generate(context, fileEntry, settingEntry);
  56. });
  57. });
  58. },
  59. };
  60. })(jQuery, Drupal);