media.format_form.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * @file
  3. * Attach behaviors to formatter radio select when selecting a media's display
  4. * formatter.
  5. */
  6. (function ($) {
  7. namespace('Drupal.media.formatForm');
  8. Drupal.media.mediaFormatSelected = {};
  9. Drupal.behaviors.mediaFormatForm = {
  10. attach: function (context, settings) {
  11. // Add "Submit" and "Cancel" buttons inside the IFRAME that trigger the
  12. // behavior of the hidden "OK" and "Cancel" buttons that are outside the
  13. // IFRAME. See Drupal.media.browser.validateButtons() for more details.
  14. $('<a class="button fake-ok">' + Drupal.t('Submit') + '</a>').appendTo($('#media-format-form')).bind('click', Drupal.media.formatForm.submit);
  15. $('<a class="button fake-cancel">' + Drupal.t('Cancel') + '</a>').appendTo($('#media-format-form')).bind('click', Drupal.media.formatForm.submit);
  16. if (Drupal.settings.media_format_form.autosubmit) {
  17. $('.button.fake-ok').click();
  18. }
  19. }
  20. };
  21. Drupal.media.formatForm.getOptions = function () {
  22. // Get all the values
  23. var ret = {}; $.each($('#media-format-form fieldset#edit-options *').serializeArray(), function (i, field) { ret[field.name] = field.value; });
  24. return ret;
  25. };
  26. Drupal.media.formatForm.getFormattedMedia = function () {
  27. var formatType = $("select#edit-format option:selected").val();
  28. return { type: formatType, options: Drupal.media.formatForm.getOptions(), html: Drupal.settings.media.formatFormFormats[formatType] };
  29. };
  30. Drupal.media.formatForm.submit = function () {
  31. // @see Drupal.behaviors.mediaFormatForm.attach().
  32. var buttons = $(parent.window.document.body).find('#mediaStyleSelector').parent('.ui-dialog').find('.ui-dialog-buttonpane button');
  33. if ($(this).hasClass('fake-cancel')) {
  34. buttons[1].click();
  35. } else {
  36. buttons[0].click();
  37. }
  38. }
  39. })(jQuery);