projekktor.builder.es6.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * @file
  3. * Audiofield build Projekktor audio player.
  4. */
  5. (($, Drupal) => {
  6. 'use strict';
  7. Drupal.AudiofieldProjekktor = {};
  8. /**
  9. * Generate a projekktor 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.AudiofieldProjekktor.generate = (context, file, settings) => {
  19. $.each($(context).find(`#${file}`).once('generate-projekktor'), (index, item) => {
  20. projekktor($(item), {
  21. debug: false,
  22. playerFlashMP4: settings.swfpath,
  23. playerFlashMP3: settings.swfpath,
  24. enableFullscreen: false,
  25. streamType: 'http',
  26. controls: true,
  27. thereCanBeOnlyOne: true,
  28. volume: settings.volume,
  29. autoplay: !!settings.autoplay,
  30. plugin_display: {},
  31. }, {});
  32. });
  33. };
  34. /**
  35. * Attach the behaviors to generate the audio player.
  36. *
  37. * @type {Drupal~behavior}
  38. *
  39. * @prop {Drupal~behaviorAttach} attach
  40. * Attaches generation of Projekktor audio players.
  41. */
  42. Drupal.behaviors.audiofieldprojekktor = {
  43. attach: (context, settings) => {
  44. // Have to encapsulate because of the way library is created.
  45. jQuery(() => {
  46. $.each(settings.audiofieldprojekktor, (key, settingEntry) => {
  47. // Loop over the attached files.
  48. $.each(settingEntry.files, (key2, file) => {
  49. // Create the audioplayer for each file.
  50. Drupal.AudiofieldProjekktor.generate(context, file, settingEntry);
  51. });
  52. });
  53. });
  54. },
  55. };
  56. })(jQuery, Drupal);