/ffmpeg_wrapper.js

https://gitlab.com/vozmob/ffmpeg_wrapper · JavaScript · 115 lines · 55 code · 17 blank · 43 comment · 17 complexity · b5d4a07f85368c2a4fa4bc63e8b9e743 MD5 · raw file

  1. /**
  2. * @param string $prefix is the prefix of the elements
  3. * @param string $source is the source for the output type
  4. */
  5. function ffmpeg_wrapper_update_options(prefix, source) {
  6. // get the path to the output settings set in ffmpeg_wrapper module
  7. var path = Drupal.settings.ffmpeg_wrapper.ffmpeg_wrapper_output_url;
  8. // get the output type
  9. var output = $('#'+prefix+source).val();
  10. // only look for the value if there is one selected
  11. if (output != 0) {
  12. // now get the values for this codec
  13. $.getJSON(path+output, function(json) {
  14. // now we need to itterate through each of the keys returned and
  15. // limit the choices to the incoming values.
  16. var data = eval (json);
  17. // first break the configuration into the types of config data we have
  18. for (var type in data) {
  19. // catch the flag for default settings and don't do
  20. // any form updating for this value
  21. if (data[type] != 'default') {
  22. // now get each of the items in the config
  23. // types here are 'audio' and 'video'
  24. for (var key in data[type] ) {
  25. // build the element from the prefix value: ffmpeg & the kind of item it is & the key
  26. var element = '#'+prefix+'ffmpeg-'+type+'-'+key;
  27. // make sure element exists
  28. if ($(element)) {
  29. // remove existing html from this select box
  30. $(element).html('');
  31. var html = '';
  32. // break each of the options out for each select box
  33. for (var option in data[type][key]) {
  34. // create the description for this element
  35. var description = data[type][key][option].valueOf();
  36. // now we check to see if the option coming in contains
  37. // the default value for this configuration so we know to use it as default
  38. // make a new variable to properly type cast the value
  39. var test = ''+data[type][key][option]+'';
  40. // search this string for the "default" text and save it for
  41. // use after the select is rebuilt
  42. if (test.match(Drupal.settings.ffmpeg_wrapper.default_string) ) {
  43. var selected = option;
  44. }
  45. // now build the html for the select options
  46. html += ffmpeg_wrapper_select_builder(option, description);
  47. }
  48. // build the new select element
  49. $(element).html(html);
  50. // now update the selected value
  51. if (selected) {
  52. $(element).val(selected);
  53. selected = null;
  54. }
  55. }
  56. }
  57. // now turn on the advanced options so they are picked up
  58. $('#'+prefix+'ffmpeg-'+type+'-advanced').attr('checked', true);
  59. }
  60. else {
  61. // is the configuration data being passed back was the default data?
  62. // turn off the advanced configuration so that nothing nasty
  63. // happens without user action
  64. $('#'+prefix+'ffmpeg-audio-advanced').attr('checked', false);
  65. $('#'+prefix+'ffmpeg-video-advanced').attr('checked', false);
  66. }
  67. }
  68. });
  69. }
  70. }
  71. /**
  72. * this builds the html for the output of the selects
  73. * simple function but makes code easier
  74. * @param string $value is the key value
  75. * @param string $description is the text value
  76. */
  77. function ffmpeg_wrapper_select_builder(value, description) {
  78. if (selected) { var selected = 'selected'; }
  79. else { var selected = ''; }
  80. return '<option value="'+value+'">'+description+'</option>';
  81. }
  82. /**
  83. * This shows and hides the frame size other option in the
  84. * video options dropdown
  85. */
  86. if (Drupal.jsEnabled) {
  87. $(document).ready(function () {
  88. // get the video size element
  89. $('#edit-ffmpeg-video-size').bind('change', function () {
  90. if ($(this).val() == 'other'){
  91. $('#edit-ffmpeg-video-size-other').show('slow');
  92. }
  93. else {
  94. $('#edit-ffmpeg-video-size-other').hide('slow');
  95. }
  96. });
  97. });
  98. }