PageSourceSearch

https://nationaltrailraceway.com/core/misc/ajax.js?v=8.9.11

js nationaltrailraceway.com collected 2026-10-02 05:51:26 UTC 20,874 bytes, 644 lines download raw bytes

1/**
2* DO NOT EDIT THIS FILE.
3* See the following change record for more information,
4* https://www.drupal.org/node/2815083
5* @preserve
6**/
7function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
8
9(function ($, window, Drupal, drupalSettings) {
10  Drupal.behaviors.AJAX = {
11    attach: function attach(context, settings) {
12      function loadAjaxBehavior(base) {
13        var elementSettings = settings.ajax[base];
14        if (typeof elementSettings.selector === 'undefined') {
15          elementSettings.selector = '#' + base;
16        }
17        $(elementSettings.selector).once('drupal-ajax').each(function () {
18          elementSettings.element = this;
19          elementSettings.base = base;
20          Drupal.ajax(elementSettings);
21        });
22      }
23
24      Object.keys(settings.ajax || {}).forEach(function (base) {
25        return loadAjaxBehavior(base);
26      });
27
28      Drupal.ajax.bindAjaxLinks(document.body);
29
30      $('.use-ajax-submit').once('ajax').each(function () {
31        var elementSettings = {};
32
33        elementSettings.url = $(this.form).attr('action');
34
35        elementSettings.setClick = true;
36
37        elementSettings.event = 'click';
38
39        elementSettings.progress = { type: 'throbber' };
40        elementSettings.base = $(this).attr('id');
41        elementSettings.element = this;
42
43        Drupal.ajax(elementSettings);
44      });
45    },
46    detach: function detach(context, settings, trigger) {
47      if (trigger === 'unload') {
48        Drupal.ajax.expired().forEach(function (instance) {
49          Drupal.ajax.instances[instance.instanceIndex] = null;
50        });
51      }
52    }
53  };
54
55  Drupal.AjaxError = function (xmlhttp, uri, customMessage) {
56    var statusCode = void 0;
57    var statusText = void 0;
58    var responseText = void 0;
59    if (xmlhttp.status) {
60      statusCode = '\n' + Drupal.t('An AJAX HTTP error occurred.') + '\n' + Drupal.t('HTTP Result Code: !status', {
61        '!status': xmlhttp.status
62      });
63    } else {
64      statusCode = '\n' + Drupal.t('An AJAX HTTP request terminated abnormally.');
65    }
66    statusCode += '\n' + Drupal.t('Debugging information follows.');
67    var pathText = '\n' + Drupal.t('Path: !uri', { '!uri': uri });
68    statusText = '';
69
70    try {
71      statusText = '\n' + Drupal.t('StatusText: !statusText', {
72        '!statusText': $.trim(xmlhttp.statusText)
73      });
74    } catch (e) {}
75
76    responseText = '';
77
78    try {
79      responseText = '\n' + Drupal.t('ResponseText: !responseText', {
80        '!responseText': $.trim(xmlhttp.responseText)
81      });
82    } catch (e) {}
83
84    responseText = responseText.replace(/<("[^"]*"|'[^']*'|[^'">])*>/gi, '');
85    responseText = responseText.replace(/[\n]+\s+/g, '\n');
86
87    var readyStateText = xmlhttp.status === 0 ? '\n' + Drupal.t('ReadyState: !readyState', {
88      '!readyState': xmlhttp.readyState
89    }) : '';
90
91    customMessage = customMessage ? '\n' + Drupal.t('CustomMessage: !customMessage', {
92      '!customMessage': customMessage
93    }) : '';
94
95    this.message = statusCode + pathText + statusText + customMessage + responseText + readyStateText;
96
97    this.name = 'AjaxError';
98  };
99
100  Drupal.AjaxError.prototype = new Error();
101  Drupal.AjaxError.prototype.constructor = Drupal.AjaxError;
102
103  Drupal.ajax = function (settings) {
104    if (arguments.length !== 1) {
105      throw new Error('Drupal.ajax() function must be called with one configuration object only');
106    }
107
108    var base = settings.base || false;
109    var element = settings.element || false;
110    delete settings.base;
111    delete settings.element;
112
113    if (!settings.progress && !element) {
114      settings.progress = false;
115    }
116
117    var ajax = new Drupal.Ajax(base, element, settings);
118    ajax.instanceIndex = Drupal.ajax.instances.length;
119    Drupal.ajax.instances.push(ajax);
120
121    return ajax;
122  };
123
124  Drupal.ajax.instances = [];
125
126  Drupal.ajax.expired = function () {
127    return Drupal.ajax.instances.filter(function (instance) {
128      return instance && instance.element !== false && !document.body.contains(instance.element);
129    });
130  };
131
132  Drupal.ajax.bindAjaxLinks = function (element) {
133    $(element).find('.use-ajax').once('ajax').each(function (i, ajaxLink) {
134      var $linkElement = $(ajaxLink);
135
136      var elementSettings = {
137        progress: { type: 'throbber' },
138        dialogType: $linkElement.data('dialog-type'),
139        dialog: $linkElement.data('dialog-options'),
140        dialogRenderer: $linkElement.data('dialog-renderer'),
141        base: $linkElement.attr('id'),
142        element: ajaxLink
143      };
144      var href = $linkElement.attr('href');
145
146      if (href) {
147        elementSettings.url = href;
148        elementSettings.event = 'click';
149      }
150      Drupal.ajax(elementSettings);
151    });
152  };
153
154  Drupal.Ajax = function (base, element, elementSettings) {
155    var defaults = {
156      event: element ? 'mousedown' : null,
157      keypress: true,
158      selector: base ? '#' + base : null,
159      effect: 'none',
160      speed: 'none',
161      method: 'replaceWith',
162      progress: {
163        type: 'throbber',
164        message: Drupal.t('Please wait...')
165      },
166      submit: {
167        js: true
168      }
169    };
170
171    $.extend(this, defaults, elementSettings);
172
173    this.commands = new Drupal.AjaxCommands();
174
175    this.instanceIndex = false;
176
177    if (this.wrapper) {
178      this.wrapper = '#' + this.wrapper;
179    }
180
181    this.element = element;
182
183    this.element_settings = elementSettings;
184
185    this.elementSettings = elementSettings;
186
187    if (this.element && this.element.form) {
188      this.$form = $(this.element.form);
189    }
190
191    if (!this.url) {
192      var $element = $(this.element);
193      if ($element.is('a')) {
194        this.url = $element.attr('href');
195      } else if (this.element && element.form) {
196        this.url = this.$form.attr('action');
197      }
198    }
199
200    var originalUrl = this.url;
201
202    this.url = this.url.replace(/\/nojs(\/|$|\?|#)/, '/ajax$1');
203
204    if (drupalSettings.ajaxTrustedUrl[originalUrl]) {
205      drupalSettings.ajaxTrustedUrl[this.url] = true;
206    }
207
208    var ajax = this;
209
210    ajax.options = {
211      url: ajax.url,
212      data: ajax.submit,
213      beforeSerialize: function beforeSerialize(elementSettings, options) {
214        return ajax.beforeSerialize(elementSettings, options);
215      },
216      beforeSubmit: function beforeSubmit(formValues, elementSettings, options) {
217        ajax.ajaxing = true;
218        return ajax.beforeSubmit(formValues, elementSettings, options);
219      },
220      beforeSend: function beforeSend(xmlhttprequest, options) {
221        ajax.ajaxing = true;
222        return ajax.beforeSend(xmlhttprequest, options);
223      },
224      success: function success(response, status, xmlhttprequest) {
225        if (typeof response === 'string') {
226          response = $.parseJSON(response);
227        }
228
229        if (response !== null && !drupalSettings.ajaxTrustedUrl[ajax.url]) {
230          if (xmlhttprequest.getResponseHeader('X-Drupal-Ajax-Token') !== '1') {
231            var customMessage = Drupal.t('The response failed verification so will not be processed.');
232            return ajax.error(xmlhttprequest, ajax.url, customMessage);
233          }
234        }
235
236        return ajax.success(response, status);
237      },
238      complete: function complete(xmlhttprequest, status) {
239        ajax.ajaxing = false;
240        if (status === 'error' || status === 'parsererror') {
241          return ajax.error(xmlhttprequest, ajax.url);
242        }
243      },
244
245      dataType: 'json',
246      jsonp: false,
247      type: 'POST'
248    };
249
250    if (elementSettings.dialog) {
251      ajax.options.data.dialogOptions = elementSettings.dialog;
252    }
253
254    if (ajax.options.url.indexOf('?') === -1) {
255      ajax.options.url += '?';
256    } else {
257      ajax.options.url += '&';
258    }
259
260    var wrapper = 'drupal_' + (elementSettings.dialogType || 'ajax');
261    if (elementSettings.dialogRenderer) {
262      wrapper += '.' + elementSettings.dialogRenderer;
263    }
264    ajax.options.url += Drupal.ajax.WRAPPER_FORMAT + '=' + wrapper;
265
266    $(ajax.element).on(elementSettings.event, function (event) {
267      if (!drupalSettings.ajaxTrustedUrl[ajax.url] && !Drupal.url.isLocal(ajax.url)) {
268        throw new Error(Drupal.t('The callback URL is not local and not trusted: !url', {
269          '!url': ajax.url
270        }));
271      }
272      return ajax.eventResponse(this, event);
273    });
274
275    if (elementSettings.keypress) {
276      $(ajax.element).on('keypress', function (event) {
277        return ajax.keypressResponse(this, event);
278      });
279    }
280
281    if (elementSettings.prevent) {
282      $(ajax.element).on(elementSettings.prevent, false);
283    }
284  };
285
286  Drupal.ajax.WRAPPER_FORMAT = '_wrapper_format';
287
288  Drupal.Ajax.AJAX_REQUEST_PARAMETER = '_drupal_ajax';
289
290  Drupal.Ajax.prototype.execute = function () {
291    if (this.ajaxing) {
292      return;
293    }
294
295    try {
296      this.beforeSerialize(this.element, this.options);
297
298      return $.ajax(this.options);
299    } catch (e) {
300      this.ajaxing = false;
301      window.alert('An error occurred while attempting to process ' + this.options.url + ': ' + e.message);
302
303      return $.Deferred().reject();
304    }
305  };
306
307  Drupal.Ajax.prototype.keypressResponse = function (element, event) {
308    var ajax = this;
309
310    if (event.which === 13 || event.which === 32 && element.type !== 'text' && element.type !== 'textarea' && element.type !== 'tel' && element.type !== 'number') {
311      event.preventDefault();
312      event.stopPropagation();
313      $(element).trigger(ajax.elementSettings.event);
314    }
315  };
316
317  Drupal.Ajax.prototype.eventResponse = function (element, event) {
318    event.preventDefault();
319    event.stopPropagation();
320
321    var ajax = this;
322
323    if (ajax.ajaxing) {
324      return;
325    }
326
327    try {
328      if (ajax.$form) {
329        if (ajax.setClick) {
330          element.form.clk = element;
331        }
332
333        ajax.$form.ajaxSubmit(ajax.options);
334      } else {
335        ajax.beforeSerialize(ajax.element, ajax.options);
336        $.ajax(ajax.options);
337      }
338    } catch (e) {
339      ajax.ajaxing = false;
340      window.alert('An error occurred while attempting to process ' + ajax.options.url + ': ' + e.message);
341    }
342  };
343
344  Drupal.Ajax.prototype.beforeSerialize = function (element, options) {
345    if (this.$form && document.body.contains(this.$form.get(0))) {
346      var settings = this.settings || drupalSettings;
347      Drupal.detachBehaviors(this.$form.get(0), settings, 'serialize');
348    }
349
350    options.data[Drupal.Ajax.AJAX_REQUEST_PARAMETER] = 1;
351
352    var pageState = drupalSettings.ajaxPageState;
353    options.data['ajax_page_state[theme]'] = pageState.theme;
354    options.data['ajax_page_state[theme_token]'] = pageState.theme_token;
355    options.data['ajax_page_state[libraries]'] = pageState.libraries;
356  };
357
358  Drupal.Ajax.prototype.beforeSubmit = function (formValues, element, options) {};
359
360  Drupal.Ajax.prototype.beforeSend = function (xmlhttprequest, options) {
361    if (this.$form) {
362      options.extraData = options.extraData || {};
363
364      options.extraData.ajax_iframe_upload = '1';
365
366      var v = $.fieldValue(this.element);
367      if (v !== null) {
368        options.extraData[this.element.name] = v;
369      }
370    }
371
372    $(this.element).prop('disabled', true);
373
374    if (!this.progress || !this.progress.type) {
375      return;
376    }
377
378    var progressIndicatorMethod = 'setProgressIndicator' + this.progress.type.slice(0, 1).toUpperCase() + this.progress.type.slice(1).toLowerCase();
379    if (progressIndicatorMethod in this && typeof this[progressIndicatorMethod] === 'function') {
380      this[progressIndicatorMethod].call(this);
381    }
382  };
383
384  Drupal.theme.ajaxProgressThrobber = function (message) {
385    var messageMarkup = typeof message === 'string' ? Drupal.theme('ajaxProgressMessage', message) : '';
386    var throbber = '<div class="throbber">&nbsp;</div>';
387
388    return '<div class="ajax-progress ajax-progress-throbber">' + throbber + messageMarkup + '</div>';
389  };
390
391  Drupal.theme.ajaxProgressIndicatorFullscreen = function () {
392    return '<div class="ajax-progress ajax-progress-fullscreen">&nbsp;</div>';
393  };
394
395  Drupal.theme.ajaxProgressMessage = function (message) {
396    return '<div class="message">' + message + '</div>';
397  };
398
399  Drupal.theme.ajaxProgressBar = function ($element) {
400    return $('<div class="ajax-progress ajax-progress-bar"></div>').append($element);
401  };
402
403  Drupal.Ajax.prototype.setProgressIndicatorBar = function () {
404    var progressBar = new Drupal.ProgressBar('ajax-progress-' + this.element.id, $.noop, this.progress.method, $.noop);
405    if (this.progress.message) {
406      progressBar.setProgress(-1, this.progress.message);
407    }
408    if (this.progress.url) {
409      progressBar.startMonitoring(this.progress.url, this.progress.interval || 1500);
410    }
411    this.progress.element = $(Drupal.theme('ajaxProgressBar', progressBar.element));
412    this.progress.object = progressBar;
413    $(this.element).after(this.progress.element);
414  };
415
416  Drupal.Ajax.prototype.setProgressIndicatorThrobber = function () {
417    this.progress.element = $(Drupal.theme('ajaxProgressThrobber', this.progress.message));
418    $(this.element).after(this.progress.element);
419  };
420
421  Drupal.Ajax.prototype.setProgressIndicatorFullscreen = function () {
422    this.progress.element = $(Drupal.theme('ajaxProgressIndicatorFullscreen'));
423    $('body').append(this.progress.element);
424  };
425
426  Drupal.Ajax.prototype.success = function (response, status) {
427    var _this = this;
428
429    if (this.progress.element) {
430      $(this.progress.element).remove();
431    }
432    if (this.progress.object) {
433      this.progress.object.stopMonitoring();
434    }
435    $(this.element).prop('disabled', false);
436
437    var elementParents = $(this.element).parents('[data-drupal-selector]').addBack().toArray();
438
439    var focusChanged = false;
440    Object.keys(response || {}).forEach(function (i) {
441      if (response[i].command && _this.commands[response[i].command]) {
442        _this.commands[response[i].command](_this, response[i], status);
443        if (response[i].command === 'invoke' && response[i].method === 'focus') {
444          focusChanged = true;
445        }
446      }
447    });
448
449    if (!focusChanged && this.element && !$(this.element).data('disable-refocus')) {
450      var target = false;
451
452      for (var n = elementParents.length - 1; !target && n >= 0; n--) {
453        target = document.querySelector('[data-drupal-selector="' + elementParents[n].getAttribute('data-drupal-selector') + '"]');
454      }
455
456      if (target) {
457        $(target).trigger('focus');
458      }
459    }
460
461    if (this.$form && document.body.contains(this.$form.get(0))) {
462      var settings = this.settings || drupalSettings;
463      Drupal.attachBehaviors(this.$form.get(0), settings);
464    }
465
466    this.settings = null;
467  };
468
469  Drupal.Ajax.prototype.getEffect = function (response) {
470    var type = response.effect || this.effect;
471    var speed = response.speed || this.speed;
472
473    var effect = {};
474    if (type === 'none') {
475      effect.showEffect = 'show';
476      effect.hideEffect = 'hide';
477      effect.showSpeed = '';
478    } else if (type === 'fade') {
479      effect.showEffect = 'fadeIn';
480      effect.hideEffect = 'fadeOut';
481      effect.showSpeed = speed;
482    } else {
483      effect.showEffect = type + 'Toggle';
484      effect.hideEffect = type + 'Toggle';
485      effect.showSpeed = speed;
486    }
487
488    return effect;
489  };
490
491  Drupal.Ajax.prototype.error = function (xmlhttprequest, uri, customMessage) {
492    if (this.progress.element) {
493      $(this.progress.element).remove();
494    }
495    if (this.progress.object) {
496      this.progress.object.stopMonitoring();
497    }
498
499    $(this.wrapper).show();
500
501    $(this.element).prop('disabled', false);
502
503    if (this.$form && document.body.contains(this.$form.get(0))) {
504      var settings = this.settings || drupalSettings;
505      Drupal.attachBehaviors(this.$form.get(0), settings);
506    }
507    throw new Drupal.AjaxError(xmlhttprequest, uri, customMessage);
508  };
509
510  Drupal.theme.ajaxWrapperNewContent = function ($newContent, ajax, response) {
511    return (response.effect || ajax.effect) !== 'none' && $newContent.filter(function (i) {
512      return !($newContent[i].nodeName === '#comment' || $newContent[i].nodeName === '#text' && /^(\s|\n|\r)*$/.test($newContent[i].textContent));
513    }).length > 1 ? Drupal.theme('ajaxWrapperMultipleRootElements', $newContent) : $newContent;
514  };
515
516  Drupal.theme.ajaxWrapperMultipleRootElements = function ($elements) {
517    return $('<div></div>').append($elements);
518  };
519
520  Drupal.AjaxCommands = function () {};
521  Drupal.AjaxCommands.prototype = {
522    insert: function insert(ajax, response) {
523      var $wrapper = response.selector ? $(response.selector) : $(ajax.wrapper);
524      var method = response.method || ajax.method;
525      var effect = ajax.getEffect(response);
526
527      var settings = response.settings || ajax.settings || drupalSettings;
528
529      var $newContent = $($.parseHTML(response.data, document, true));
530
531      $newContent = Drupal.theme('ajaxWrapperNewContent', $newContent, ajax, response);
532
533      switch (method) {
534        case 'html':
535        case 'replaceWith':
536        case 'replaceAll':
537        case 'empty':
538        case 'remove':
539          Drupal.detachBehaviors($wrapper.get(0), settings);
540          break;
541        default:
542          break;
543      }
544
545      $wrapper[method]($newContent);
546
547      if (effect.showEffect !== 'show') {
548        $newContent.hide();
549      }
550
551      var $ajaxNewContent = $newContent.find('.ajax-new-content');
552      if ($ajaxNewContent.length) {
553        $ajaxNewContent.hide();
554        $newContent.show();
555        $ajaxNewContent[effect.showEffect](effect.showSpeed);
556      } else if (effect.showEffect !== 'show') {
557        $newContent[effect.showEffect](effect.showSpeed);
558      }
559
560      if ($newContent.parents('html').length) {
561        $newContent.each(function (index, element) {
562          if (element.nodeType === Node.ELEMENT_NODE) {
563            Drupal.attachBehaviors(element, settings);
564          }
565        });
566      }
567    },
568    remove: function remove(ajax, response, status) {
569      var settings = response.settings || ajax.settings || drupalSettings;
570      $(response.selector).each(function () {
571        Drupal.detachBehaviors(this, settings);
572      }).remove();
573    },
574    changed: function changed(ajax, response, status) {
575      var $element = $(response.selector);
576      if (!$element.hasClass('ajax-changed')) {
577        $element.addClass('ajax-changed');
578        if (response.asterisk) {
579          $element.find(response.asterisk).append(' <abbr class="ajax-changed" title="' + Drupal.t('Changed') + '">*</abbr> ');
580        }
581      }
582    },
583    alert: function alert(ajax, response, status) {
584      window.alert(response.text, response.title);
585    },
586    announce: function announce(ajax, response) {
587      if (response.priority) {
588        Drupal.announce(response.text, response.priority);
589      } else {
590        Drupal.announce(response.text);
591      }
592    },
593    redirect: function redirect(ajax, response, status) {
594      window.location = response.url;
595    },
596    css: function css(ajax, response, status) {
597      $(response.selector).css(response.argument);
598    },
599    settings: function settings(ajax, response, status) {
600      var ajaxSettings = drupalSettings.ajax;
601
602      if (ajaxSettings) {
603        Drupal.ajax.expired().forEach(function (instance) {
604
605          if (instance.selector) {
606            var selector = instance.selector.replace('#', '');
607            if (selector in ajaxSettings) {
608              delete ajaxSettings[selector];
609            }
610          }
611        });
612      }
613
614      if (response.merge) {
615        $.extend(true, drupalSettings, response.settings);
616      } else {
617        ajax.settings = response.settings;
618      }
619    },
620    data: function data(ajax, response, status) {
621      $(response.selector).data(response.name, response.value);
622    },
623    invoke: function invoke(ajax, response, status) {
624      var $element = $(response.selector);
625      $element[response.method].apply($element, _toConsumableArray(response.args));
626    },
627    restripe: function restripe(ajax, response, status) {
628      $(response.selector).find('> tbody > tr:visible, > tr:visible').removeClass('odd even').filter(':even').addClass('odd').end().filter(':odd').addClass('even');
629    },
630    update_build_id: function update_build_id(ajax, response, status) {
631      $('input[name="form_build_id"][value="' + response.old + '"]').val(response.new);
632    },
633    add_css: function add_css(ajax, response, status) {
634      $('head').prepend(response.data);
635    },
636    message: function message(ajax, response) {
637      var messages = new Drupal.Message(document.querySelector(response.messageWrapperQuerySelector));
638      if (response.clearPrevious) {
639        messages.clear();
640      }
641      messages.add(response.message, response.messageOptions);
642    }
643  };
644})(jQuery, window, 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.