mediaelement.builder.es6.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * @file
  3. * Audiofield build MediaElement audio player.
  4. */
  5. (($, Drupal) => {
  6. 'use strict';
  7. Drupal.AudiofieldMediaelement = {};
  8. /**
  9. * Generate a mediaelement 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.AudiofieldMediaelement.generate = (context, file, settings) => {
  19. // Create the media player.
  20. $(file, context).once('generate-mediaelement').mediaelementplayer({
  21. startVolume: settings.volume,
  22. loop: false,
  23. enableAutosize: true,
  24. isVideo: false,
  25. });
  26. };
  27. /**
  28. * Attach the behaviors to generate the audio player.
  29. *
  30. * @type {Drupal~behavior}
  31. *
  32. * @prop {Drupal~behaviorAttach} attach
  33. * Attaches generation of MediaElement audio players.
  34. */
  35. Drupal.behaviors.audiofieldmediaelement = {
  36. attach: (context, settings) => {
  37. $.each(settings.audiofieldmediaelement, (key, settingEntry) => {
  38. // Loop over each file.
  39. $.each(settingEntry.elements, (key2, fileEntry) => {
  40. // Create the media player.
  41. Drupal.AudiofieldMediaelement.generate(context, fileEntry, settingEntry);
  42. });
  43. });
  44. },
  45. };
  46. })(jQuery, Drupal);