audiojs.builder.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * DO NOT EDIT THIS FILE.
  3. * See the following change record for more information,
  4. * https://www.drupal.org/node/2815083
  5. * @preserve
  6. **/
  7. (function ($, Drupal) {
  8. 'use strict';
  9. Drupal.AudiofieldAudiojs = {};
  10. Drupal.AudiofieldAudiojs.generate = function (context, settings) {
  11. $.each($(context).find('#' + settings.element).once('generate-audiojs'), function (index, item) {
  12. var audioPlayer = audiojs.create($(item).find('audio').get(0), {
  13. css: false,
  14. createPlayer: {
  15. markup: false,
  16. playPauseClass: 'play-pauseZ',
  17. scrubberClass: 'scrubberZ',
  18. progressClass: 'progressZ',
  19. loaderClass: 'loadedZ',
  20. timeClass: 'timeZ',
  21. durationClass: 'durationZ',
  22. playedClass: 'playedZ',
  23. errorMessageClass: 'error-messageZ',
  24. playingClass: 'playingZ',
  25. loadingClass: 'loadingZ',
  26. errorClass: 'errorZ'
  27. },
  28. trackEnded: function trackEnded() {
  29. var next = $(context).find('#' + settings.element + ' ol li.playing').next();
  30. if (!next.length) {
  31. next = $(context).find('#' + settings.element + ' ol li:first');
  32. }
  33. next.addClass('playing').siblings().removeClass('playing');
  34. audioPlayer.load($('a', next).attr('data-src'));
  35. audioPlayer.play();
  36. }
  37. });
  38. $(item).find('ol li:first').addClass('playing');
  39. audioPlayer.load($(item).find('ol a:first').attr('data-src'));
  40. $(item).find('ol li').click(function (event) {
  41. event.preventDefault();
  42. $(event.currentTarget).addClass('playing').siblings().removeClass('playing');
  43. audioPlayer.load($('a', event.currentTarget).attr('data-src'));
  44. audioPlayer.play();
  45. });
  46. });
  47. };
  48. Drupal.behaviors.audiofieldaudiojs = {
  49. attach: function attach(context, settings) {
  50. $.each(settings.audiofieldaudiojs, function (key, settingEntry) {
  51. Drupal.AudiofieldAudiojs.generate(context, settingEntry);
  52. });
  53. }
  54. };
  55. })(jQuery, Drupal);