PageSourceSearch

https://alca-nouvelle-aquitaine.fr/sites/all/modules/dialog/misc/ajax.js?v=7.106

js alca-nouvelle-aquitaine.fr collected 2026-10-02 07:39:12 UTC 27,046 bytes, 720 lines download raw bytes

1(function ($) {
2
3/**
4 * Provides Ajax page updating via jQuery $.ajax (Asynchronous JavaScript and XML).
5 *
6 * Ajax is a method of making a request via JavaScript while viewing an HTML
7 * page. The request returns an array of commands encoded in JSON, which is
8 * then executed to make any changes that are necessary to the page.
9 *
10 * Drupal uses this file to enhance form elements with #ajax['path'] and
11 * #ajax['wrapper'] properties. If set, this file will automatically be included
12 * to provide Ajax capabilities.
13 */
14
15Drupal.ajax = Drupal.ajax || {};
16
17Drupal.settings.urlIsAjaxTrusted = Drupal.settings.urlIsAjaxTrusted || {};
18
19/**
20 * Attaches the Ajax behavior to each Ajax form element.
21 */
22Drupal.behaviors.AJAX = {
23  attach: function (context, settings) {
24    // Load all Ajax behaviors specified in the settings.
25    for (var base in settings.ajax) {
26      if (!$('#' + base + '.ajax-processed').length) {
27        var element_settings = settings.ajax[base];
28
29        if (typeof element_settings.selector == 'undefined') {
30          element_settings.selector = '#' + base;
31        }
32        $(element_settings.selector).each(function () {
33          element_settings.element = this;
34          Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings);
35        });
36
37        $('#' + base).addClass('ajax-processed');
38      }
39    }
40
41    // Bind Ajax behaviors to all items showing the class.
42    $('.use-ajax:not(.ajax-processed)').addClass('ajax-processed').each(function () {
43      var element_settings = {};
44      // Clicked links look better with the throbber than the progress bar.
45      element_settings.progress = { 'type': 'throbber' };
46
47      // For anchor tags, these will go to the target of the anchor rather
48      // than the usual location.
49      if ($(this).attr('href')) {
50        element_settings.url = $(this).attr('href');
51        element_settings.event = 'click';
52      }
53      // Special handling if the data-dialog attribute is TRUE.
54      if ($(this).data('dialog')) {
55        element_settings.dialog = $(this).data('dialog-options') || {};
56
57        var uri = element_settings.url;
58        if (uri.indexOf('?') === -1) {
59          uri += '?';
60        }
61        else {
62          uri += '&';
63        }
64        uri += '_format=drupal_dialog';
65
66        element_settings.url = uri;
67      }
68      var base = $(this).attr('id');
69      Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings);
70    });
71
72    // This class means to submit the form to the action using Ajax.
73    $('.use-ajax-submit:not(.ajax-processed)').addClass('ajax-processed').each(function () {
74      var element_settings = {};
75
76      // Ajax submits specified in this manner automatically submit to the
77      // normal form action.
78      element_settings.url = $(this.form).attr('action');
79      // Form submit button clicks need to tell the form what was clicked so
80      // it gets passed in the POST request.
81      element_settings.setClick = true;
82      // Form buttons use the 'click' event rather than mousedown.
83      element_settings.event = 'click';
84      // Clicked form buttons look better with the throbber than the progress bar.
85      element_settings.progress = { 'type': 'throbber' };
86
87      var base = $(this).attr('id');
88      Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings);
89    });
90  }
91};
92
93/**
94 * Ajax object.
95 *
96 * All Ajax objects on a page are accessible through the global Drupal.ajax
97 * object and are keyed by the submit button's ID. You can access them from
98 * your module's JavaScript file to override properties or functions.
99 *
100 * For example, if your Ajax enabled button has the ID 'edit-submit', you can
101 * redefine the function that is called to insert the new content like this
102 * (inside a Drupal.behaviors attach block):
103 * @code
104 *    Drupal.behaviors.myCustomAJAXStuff = {
105 *      attach: function (context, settings) {
106 *        Drupal.ajax['edit-submit'].commands.insert = function (ajax, response, status) {
107 *          new_content = $(response.data);
108 *          $('#my-wrapper').append(new_content);
109 *          alert('New content was appended to #my-wrapper');
110 *        }
111 *      }
112 *    };
113 * @endcode
114 */
115Drupal.ajax = function (base, element, element_settings) {
116  var defaults = {
117    url: 'system/ajax',
118    event: 'mousedown',
119    keypress: true,
120    selector: '#' + base,
121    effect: 'none',
122    speed: 'none',
123    method: 'replaceWith',
124    progress: {
125      type: 'throbber',
126      message: Drupal.t('Please wait...')
127    },
128    submit: {
129      'js': true
130    }
131  };
132
133  $.extend(this, defaults, element_settings);
134
135  this.element = element;
136  this.element_settings = element_settings;
137
138  // Replacing 'nojs' with 'ajax' in the URL allows for an easy method to let
139  // the server detect when it needs to degrade gracefully.
140  // There are five scenarios to check for:
141  // 1. /nojs/
142  // 2. /nojs$ - The end of a URL string.
143  // 3. /nojs? - Followed by a query (with clean URLs enabled).
144  //      E.g.: path/nojs?destination=foobar
145  // 4. /nojs& - Followed by a query (without clean URLs enabled).
146  //      E.g.: ?q=path/nojs&destination=foobar
147  // 5. /nojs# - Followed by a fragment.
148  //      E.g.: path/nojs#myfragment
149  this.url = element_settings.url.replace(/\/nojs(\/|$|\?|&|#)/g, '/ajax$1');
150  // If the 'nojs' version of the URL is trusted, also trust the 'ajax' version.
151  if (Drupal.settings.urlIsAjaxTrusted[element_settings.url]) {
152    Drupal.settings.urlIsAjaxTrusted[this.url] = true;
153  }
154
155  this.wrapper = '#' + element_settings.wrapper;
156
157  // If there isn't a form, jQuery.ajax() will be used instead, allowing us to
158  // bind Ajax to links as well.
159  if (this.element.form) {
160    this.form = $(this.element.form);
161  }
162
163  // Set the options for the ajaxSubmit function.
164  // The 'this' variable will not persist inside of the options object.
165  var ajax = this;
166  ajax.options = {
167    url: Drupal.sanitizeAjaxUrl(ajax.url),
168    data: ajax.submit,
169    beforeSerialize: function (element_settings, options) {
170      return ajax.beforeSerialize(element_settings, options);
171    },
172    beforeSubmit: function (form_values, element_settings, options) {
173      ajax.ajaxing = true;
174      return ajax.beforeSubmit(form_values, element_settings, options);
175    },
176    beforeSend: function (xmlhttprequest, options) {
177      ajax.ajaxing = true;
178      return ajax.beforeSend(xmlhttprequest, options);
179    },
180    success: function (response, status, xmlhttprequest) {
181      // Sanity check for browser support (object expected).
182      // When using iFrame uploads, responses must be returned as a string.
183      if (typeof response == 'string') {
184        response = $.parseJSON(response);
185      }
186
187      // Prior to invoking the response's commands, verify that they can be
188      // trusted by checking for a response header. See
189      // ajax_set_verification_header() for details.
190      // - Empty responses are harmless so can bypass verification. This avoids
191      //   an alert message for server-generated no-op responses that skip Ajax
192      //   rendering.
193      // - Ajax objects with trusted URLs (e.g., ones defined server-side via
194      //   #ajax) can bypass header verification. This is especially useful for
195      //   Ajax with multipart forms. Because IFRAME transport is used, the
196      //   response headers cannot be accessed for verification.
197      if (response !== null && !Drupal.settings.urlIsAjaxTrusted[ajax.url]) {
198        if (xmlhttprequest.getResponseHeader('X-Drupal-Ajax-Token') !== '1') {
199          var customMessage = Drupal.t("The response failed verification so will not be processed.");
200          return ajax.error(xmlhttprequest, ajax.url, customMessage);
201        }
202      }
203
204      return ajax.success(response, status);
205    },
206    complete: function (xmlhttprequest, status) {
207      ajax.ajaxing = false;
208      if (status == 'error' || status == 'parsererror') {
209        return ajax.error(xmlhttprequest, ajax.url);
210      }
211    },
212    dataType: 'json',
213    jsonp: false,
214    type: 'POST'
215  };
216  if (element_settings.dialog) {
217    ajax.options.data.dialogOptions = element_settings.dialog;
218  }
219
220  // For multipart forms (e.g., file uploads), jQuery Form targets the form
221  // submission to an iframe instead of using an XHR object. The initial "src"
222  // of the iframe, prior to the form submission, is set to options.iframeSrc.
223  // "about:blank" is the semantically correct, standards-compliant, way to
224  // initialize a blank iframe; however, some old IE versions (possibly only 6)
225  // incorrectly report a mixed content warning when iframes with an
226  // "about:blank" src are added to a parent document with an https:// origin.
227  // jQuery Form works around this by defaulting to "javascript:false" instead,
228  // but that breaks on Chrome 83, so here we force the semantically correct
229  // behavior for all browsers except old IE.
230  // @see https://www.drupal.org/project/drupal/issues/3143016
231  // @see https://github.com/jquery-form/form/blob/df9cb101b9c9c085c8d75ad980c7ff1cf62063a1/jquery.form.js#L68
232  // @see https://bugs.chromium.org/p/chromium/issues/detail?id=1084874
233  // @see https://html.spec.whatwg.org/multipage/browsers.html#creating-browsing-contexts
234  // @see https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy
235  if (navigator.userAgent.indexOf("MSIE") === -1) {
236    ajax.options.iframeSrc = 'about:blank';
237  }
238
239  // Bind the ajaxSubmit function to the element event.
240  $(ajax.element).bind(element_settings.event, function (event) {
241    if (!Drupal.settings.urlIsAjaxTrusted[ajax.url] && !Drupal.urlIsLocal(ajax.url)) {
242      throw new Error(Drupal.t('The callback URL is not local and not trusted: !url', {'!url': ajax.url}));
243    }
244    return ajax.eventResponse(this, event);
245  });
246
247  // If necessary, enable keyboard submission so that Ajax behaviors
248  // can be triggered through keyboard input as well as e.g. a mousedown
249  // action.
250  if (element_settings.keypress) {
251    $(ajax.element).keypress(function (event) {
252      return ajax.keypressResponse(this, event);
253    });
254  }
255
256  // If necessary, prevent the browser default action of an additional event.
257  // For example, prevent the browser default action of a click, even if the
258  // AJAX behavior binds to mousedown.
259  if (element_settings.prevent) {
260    $(ajax.element).bind(element_settings.prevent, false);
261  }
262};
263
264/**
265 * Handle a key press.
266 *
267 * The Ajax object will, if instructed, bind to a key press response. This
268 * will test to see if the key press is valid to trigger this event and
269 * if it is, trigger it for us and prevent other keypresses from triggering.
270 * In this case we're handling RETURN and SPACEBAR keypresses (event codes 13
271 * and 32. RETURN is often used to submit a form when in a textfield, and
272 * SPACE is often used to activate an element without submitting.
273 */
274Drupal.ajax.prototype.keypressResponse = function (element, event) {
275  // Create a synonym for this to reduce code confusion.
276  var ajax = this;
277
278  // Detect enter key and space bar and allow the standard response for them,
279  // except for form elements of type 'text' and 'textarea', where the
280  // spacebar activation causes inappropriate activation if #ajax['keypress'] is
281  // TRUE. On a text-type widget a space should always be a space.
282  if (event.which == 13 || (event.which == 32 && element.type != 'text' && element.type != 'textarea')) {
283    $(ajax.element_settings.element).trigger(ajax.element_settings.event);
284    return false;
285  }
286};
287
288/**
289 * Handle an event that triggers an Ajax response.
290 *
291 * When an event that triggers an Ajax response happens, this method will
292 * perform the actual Ajax call. It is bound to the event using
293 * bind() in the constructor, and it uses the options specified on the
294 * ajax object.
295 */
296Drupal.ajax.prototype.eventResponse = function (element, event) {
297  // Create a synonym for this to reduce code confusion.
298  var ajax = this;
299
300  // Do not perform another ajax command if one is already in progress.
301  if (ajax.ajaxing) {
302    return false;
303  }
304
305  try {
306    if (ajax.form) {
307      // If setClick is set, we must set this to ensure that the button's
308      // value is passed.
309      if (ajax.setClick) {
310        // Mark the clicked button. 'form.clk' is a special variable for
311        // ajaxSubmit that tells the system which element got clicked to
312        // trigger the submit. Without it there would be no 'op' or
313        // equivalent.
314        element.form.clk = element;
315      }
316
317      ajax.form.ajaxSubmit(ajax.options);
318    }
319    else {
320      ajax.beforeSerialize(ajax.element, ajax.options);
321      $.ajax(ajax.options);
322    }
323  }
324  catch (e) {
325    // Unset the ajax.ajaxing flag here because it won't be unset during
326    // the complete response.
327    ajax.ajaxing = false;
328    alert("An error occurred while attempting to process " + ajax.options.url + ": " + e.message);
329  }
330
331  // For radio/checkbox, allow the default event. On IE, this means letting
332  // it actually check the box.
333  if (typeof element.type != 'undefined' && (element.type == 'checkbox' || element.type == 'radio')) {
334    return true;
335  }
336  else {
337    return false;
338  }
339
340};
341
342/**
343 * Handler for the form serialization.
344 *
345 * Runs before the beforeSend() handler (see below), and unlike that one, runs
346 * before field data is collected.
347 */
348Drupal.ajax.prototype.beforeSerialize = function (element, options) {
349  // Allow detaching behaviors to update field values before collecting them.
350  // This is only needed when field values are added to the POST data, so only
351  // when there is a form such that this.form.ajaxSubmit() is used instead of
352  // $.ajax(). When there is no form and $.ajax() is used, beforeSerialize()
353  // isn't called, but don't rely on that: explicitly check this.form.
354  if (this.form) {
355    var settings = this.settings || Drupal.settings;
356    Drupal.detachBehaviors(this.form, settings, 'serialize');
357  }
358
359  // Prevent duplicate HTML ids in the returned markup.
360  // @see drupal_html_id()
361  options.data['ajax_html_ids[]'] = [];
362  $('[id]').each(function () {
363    options.data['ajax_html_ids[]'].push(this.id);
364  });
365
366  // Allow Drupal to return new JavaScript and CSS files to load without
367  // returning the ones already loaded.
368  // @see ajax_base_page_theme()
369  // @see drupal_get_css()
370  // @see drupal_get_js()
371  options.data['ajax_page_state[theme]'] = Drupal.settings.ajaxPageState.theme;
372  options.data['ajax_page_state[theme_token]'] = Drupal.settings.ajaxPageState.theme_token;
373  for (var key in Drupal.settings.ajaxPageState.css) {
374    options.data['ajax_page_state[css][' + key + ']'] = 1;
375  }
376  for (var key in Drupal.settings.ajaxPageState.js) {
377    options.data['ajax_page_state[js][' + key + ']'] = 1;
378  }
379
380  // Provide an error if the dialog options can't be parsed.
381  if (this.options.data.dialogOptions && typeof this.options.data.dialogOptions !== 'object') {
382    $.error(Drupal.t('The data-dialog-options property on this link is not valid JSON.'));
383  }
384};
385
386/**
387 * Modify form values prior to form submission.
388 */
389Drupal.ajax.prototype.beforeSubmit = function (form_values, element, options) {
390  // This function is left empty to make it simple to override for modules
391  // that wish to add functionality here.
392};
393
394/**
395 * Prepare the Ajax request before it is sent.
396 */
397Drupal.ajax.prototype.beforeSend = function (xmlhttprequest, options) {
398  // For forms without file inputs, the jQuery Form plugin serializes the form
399  // values, and then calls jQuery's $.ajax() function, which invokes this
400  // handler. In this circumstance, options.extraData is never used. For forms
401  // with file inputs, the jQuery Form plugin uses the browser's normal form
402  // submission mechanism, but captures the response in a hidden IFRAME. In this
403  // circumstance, it calls this handler first, and then appends hidden fields
404  // to the form to submit the values in options.extraData. There is no simple
405  // way to know which submission mechanism will be used, so we add to extraData
406  // regardless, and allow it to be ignored in the former case.
407  if (this.form) {
408    options.extraData = options.extraData || {};
409
410    // Let the server know when the IFRAME submission mechanism is used. The
411    // server can use this information to wrap the JSON response in a TEXTAREA,
412    // as per http://jquery.malsup.com/form/#file-upload.
413    options.extraData.ajax_iframe_upload = '1';
414
415    // The triggering element is about to be disabled (see below), but if it
416    // contains a value (e.g., a checkbox, textfield, select, etc.), ensure that
417    // value is included in the submission. As per above, submissions that use
418    // $.ajax() are already serialized prior to the element being disabled, so
419    // this is only needed for IFRAME submissions.
420    var v = $.fieldValue(this.element);
421    if (v !== null) {
422      options.extraData[this.element.name] = Drupal.checkPlain(v);
423    }
424  }
425
426  // Disable the element that received the change to prevent user interface
427  // interaction while the Ajax request is in progress. ajax.ajaxing prevents
428  // the element from triggering a new request, but does not prevent the user
429  // from changing its value.
430  $(this.element).addClass('progress-disabled').attr('disabled', true);
431
432  // Insert progressbar or throbber.
433  if (this.progress.type == 'bar') {
434    var progressBar = new Drupal.progressBar('ajax-progress-' + this.element.i
434d, $.noop, this.progress.method, $.noop);
435    if (this.progress.message) {
436      progressBar.setProgress(-1, this.progress.message);
437    }
438    if (this.progress.url) {
439      progressBar.startMonitoring(this.progress.url, this.progress.interval || 1500);
440    }
441    this.progress.element = $(progressBar.element).addClass('ajax-progress ajax-progress-bar');
442    this.progress.object = progressBar;
443    $(this.element).after(this.progress.element);
444  }
445  else if (this.progress.type == 'throbber') {
446    this.progress.element = $('<div class="ajax-progress ajax-progress-throbber"><div class="throbber">&nbsp;</div></div>');
447    if (this.progress.message) {
448      $('.throbber', this.progress.element).after('<div class="message">' + this.progress.message + '</div>');
449    }
450    $(this.element).after(this.progress.element);
451  }
452};
453
454/**
455 * Handler for the form redirection completion.
456 */
457Drupal.ajax.prototype.success = function (response, status) {
458  // Remove the progress element.
459  if (this.progress.element) {
460    $(this.progress.element).remove();
461  }
462  if (this.progress.object) {
463    this.progress.object.stopMonitoring();
464  }
465  $(this.element).removeClass('progress-disabled').removeAttr('disabled');
466
467  Drupal.freezeHeight();
468
469  for (var i in response) {
470    if (response.hasOwnProperty(i) && response[i]['command'] && this.commands[response[i]['command']]) {
471      this.commands[response[i]['command']](this, response[i], status);
472    }
473  }
474
475  // Reattach behaviors, if they were detached in beforeSerialize(). The
476  // attachBehaviors() called on the new content from processing the response
477  // commands is not sufficient, because behaviors from the entire form need
478  // to be reattached.
479  if (this.form) {
480    var settings = this.settings || Drupal.settings;
481    Drupal.attachBehaviors(this.form, settings);
482  }
483
484  Drupal.unfreezeHeight();
485
486  // Remove any response-specific settings so they don't get used on the next
487  // call by mistake.
488  this.settings = null;
489};
490
491/**
492 * Build an effect object which tells us how to apply the effect when adding new HTML.
493 */
494Drupal.ajax.prototype.getEffect = function (response) {
495  var type = response.effect || this.effect;
496  var speed = response.speed || this.speed;
497
498  var effect = {};
499  if (type == 'none') {
500    effect.showEffect = 'show';
501    effect.hideEffect = 'hide';
502    effect.showSpeed = '';
503  }
504  else if (type == 'fade') {
505    effect.showEffect = 'fadeIn';
506    effect.hideEffect = 'fadeOut';
507    effect.showSpeed = speed;
508  }
509  else {
510    effect.showEffect = type + 'Toggle';
511    effect.hideEffect = type + 'Toggle';
512    effect.showSpeed = speed;
513  }
514
515  return effect;
516};
517
518/**
519 * Handler for the form redirection error.
520 */
521Drupal.ajax.prototype.error = function (xmlhttprequest, uri, customMessage) {
522  Drupal.displayAjaxError(Drupal.ajaxError(xmlhttprequest, uri, customMessage));
523  // Remove the progress element.
524  if (this.progress.element) {
525    $(this.progress.element).remove();
526  }
527  if (this.progress.object) {
528    this.progress.object.stopMonitoring();
529  }
530  // Undo hide.
531  $(this.wrapper).show();
532  // Re-enable the element.
533  $(this.element).removeClass('progress-disabled').removeAttr('disabled');
534  // Reattach behaviors, if they were detached in beforeSerialize().
535  if (this.form) {
536    var settings = this.settings || Drupal.settings;
537    Drupal.attachBehaviors(this.form, settings);
538  }
539};
540
541/**
542 * Provide a series of commands that the server can request the client perform.
543 */
544Drupal.ajax.prototype.commands = {
545  /**
546   * Command to insert new content into the DOM.
547   */
548  insert: function (ajax, response, status) {
549    // Get information from the response. If it is not there, default to
550    // our presets.
551    var wrapper = response.selector ? $(response.selector) : $(ajax.wrapper);
552    var method = response.method || ajax.method;
553    var effect = ajax.getEffect(response);
554
555    // We don't know what response.data contains: it might be a string of text
556    // without HTML, so don't rely on jQuery correctly iterpreting
557    // $(response.data) as new HTML rather than a CSS selector. Also, if
558    // response.data contains top-level text nodes, they get lost with either
559    // $(response.data) or $('<div></div>').replaceWith(response.data).
560    var new_content_wrapped = $('<div></div>').html(response.data);
561    var new_content = new_content_wrapped.contents();
562
563    // For legacy reasons, the effects processing code assumes that new_content
564    // consists of a single top-level element. Also, it has not been
565    // sufficiently tested whether attachBehaviors() can be successfully called
566    // with a context object that includes top-level text nodes. However, to
567    // give developers full control of the HTML appearing in the page, and to
568    // enable Ajax content to be inserted in places where DIV elements are not
569    // allowed (e.g., within TABLE, TR, and SPAN parents), we check if the new
570    // content satisfies the requirement of a single top-level element, and
571    // only use the container DIV created above when it doesn't. For more
572    // information, please see http://drupal.org/node/736066.
573    if (new_content.length != 1 || new_content.get(0).nodeType != 1) {
574      new_content = new_content_wrapped;
575    }
576
577    // If removing content from the wrapper, detach behaviors first.
578    switch (method) {
579      case 'html':
580      case 'replaceWith':
581      case 'replaceAll':
582      case 'empty':
583      case 'remove':
584        var settings = response.settings || ajax.settings || Drupal.settings;
585        Drupal.detachBehaviors(wrapper, settings);
586    }
587
588    // Add the new content to the page.
589    wrapper[method](new_content);
590
591    // Immediately hide the new content if we're using any effects.
592    if (effect.showEffect != 'show') {
593      new_content.hide();
594    }
595
596    // Determine which effect to use and what content will receive the
597    // effect, then show the new content.
598    if ($('.ajax-new-content', new_content).length > 0) {
599      $('.ajax-new-content', new_content).hide();
600      new_content.show();
601      $('.ajax-new-content', new_content)[effect.showEffect](effect.showSpeed);
602    }
603    else if (effect.showEffect != 'show') {
604      new_content[effect.showEffect](effect.showSpeed);
605    }
606
607    // Attach all JavaScript behaviors to the new content, if it was successfully
608    // added to the page, this if statement allows #ajax['wrapper'] to be
609    // optional.
610    if (new_content.parents('html').length > 0) {
611      // Apply any settings from the returned JSON if available.
612      var settings = response.settings || ajax.settings || Drupal.settings;
613      Drupal.attachBehaviors(new_content, settings);
614    }
615  },
616
617  /**
618   * Command to remove a chunk from the page.
619   */
620  remove: function (ajax, response, status) {
621    var settings = response.settings || ajax.settings || Drupal.settings;
622    Drupal.detachBehaviors($(response.selector), settings);
623    $(response.selector).remove();
624  },
625
626  /**
627   * Command to mark a chunk changed.
628   */
629  changed: function (ajax, response, status) {
630    if (!$(response.selector).hasClass('ajax-changed')) {
631      $(response.selector).addClass('ajax-changed');
632      if (response.asterisk) {
633        $(response.selector).find(response.asterisk).append(' <span class="ajax-changed">*</span> ');
634      }
635    }
636  },
637
638  /**
639   * Command to provide an alert.
640   */
641  alert: function (ajax, response, status) {
642    alert(response.text, response.title);
643  },
644
645  /**
646   * Command to provide the jQuery css() function.
647   */
648  css: function (ajax, response, status) {
649    $(response.selector).css(response.argument);
650  },
651
652  /**
653   * Command to set the settings that will be used for other commands in this response.
654   */
655  settings: function (ajax, response, status) {
656    if (response.merge) {
657      $.extend(true, Drupal.settings, response.settings);
658    }
659    else {
660      ajax.settings = response.settings;
661    }
662  },
663
664  /**
665   * Command to attach data using jQuery's data API.
666   */
667  data: function (ajax, response, status) {
668    $(response.selector).data(response.name, response.value);
669  },
670
671  /**
672   * Command to apply a jQuery method.
673   */
674  invoke: function (ajax, response, status) {
675    var $element = $(response.selector);
676    $element[response.method].apply($element, response.arguments);
677  },
678
679  /**
680   * Command to restripe a table.
681   */
682  restripe: function (ajax, response, status) {
683    // :even and :odd are reversed because jQuery counts from 0 and
684    // we count from 1, so we're out of sync.
685    // Match immediate children of the parent element to allow nesting.
686    $('> tbody > tr:visible, > tr:visible', $(response.selector))
687      .removeClass('odd even')
688      .filter(':even').addClass('odd').end()
689      .filter(':odd').addClass('even');
690  },
691
692  /**
693   * Command to add css.
694   *
695   * Uses the proprietary addImport method if available as browsers which
696   * support that method ignore @import statements in dynamically added
697   * stylesheets.
698   */
699  add_css: function (ajax, response, status) {
700    // Add the styles in the normal way.
701    $('head').prepend(response.data);
702    // Add imports in the styles using the addImport method if available.
703    var match, importMatch = /^@import url\("(.*)"\);$/igm;
704    if (document.styleSheets[0].addImport && importMatch.test(response.data)) {
705      importMatch.lastIndex = 0;
706      while (match = importMatch.exec(response.data)) {
707        document.styleSheets[0].addImport(match[1]);
708      }
709    }
710  },
711
712  /**
713   * Command to update a form's build ID.
714   */
715  updateBuildId: function(ajax, response, status) {
716    $('input[name="form_build_id"][value="' + response['old'] + '"]').val(response['new']);
717  }
718};
719
720})(jQuery);

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.