1(function ($, window, Drupal, drupalSettings) { 2 /** 3 * Prepare the Ajax request before it is sent. 4 * 5 * @param {XMLHttpRequest} xmlhttprequest 6 * @param {object} options 7 * @param {object} options.extraData 8 */ 9 Drupal.Ajax.prototype.beforeSend = function (xmlhttprequest, options) { 10 // For forms without file inputs, the jQuery Form plugin serializes the 11 // form values, and then calls jQuery's $.ajax() function, which invokes 12 // this handler. In this circumstance, options.extraData is never used. For 13 // forms with file inputs, the jQuery Form plugin uses the browser's normal 14 // form submission mechanism, but captures the response in a hidden IFRAME. 15 // In this circumstance, it calls this handler first, and then appends 16 // hidden fields to the form to submit the values in options.extraData. 17 // There is no simple way to know which submission mechanism will be used, 18 // so we add to extraData regardless, and allow it to be ignored in the 19 // former case. 20 if (this.$form) { 21 options.extraData = options.extraData || {}; 22 23 // Let the server know when the IFRAME submission mechanism is used. The 24 // server can use this information to wrap the JSON response in a 25 // TEXTAREA, as per http://jquery.malsup.com/form/#file-upload. 26 options.extraData.ajax_iframe_upload = '1'; 27 28 // The triggering element is about to be disabled (see below), but if it 29 // contains a value (e.g., a checkbox, textfield, select, etc.), ensure 30 // that value is included in the submission. As per above, submissions 31 // that use $.ajax() are already serialized prior to the element being 32 // disabled, so this is only needed for IFRAME submissions. 33 const v = $.fieldValue(this.element); 34 if (v !== null) { 35 options.extraData[this.element.name] = v; 36 } 37 } 38 39 // Disable the element that received the change to prevent user interface 40 // interaction while the Ajax request is in progress. ajax.ajaxing prevents 41 // the element from triggering a new request, but does not prevent the user 42 // from changing its value. 43 $(this.element).prop('disabled', true); 44 45 if (!this.progress || !this.progress.type) { 46 return; 47 } 48 49 // Insert progress indicator. 50 let callable = this.progress.type; 51 if ( 52 this.progress.type === 'throbber' && 53 drupalSettings.ajaxLoader.alwaysFullscreen 54 ) { 55 // Always show throbber as fullscreen overlay. 56 callable = 'fullscreen'; 57 } 58 const progressIndicatorMethod = `setProgressIndicator${callable 59 .slice(0, 1) 60 .toUpperCase()}${callable.slice(1).toLowerCase()}`; 61 if ( 62 progressIndicatorMethod in this && 63 typeof this[progressIndicatorMethod] === 'function' 64 ) { 65 this[progressIndicatorMethod].call(this); 66 } 67 }; 68 69 /** 70 * Overrides the throbber progress indicator. 71 */ 72 Drupal.Ajax.prototype.setProgressIndicatorThrobber = function () { 73 if (!this.progressIsSet()) { 74 this.progress.element = $( 75 `<div class="ajax-progress ajax-progress-throbber"><div class="ajax-loader">${drupalSettings.ajaxLoader.markup}</div></div>`, 76 ); 77 if (this.progress.message && !drupalSettings.ajaxLoader.hideAjaxMessage) { 78 this.progress.element 79 .find('.ajax-loader') 80 .after(`<div class="message">${this.progress.message}</div>`); 81 } 82 $(this.element).after(this.progress.element); 83 } 84 }; 85 86 /** 87 * Sets the fullscreen progress indicator. 88 */ 89 Drupal.Ajax.prototype.setProgressIndicatorFullscreen = function () { 90 if (!this.progressIsSet()) { 91 this.progress.element = $( 92 `<div class="ajax-progress ajax-progress-fullscreen">${drupalSettings.ajaxLoader.markup}</div>`, 93 ); 94 $(drupalSettings.ajaxLoader.throbberPosition).after( 95 this.progress.element, 96 ); 97 } 98 }; 99 100 /** 101 * Check ajax throbber is not already set. 102 */ 103 Drupal.Ajax.prototype.progressIsSet = function () { 104 // return false; 105 return ( 106 this.progress.type !== 'throbber' && 107 this.progress.hasOwnProperty('element') && 108 this.progress.element.hasOwnProperty('length') && 109 this.progress.element.length > 0 110 ); 111 }; 112})(jQuery, this, Drupal, drupalSettings);
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.