Projet

Général

Profil

Paste
Télécharger (2,57 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / media / js / media.format_form.js @ 74f6bef0

1

    
2
/**
3
 *  @file
4
 *  Attach behaviors to formatter radio select when selecting a media's display
5
 *  formatter.
6
 */
7

    
8
(function ($) {
9
namespace('Drupal.media.formatForm');
10

    
11
Drupal.media.mediaFormatSelected = {};
12

    
13
Drupal.behaviors.mediaFormatForm = {
14
  attach: function (context, settings) {
15

    
16
    // Add "Submit" and "Cancel" buttons inside the IFRAME that trigger the
17
    // behavior of the hidden "OK" and "Cancel" buttons that are outside the
18
    // IFRAME. See Drupal.media.browser.validateButtons() for more details.
19

    
20
    // @note I think this should be handled in media.browser.js in
21
    //       Drupal.media.browser.validateButtons but I'm not sure how crufty
22
    //       this particular functionality is. We should evaluate if it is still
23
    //       needed.
24

    
25
    // @TODO can these be added to the content being displayed via form_alter?
26

    
27
    // Adding the buttons should only be done once in order to prevent multiple
28
    // buttons from being added if part of the form is updated via AJAX
29
    $('#media-format-form').once('format', function() {
30
      $('<a class="button fake-ok">' + Drupal.t('Submit') + '</a>').appendTo($('#media-format-form')).bind('click', Drupal.media.formatForm.submit);
31
      $('<a class="button fake-cancel">' + Drupal.t('Cancel') + '</a>').appendTo($('#media-format-form')).bind('click', Drupal.media.formatForm.submit);
32
    });
33

    
34
    // Resize the window on load.
35
    // @TODO this duplicates Drupal.media.browser.resizeIframe()
36
    //       can we put a resize function into media.core.js?
37
    $(document).ready(function () {
38
      // Get the height and add a bit of padding to acomidate the form buttons.
39
      var h = $('body').height() + 20;
40
      $(parent.window.document).find('#mediaStyleSelector').height(h);
41
    });
42

    
43
  }
44
};
45

    
46
Drupal.media.formatForm.getOptions = function () {
47
  // Get all the values
48
  var ret = {}; $.each($('#media-format-form fieldset#edit-options *').serializeArray(), function (i, field) { ret[field.name] = field.value; });
49
  return ret;
50
};
51

    
52
Drupal.media.formatForm.getFormattedMedia = function () {
53
  var formatType = $("select#edit-format option:selected").val();
54
  return { type: formatType, options: Drupal.media.formatForm.getOptions(), html: Drupal.settings.media.formatFormFormats[formatType] };
55
};
56

    
57
Drupal.media.formatForm.submit = function () {
58
  // @see Drupal.behaviors.mediaFormatForm.attach().
59
  var buttons = $(parent.window.document.body).find('#mediaStyleSelector').parent('.ui-dialog').find('.ui-dialog-buttonpane button');
60
  if ($(this).hasClass('fake-cancel')) {
61
    buttons[1].click();
62
  } else {
63
    buttons[0].click();
64
  }
65
}
66

    
67
})(jQuery);