settings.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. (function($){
  2. FLBuilder.registerModuleHelper('audio', {
  3. init: function()
  4. {
  5. var form = $('.fl-builder-settings'),
  6. type = form.find('select[name=audio_type]'),
  7. audioField = form.find('input[name=audios]');
  8. type.on('change', $.proxy(this._audioFieldChanged, this));
  9. audioField.on('change', $.proxy(this._audioFieldChanged, this));
  10. this._audioFieldChanged();
  11. },
  12. _audioFieldChanged: function()
  13. {
  14. var form = $('.fl-builder-settings'),
  15. audio = form.find('input[name=audios]'),
  16. count = audio.val() == '' ? 0 : parseInt(JSON.parse(audio.val()).length),
  17. type = form.find('select[name=audio_type]').val(),
  18. toggle = form.find('.fl-multiple-audios-field').attr('data-toggle'),
  19. playlistFields = [],
  20. singleAudioFields = [],
  21. i = 0;
  22. if (typeof toggle !== 'undefined') {
  23. toggle = JSON.parse(toggle);
  24. playlistFields = toggle['playlist'].fields;
  25. singleAudioFields = toggle['single_audio'].fields;
  26. // Only show playlist options if user selected more than one files
  27. if (count > 1 && type == 'media_library') {
  28. this._showhide(singleAudioFields, 'hide');
  29. this._showhide(playlistFields, 'show');
  30. }
  31. else if ((count == 1 && type == 'media_library') || (type == 'link')) {
  32. this._showhide(playlistFields, 'hide');
  33. this._showhide(singleAudioFields, 'show');
  34. }
  35. else {
  36. // Hide by default
  37. this._showhide(playlistFields, 'hide');
  38. this._showhide(singleAudioFields, 'hide');
  39. }
  40. }
  41. },
  42. _showhide: function(fieldArray, method) {
  43. var i = 0;
  44. if(typeof fieldArray !== 'undefined') {
  45. for( ; i < fieldArray.length; i++) {
  46. $('#fl-field-' + fieldArray[i])[method]();
  47. }
  48. }
  49. }
  50. });
  51. })(jQuery);