1/** 2 * @file 3 * Extends methods from core/misc/ajax.js. 4 */ 5 6(function ($, window, Drupal, drupalSettings) { 7 8 /** 9 * Attempts to find the closest glyphicon progress indicator. 10 * 11 * @param {jQuery|Element} element 12 * A DOM element. 13 * 14 * @returns {jQuery} 15 * A jQuery object. 16 */ 17 Drupal.Ajax.prototype.findGlyphicon = function (element) { 18 return $(element).closest('.form-item').find('.ajax-progress.glyphicon') 19 }; 20 21 /** 22 * Starts the spinning of the glyphicon progress indicator. 23 * 24 * @param {jQuery|Element} element 25 * A DOM element. 26 * @param {string} [message] 27 * An optional message to display (tooltip) for the progress. 28 * 29 * @returns {jQuery} 30 * A jQuery object. 31 */ 32 Drupal.Ajax.prototype.glyphiconStart = function (element, message) { 33 var $glyphicon = this.findGlyphicon(element); 34 if ($glyphicon[0]) { 35 $glyphicon.addClass('glyphicon-spin'); 36 37 // Add any message as a tooltip to the glyphicon. 38 if ($.fn.tooltip && drupalSettings.bootstrap.tooltip_enabled) { 39 $glyphicon 40 .removeAttr('data-toggle') 41 .removeAttr('data-original-title') 42 .removeAttr('title') 43 .tooltip('destroy') 44 ; 45 46 if (message) { 47 $glyphicon.attr('data-toggle', 'tooltip').attr('title', message).tooltip(); 48 } 49 } 50 51 // Append a message for screen readers. 52 if (message) { 53 $glyphicon.parent().append('<div class="sr-only message">' + message + '</div>'); 54 } 55 } 56 return $glyphicon; 57 }; 58 59 /** 60 * Stop the spinning of a glyphicon progress indicator. 61 * 62 * @param {jQuery|Element} element 63 * A DOM element. 64 */ 65 Drupal.Ajax.prototype.glyphiconStop = function (element) { 66 var $glyphicon = this.findGlyphicon(element); 67 if ($glyphicon[0]) { 68 $glyphicon.removeClass('glyphicon-spin'); 69 if ($.fn.tooltip && drupalSettings.bootstrap.tooltip_enabled) { 70 $glyphicon 71 .removeAttr('data-toggle') 72 .removeAttr('data-original-title') 73 .removeAttr('title') 74 .tooltip('destroy') 75 ; 76 } 77 } 78 }; 79 80 /** 81 * Sets the throbber progress indicator. 82 */ 83 Drupal.Ajax.prototype.setProgressIndicatorThrobber = function () { 84 var $element = $(this.element); 85 86 // Find an existing glyphicon progress indicator. 87 var $glyphicon = this.glyphiconStart($element, this.progress.message); 88 if ($glyphicon[0]) { 89 this.progress.element = $glyphicon.parent(); 90 this.progress.glyphicon = true; 91 return; 92 } 93 94 // Otherwise, add a glyphicon throbber after the element. 95 if (!this.progress.element) { 96 this.progress.element = $(Drupal.theme('ajaxThrobber')); 97 } 98 if (this.progress.message) { 99 this.progress.element.after('<div class="message">' + this.progress.message + '</div>'); 100 } 101 102 // If element is an input DOM element type (not :input), append after. 103 if ($element.is('input') || $element.is('select')) { 104 $element.after(this.progress.element); 105 } 106 // Otherwise append the throbber inside the element. 107 else { 108 $element.append(this.progress.element); 109 } 110 }; 111 112 113 /** 114 * Handler for the form redirection completion. 115 * 116 * @param {Array.<Drupal.AjaxCommands~commandDefinition>} response 117 * @param {number} status 118 */ 119 var success = Drupal.Ajax.prototype.success; 120 Drupal.Ajax.prototype.success = function (response, status) { 121 if (this.progress.element) { 122 123 // Remove any message set. 124 this.progress.element.parent().find('.message').remove(); 125 } 126 127 // Invoke the original success handler. 128 return success.apply(this, [response, status]); 129 }; 130 131})(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.