root / drupal7 / sites / all / modules / media / modules / media_wysiwyg / js / media_wysiwyg.format_form.js @ ca0757b9
1 | ca0757b9 | Assos Assos | |
---|---|---|---|
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 | // Add the "Submit" button inside the IFRAME that trigger the behavior of
|
||
16 | // the hidden "OK" button that is outside the IFRAME.
|
||
17 | // @see Drupal.media.browser.validateButtons() for more details.
|
||
18 | |||
19 | // @note I think this should be handled in media.browser.js in
|
||
20 | // Drupal.media.browser.validateButtons but I'm not sure how crufty this
|
||
21 | // particular functionality is. We should evaluate if it is still needed.
|
||
22 | |||
23 | // @TODO can these be added to the content being displayed via form_alter?
|
||
24 | |||
25 | // Adding the buttons should only be done once in order to prevent multiple
|
||
26 | // buttons from being added if part of the form is updated via AJAX
|
||
27 | $('#media-wysiwyg-format-form').once('format', function() { |
||
28 | $('<a class="button fake-ok">' + Drupal.t('Submit') + '</a>').appendTo($('#media-wysiwyg-format-form')).bind('click', Drupal.media.formatForm.submit); |
||
29 | }); |
||
30 | } |
||
31 | }; |
||
32 | |||
33 | Drupal.media.formatForm.getOptions = function () { |
||
34 | // Get all the values
|
||
35 | var ret = {};
|
||
36 | |||
37 | $.each($('#media-wysiwyg-format-form .fieldset-wrapper *').serializeArray(), function (i, field) { |
||
38 | ret[field.name] = field.value; |
||
39 | |||
40 | // When a field uses a WYSIWYG format, the value needs to be extracted.
|
||
41 | if (field.name.match(/\[format\]/i)) { |
||
42 | field.name = field.name.replace(/\[format\]/i, '[value]'); |
||
43 | field.key = 'edit-' + field.name.replace(/[_\[]/g, '-').replace(/[\]]/g, ''); |
||
44 | |||
45 | if (Drupal.wysiwyg.instances[field.key]) {
|
||
46 | // Retrieve the content from the WYSIWYG instance.
|
||
47 | ret[field.name] = Drupal.wysiwyg.instances[field.key].getContent(); |
||
48 | |||
49 | // Escape the double-quotes and encode it to play nicely within JSON.
|
||
50 | ret[field.name] = encodeURIComponent(ret[field.name].replace(/"/g, '\\"')); |
||
51 | } |
||
52 | } |
||
53 | }); |
||
54 | |||
55 | return ret;
|
||
56 | }; |
||
57 | |||
58 | Drupal.media.formatForm.getFormattedMedia = function () { |
||
59 | var formatType = $("#edit-format").val(); |
||
60 | return { type: formatType, options: Drupal.media.formatForm.getOptions(), html: Drupal.settings.media.formatFormFormats[formatType] }; |
||
61 | }; |
||
62 | |||
63 | Drupal.media.formatForm.submit = function () { |
||
64 | // @see Drupal.behaviors.mediaFormatForm.attach().
|
||
65 | var buttons = $(parent.window.document.body).find('#mediaStyleSelector').parent('.ui-dialog').find('.ui-dialog-buttonpane button'); |
||
66 | buttons[0].click();
|
||
67 | } |
||
68 | |||
69 | })(jQuery); |