PageSourceSearch

https://ocana.es/core/misc/ajax.js?v=9.4.9

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

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.