/**
* DO NOT EDIT THIS FILE.
* See the following change record for more information,
* https://www.drupal.org/node/2815083
* @preserve
**/

(function ($, Drupal) {
  'use strict';

  Drupal.AudiofieldWordpress = {};

  Drupal.AudiofieldWordpress.generate = function (context, file, settings) {
    var autostartSetting = 'no';
    if (!!settings.autoplay) {
      autostartSetting = 'yes';
    }
    $.each($(context).find('#wordpressaudioplayer_' + file.unique_id).once('generate-waveform'), function (index, item) {
      AudioPlayer.embed($(item).attr('id'), {
        soundFile: file.file,
        titles: file.title,
        autostart: autostartSetting,
        loop: 'no',
        initialvolume: settings.volume,
        checkpolicy: 'yes',
        animation: settings.animate
      });
    });
  };

  Drupal.behaviors.audiofieldwordpress = {
    attach: function buildWordpressPlayers(context, settings) {
      $.each(settings.audiofieldwordpress, function (key, settingEntry) {
        AudioPlayer.setup('/libraries/wordpress-audio/player.swf', {
          width: 400,
          initialvolume: settingEntry.volume,
          transparentpagebg: 'yes'
        });

        $.each(settingEntry.files, function (key2, fileEntry) {
          Drupal.AudiofieldWordpress.generate(context, fileEntry, settingEntry);
        });
      });
    }
  };
})(jQuery, Drupal);