5 (function ($, Drupal, Bootstrap) {
7 Drupal.behaviors.dialog.ajaxCurrentButton = null;
8 Drupal.behaviors.dialog.ajaxOriginalButton = null;
11 * Synchronizes a faux button with its original counterpart.
13 * @param {Boolean} [reset = false]
14 * Whether to reset the current and original buttons after synchronizing.
16 Drupal.behaviors.dialog.ajaxUpdateButtons = function (reset) {
17 if (this.ajaxCurrentButton && this.ajaxOriginalButton) {
18 this.ajaxCurrentButton.html(this.ajaxOriginalButton.html());
19 this.ajaxCurrentButton.prop('disabled', this.ajaxOriginalButton.prop('disabled'));
22 this.ajaxCurrentButton = null;
23 this.ajaxOriginalButton = null;
28 .ajaxSend(function () {
29 Drupal.behaviors.dialog.ajaxUpdateButtons();
31 .ajaxComplete(function () {
32 Drupal.behaviors.dialog.ajaxUpdateButtons(true);
39 Drupal.behaviors.dialog.prepareDialogButtons = function prepareDialogButtons($dialog) {
42 var $buttons = $dialog.find('.form-actions').find('button, input[type=submit], .form-actions a.button');
43 $buttons.each(function () {
44 var $originalButton = $(this)
45 // Prevent original button from being tabbed to.
47 // Visually make the original button invisible, but don't actually hide
48 // or remove it from the DOM because the click needs to be proxied from
49 // the faux button created in the footer to its original counterpart.
60 // Strip all HTML from the actual text value. This value is escaped.
61 // It actual HTML value will be synced with the original button's HTML
62 // below in the "create" method.
63 text: Bootstrap.stripHtml($originalButton),
64 class: $originalButton.attr('class').replace('use-ajax-submit', ''),
65 click: function click(e) {
68 _that.ajaxCurrentButton = $(e.target);
69 _that.ajaxOriginalButton = $originalButton;
70 Bootstrap.simulate($originalButton, 'click');
73 _that.ajaxCurrentButton = $(this);
74 _that.ajaxOriginalButton = $originalButton;
75 _that.ajaxUpdateButtons(true);
83 })(window.jQuery, window.Drupal, window.Drupal.bootstrap);