1/** 2 * @file 3 * dialog.ajax.js 4 */ 5(function ($, Drupal, Bootstrap) { 6 7 Drupal.behaviors.dialog.ajaxCurrentButton = null; 8 Drupal.behaviors.dialog.ajaxOriginalButton = null; 9 10 // Intercept the success event to add the dialog type to commands. 11 var success = Drupal.Ajax.prototype.success; 12 Drupal.Ajax.prototype.success = function (response, status) { 13 if (this.dialogType) { 14 for (var i = 0, l = response.length; i < l; i++) { 15 if (response[i].dialogOptions) { 16 response[i].dialogType = response[i].dialogOptions.dialogType = this.dialogType; 17 response[i].$trigger = response[i].dialogOptions.$trigger = $(this.element); 18 } 19 } 20 } 21 return success.apply(this, [response, status]); 22 }; 23 24 var beforeSerialize = Drupal.Ajax.prototype.beforeSerialize; 25 Drupal.Ajax.prototype.beforeSerialize = function (element, options) { 26 // Add the dialog type currently in use. 27 if (this.dialogType) { 28 options.data['ajax_page_state[dialogType]'] = this.dialogType; 29 30 // Add the dialog element ID if it can be found (useful for closing it). 31 var id = $(this.element).parents('.js-drupal-dialog:first').attr('id'); 32 if (id) { 33 options.data['ajax_page_state[dialogId]'] = id; 34 } 35 } 36 return beforeSerialize.apply(this, arguments); 37 }; 38 39 /** 40 * Synchronizes a faux button with its original counterpart. 41 * 42 * @param {Boolean} [reset = false] 43 * Whether to reset the current and original buttons after synchronizing. 44 */ 45 Drupal.behaviors.dialog.ajaxUpdateButtons = function (reset) { 46 if (this.ajaxCurrentButton && this.ajaxOriginalButton) { 47 this.ajaxCurrentButton.html(this.ajaxOriginalButton.html() || this.ajaxOriginalButton.attr('value')); 48 this.ajaxCurrentButton.prop('disabled', this.ajaxOriginalButton.prop('disabled')); 49 } 50 if (reset) { 51 this.ajaxCurrentButton = null; 52 this.ajaxOriginalButton = null; 53 } 54 }; 55 56 $(document) 57 .ajaxSend(function () { 58 Drupal.behaviors.dialog.ajaxUpdateButtons(); 59 }) 60 .ajaxComplete(function () { 61 Drupal.behaviors.dialog.ajaxUpdateButtons(true); 62 }) 63 ; 64 65 /** 66 * {@inheritdoc} 67 */ 68 Drupal.behaviors.dialog.prepareDialogButtons = function prepareDialogButtons($dialog) { 69 var _this = this; 70 var buttons = []; 71 var $buttons = $dialog.find('.form-actions').find('button, input[type=submit], a.button, .btn'); 72 $buttons.each(function () { 73 var $originalButton = $(this) 74 // Prevent original button from being tabbed to. 75 .attr('tabindex', -1) 76 // Visually make the original button invisible, but don't actually hide 77 // or remove it from the DOM because the click needs to be proxied from 78 // the faux button created in the footer to its original counterpart. 79 .css({ 80 display: 'block', 81 width: 0, 82 height: 0, 83 padding: 0, 84 border: 0, 85 overflow: 'hidden' 86 }); 87 88 buttons.push({ 89 // Strip all HTML from the actual text value. This value is escaped. 90 // It actual HTML value will be synced with the original button's HTML 91 // below in the "create" method. 92 text: Bootstrap.stripHtml($originalButton) || $originalButton.attr('value'), 93 class: $originalButton.attr('class').replace('use-ajax-submit', ''), 94 click: function click(e) { 95 e.preventDefault(); 96 e.stopPropagation(); 97 _this.ajaxCurrentButton = $(e.target); 98 _this.ajaxOriginalButton = $originalButton; 99 // Some core JS binds dialog buttons to the mousedown or mouseup 100 // events instead of click; all three events must be simulated here. 101 // @see https://www.drupal.org/project/bootstrap/issues/3016254 102 Bootstrap.simulate($originalButton, ['mousedown', 'mouseup', 'click']); 103 }, 104 create: function () { 105 _this.ajaxCurrentButton = $(this); 106 _this.ajaxOriginalButton = $originalButton; 107 _this.ajaxUpdateButtons(true); 108 } 109 }); 110 }); 111 112 return buttons; 113 }; 114 115})(window.jQuery, window.Drupal, window.Drupal.bootstrap);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.