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