Chris@0: /** Chris@0: * DO NOT EDIT THIS FILE. Chris@0: * See the following change record for more information, Chris@0: * https://www.drupal.org/node/2815083 Chris@0: * @preserve Chris@0: **/ Chris@0: function _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); } } Chris@0: Chris@0: (function ($, window, Drupal, drupalSettings) { Chris@0: Drupal.behaviors.AJAX = { Chris@0: attach: function attach(context, settings) { Chris@0: function loadAjaxBehavior(base) { Chris@14: var elementSettings = settings.ajax[base]; Chris@14: if (typeof elementSettings.selector === 'undefined') { Chris@14: elementSettings.selector = '#' + base; Chris@0: } Chris@14: $(elementSettings.selector).once('drupal-ajax').each(function () { Chris@14: elementSettings.element = this; Chris@14: elementSettings.base = base; Chris@14: Drupal.ajax(elementSettings); Chris@0: }); Chris@0: } Chris@0: Chris@14: Object.keys(settings.ajax || {}).forEach(function (base) { Chris@14: return loadAjaxBehavior(base); Chris@0: }); Chris@0: Chris@14: Drupal.ajax.bindAjaxLinks(document.body); Chris@14: Chris@0: $('.use-ajax-submit').once('ajax').each(function () { Chris@14: var elementSettings = {}; Chris@0: Chris@14: elementSettings.url = $(this.form).attr('action'); Chris@0: Chris@14: elementSettings.setClick = true; Chris@0: Chris@14: elementSettings.event = 'click'; Chris@0: Chris@14: elementSettings.progress = { type: 'throbber' }; Chris@14: elementSettings.base = $(this).attr('id'); Chris@14: elementSettings.element = this; Chris@0: Chris@14: Drupal.ajax(elementSettings); Chris@0: }); Chris@0: }, Chris@0: detach: function detach(context, settings, trigger) { Chris@0: if (trigger === 'unload') { Chris@0: Drupal.ajax.expired().forEach(function (instance) { Chris@0: Drupal.ajax.instances[instance.instanceIndex] = null; Chris@0: }); Chris@0: } Chris@0: } Chris@0: }; Chris@0: Chris@0: Drupal.AjaxError = function (xmlhttp, uri, customMessage) { Chris@0: var statusCode = void 0; Chris@0: var statusText = void 0; Chris@0: var responseText = void 0; Chris@0: if (xmlhttp.status) { Chris@0: statusCode = '\n' + Drupal.t('An AJAX HTTP error occurred.') + '\n' + Drupal.t('HTTP Result Code: !status', { '!status': xmlhttp.status }); Chris@0: } else { Chris@0: statusCode = '\n' + Drupal.t('An AJAX HTTP request terminated abnormally.'); Chris@0: } Chris@0: statusCode += '\n' + Drupal.t('Debugging information follows.'); Chris@14: var pathText = '\n' + Drupal.t('Path: !uri', { '!uri': uri }); Chris@0: statusText = ''; Chris@0: Chris@0: try { Chris@17: statusText = '\n' + Drupal.t('StatusText: !statusText', { Chris@17: '!statusText': $.trim(xmlhttp.statusText) Chris@17: }); Chris@0: } catch (e) {} Chris@0: Chris@0: responseText = ''; Chris@0: Chris@0: try { Chris@17: responseText = '\n' + Drupal.t('ResponseText: !responseText', { Chris@17: '!responseText': $.trim(xmlhttp.responseText) Chris@17: }); Chris@0: } catch (e) {} Chris@0: Chris@0: responseText = responseText.replace(/<("[^"]*"|'[^']*'|[^'">])*>/gi, ''); Chris@0: responseText = responseText.replace(/[\n]+\s+/g, '\n'); Chris@0: Chris@17: var readyStateText = xmlhttp.status === 0 ? '\n' + Drupal.t('ReadyState: !readyState', { Chris@17: '!readyState': xmlhttp.readyState Chris@17: }) : ''; Chris@0: Chris@17: customMessage = customMessage ? '\n' + Drupal.t('CustomMessage: !customMessage', { Chris@17: '!customMessage': customMessage Chris@17: }) : ''; Chris@0: Chris@0: this.message = statusCode + pathText + statusText + customMessage + responseText + readyStateText; Chris@0: Chris@0: this.name = 'AjaxError'; Chris@0: }; Chris@0: Chris@0: Drupal.AjaxError.prototype = new Error(); Chris@0: Drupal.AjaxError.prototype.constructor = Drupal.AjaxError; Chris@0: Chris@0: Drupal.ajax = function (settings) { Chris@0: if (arguments.length !== 1) { Chris@0: throw new Error('Drupal.ajax() function must be called with one configuration object only'); Chris@0: } Chris@0: Chris@0: var base = settings.base || false; Chris@0: var element = settings.element || false; Chris@0: delete settings.base; Chris@0: delete settings.element; Chris@0: Chris@0: if (!settings.progress && !element) { Chris@0: settings.progress = false; Chris@0: } Chris@0: Chris@0: var ajax = new Drupal.Ajax(base, element, settings); Chris@0: ajax.instanceIndex = Drupal.ajax.instances.length; Chris@0: Drupal.ajax.instances.push(ajax); Chris@0: Chris@0: return ajax; Chris@0: }; Chris@0: Chris@0: Drupal.ajax.instances = []; Chris@0: Chris@0: Drupal.ajax.expired = function () { Chris@0: return Drupal.ajax.instances.filter(function (instance) { Chris@0: return instance && instance.element !== false && !document.body.contains(instance.element); Chris@0: }); Chris@0: }; Chris@0: Chris@14: Drupal.ajax.bindAjaxLinks = function (element) { Chris@14: $(element).find('.use-ajax').once('ajax').each(function (i, ajaxLink) { Chris@14: var $linkElement = $(ajaxLink); Chris@14: Chris@14: var elementSettings = { Chris@14: progress: { type: 'throbber' }, Chris@14: dialogType: $linkElement.data('dialog-type'), Chris@14: dialog: $linkElement.data('dialog-options'), Chris@14: dialogRenderer: $linkElement.data('dialog-renderer'), Chris@14: base: $linkElement.attr('id'), Chris@14: element: ajaxLink Chris@14: }; Chris@14: var href = $linkElement.attr('href'); Chris@14: Chris@14: if (href) { Chris@14: elementSettings.url = href; Chris@14: elementSettings.event = 'click'; Chris@14: } Chris@14: Drupal.ajax(elementSettings); Chris@14: }); Chris@14: }; Chris@14: Chris@14: Drupal.Ajax = function (base, element, elementSettings) { Chris@0: var defaults = { Chris@0: event: element ? 'mousedown' : null, Chris@0: keypress: true, Chris@0: selector: base ? '#' + base : null, Chris@0: effect: 'none', Chris@0: speed: 'none', Chris@0: method: 'replaceWith', Chris@0: progress: { Chris@0: type: 'throbber', Chris@0: message: Drupal.t('Please wait...') Chris@0: }, Chris@0: submit: { Chris@0: js: true Chris@0: } Chris@0: }; Chris@0: Chris@14: $.extend(this, defaults, elementSettings); Chris@0: Chris@0: this.commands = new Drupal.AjaxCommands(); Chris@0: Chris@0: this.instanceIndex = false; Chris@0: Chris@0: if (this.wrapper) { Chris@0: this.wrapper = '#' + this.wrapper; Chris@0: } Chris@0: Chris@0: this.element = element; Chris@0: Chris@14: this.element_settings = elementSettings; Chris@14: Chris@14: this.elementSettings = elementSettings; Chris@0: Chris@0: if (this.element && this.element.form) { Chris@0: this.$form = $(this.element.form); Chris@0: } Chris@0: Chris@0: if (!this.url) { Chris@0: var $element = $(this.element); Chris@0: if ($element.is('a')) { Chris@0: this.url = $element.attr('href'); Chris@0: } else if (this.element && element.form) { Chris@0: this.url = this.$form.attr('action'); Chris@0: } Chris@0: } Chris@0: Chris@0: var originalUrl = this.url; Chris@0: Chris@17: this.url = this.url.replace(/\/nojs(\/|$|\?|#)/, '/ajax$1'); Chris@0: Chris@0: if (drupalSettings.ajaxTrustedUrl[originalUrl]) { Chris@0: drupalSettings.ajaxTrustedUrl[this.url] = true; Chris@0: } Chris@0: Chris@0: var ajax = this; Chris@0: Chris@0: ajax.options = { Chris@0: url: ajax.url, Chris@0: data: ajax.submit, Chris@14: beforeSerialize: function beforeSerialize(elementSettings, options) { Chris@14: return ajax.beforeSerialize(elementSettings, options); Chris@0: }, Chris@14: beforeSubmit: function beforeSubmit(formValues, elementSettings, options) { Chris@0: ajax.ajaxing = true; Chris@14: return ajax.beforeSubmit(formValues, elementSettings, options); Chris@0: }, Chris@0: beforeSend: function beforeSend(xmlhttprequest, options) { Chris@0: ajax.ajaxing = true; Chris@0: return ajax.beforeSend(xmlhttprequest, options); Chris@0: }, Chris@0: success: function success(response, status, xmlhttprequest) { Chris@0: if (typeof response === 'string') { Chris@0: response = $.parseJSON(response); Chris@0: } Chris@0: Chris@0: if (response !== null && !drupalSettings.ajaxTrustedUrl[ajax.url]) { Chris@0: if (xmlhttprequest.getResponseHeader('X-Drupal-Ajax-Token') !== '1') { Chris@0: var customMessage = Drupal.t('The response failed verification so will not be processed.'); Chris@0: return ajax.error(xmlhttprequest, ajax.url, customMessage); Chris@0: } Chris@0: } Chris@0: Chris@0: return ajax.success(response, status); Chris@0: }, Chris@0: complete: function complete(xmlhttprequest, status) { Chris@0: ajax.ajaxing = false; Chris@0: if (status === 'error' || status === 'parsererror') { Chris@0: return ajax.error(xmlhttprequest, ajax.url); Chris@0: } Chris@0: }, Chris@0: Chris@0: dataType: 'json', Chris@0: type: 'POST' Chris@0: }; Chris@0: Chris@14: if (elementSettings.dialog) { Chris@14: ajax.options.data.dialogOptions = elementSettings.dialog; Chris@0: } Chris@0: Chris@0: if (ajax.options.url.indexOf('?') === -1) { Chris@0: ajax.options.url += '?'; Chris@0: } else { Chris@0: ajax.options.url += '&'; Chris@0: } Chris@0: Chris@14: var wrapper = 'drupal_' + (elementSettings.dialogType || 'ajax'); Chris@14: if (elementSettings.dialogRenderer) { Chris@14: wrapper += '.' + elementSettings.dialogRenderer; Chris@0: } Chris@0: ajax.options.url += Drupal.ajax.WRAPPER_FORMAT + '=' + wrapper; Chris@0: Chris@14: $(ajax.element).on(elementSettings.event, function (event) { Chris@0: if (!drupalSettings.ajaxTrustedUrl[ajax.url] && !Drupal.url.isLocal(ajax.url)) { Chris@17: throw new Error(Drupal.t('The callback URL is not local and not trusted: !url', { Chris@17: '!url': ajax.url Chris@17: })); Chris@0: } Chris@0: return ajax.eventResponse(this, event); Chris@0: }); Chris@0: Chris@14: if (elementSettings.keypress) { Chris@0: $(ajax.element).on('keypress', function (event) { Chris@0: return ajax.keypressResponse(this, event); Chris@0: }); Chris@0: } Chris@0: Chris@14: if (elementSettings.prevent) { Chris@14: $(ajax.element).on(elementSettings.prevent, false); Chris@0: } Chris@0: }; Chris@0: Chris@0: Drupal.ajax.WRAPPER_FORMAT = '_wrapper_format'; Chris@0: Chris@0: Drupal.Ajax.AJAX_REQUEST_PARAMETER = '_drupal_ajax'; Chris@0: Chris@0: Drupal.Ajax.prototype.execute = function () { Chris@0: if (this.ajaxing) { Chris@0: return; Chris@0: } Chris@0: Chris@0: try { Chris@0: this.beforeSerialize(this.element, this.options); Chris@0: Chris@0: return $.ajax(this.options); Chris@0: } catch (e) { Chris@0: this.ajaxing = false; Chris@0: window.alert('An error occurred while attempting to process ' + this.options.url + ': ' + e.message); Chris@0: Chris@0: return $.Deferred().reject(); Chris@0: } Chris@0: }; Chris@0: Chris@0: Drupal.Ajax.prototype.keypressResponse = function (element, event) { Chris@0: var ajax = this; Chris@0: Chris@0: if (event.which === 13 || event.which === 32 && element.type !== 'text' && element.type !== 'textarea' && element.type !== 'tel' && element.type !== 'number') { Chris@0: event.preventDefault(); Chris@0: event.stopPropagation(); Chris@14: $(element).trigger(ajax.elementSettings.event); Chris@0: } Chris@0: }; Chris@0: Chris@0: Drupal.Ajax.prototype.eventResponse = function (element, event) { Chris@0: event.preventDefault(); Chris@0: event.stopPropagation(); Chris@0: Chris@0: var ajax = this; Chris@0: Chris@0: if (ajax.ajaxing) { Chris@0: return; Chris@0: } Chris@0: Chris@0: try { Chris@0: if (ajax.$form) { Chris@0: if (ajax.setClick) { Chris@0: element.form.clk = element; Chris@0: } Chris@0: Chris@0: ajax.$form.ajaxSubmit(ajax.options); Chris@0: } else { Chris@0: ajax.beforeSerialize(ajax.element, ajax.options); Chris@0: $.ajax(ajax.options); Chris@0: } Chris@0: } catch (e) { Chris@0: ajax.ajaxing = false; Chris@0: window.alert('An error occurred while attempting to process ' + ajax.options.url + ': ' + e.message); Chris@0: } Chris@0: }; Chris@0: Chris@0: Drupal.Ajax.prototype.beforeSerialize = function (element, options) { Chris@17: if (this.$form && document.body.contains(this.$form.get(0))) { Chris@0: var settings = this.settings || drupalSettings; Chris@0: Drupal.detachBehaviors(this.$form.get(0), settings, 'serialize'); Chris@0: } Chris@0: Chris@0: options.data[Drupal.Ajax.AJAX_REQUEST_PARAMETER] = 1; Chris@0: Chris@0: var pageState = drupalSettings.ajaxPageState; Chris@0: options.data['ajax_page_state[theme]'] = pageState.theme; Chris@0: options.data['ajax_page_state[theme_token]'] = pageState.theme_token; Chris@0: options.data['ajax_page_state[libraries]'] = pageState.libraries; Chris@0: }; Chris@0: Chris@14: Drupal.Ajax.prototype.beforeSubmit = function (formValues, element, options) {}; Chris@0: Chris@0: Drupal.Ajax.prototype.beforeSend = function (xmlhttprequest, options) { Chris@0: if (this.$form) { Chris@0: options.extraData = options.extraData || {}; Chris@0: Chris@0: options.extraData.ajax_iframe_upload = '1'; Chris@0: Chris@0: var v = $.fieldValue(this.element); Chris@0: if (v !== null) { Chris@0: options.extraData[this.element.name] = v; Chris@0: } Chris@0: } Chris@0: Chris@0: $(this.element).prop('disabled', true); Chris@0: Chris@0: if (!this.progress || !this.progress.type) { Chris@0: return; Chris@0: } Chris@0: Chris@0: var progressIndicatorMethod = 'setProgressIndicator' + this.progress.type.slice(0, 1).toUpperCase() + this.progress.type.slice(1).toLowerCase(); Chris@0: if (progressIndicatorMethod in this && typeof this[progressIndicatorMethod] === 'function') { Chris@0: this[progressIndicatorMethod].call(this); Chris@0: } Chris@0: }; Chris@0: Chris@17: Drupal.theme.ajaxProgressThrobber = function (message) { Chris@17: var messageMarkup = typeof message === 'string' ? Drupal.theme('ajaxProgressMessage', message) : ''; Chris@17: var throbber = '