Update to Drupal 8.1.0. For more information, see https://www.drupal.org/drupal-8.1.0-release-notes
This commit is contained in:
parent
b11a755ba8
commit
c0a0d5a94c
6920 changed files with 64395 additions and 57312 deletions
|
@ -19,6 +19,14 @@
|
|||
* Attaches the Ajax behavior to each Ajax form element.
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*
|
||||
* @prop {Drupal~behaviorAttach} attach
|
||||
* Initialize all {@link Drupal.Ajax} objects declared in
|
||||
* `drupalSettings.ajax` or initialize {@link Drupal.Ajax} objects from
|
||||
* DOM elements having the `use-ajax-submit` or `use-ajax` css class.
|
||||
* @prop {Drupal~behaviorDetach} detach
|
||||
* During `unload` remove all {@link Drupal.Ajax} objects related to
|
||||
* the removed content.
|
||||
*/
|
||||
Drupal.behaviors.AJAX = {
|
||||
attach: function (context, settings) {
|
||||
|
@ -50,8 +58,9 @@
|
|||
|
||||
// For anchor tags, these will go to the target of the anchor rather
|
||||
// than the usual location.
|
||||
if ($(this).attr('href')) {
|
||||
element_settings.url = $(this).attr('href');
|
||||
var href = $(this).attr('href');
|
||||
if (href) {
|
||||
element_settings.url = href;
|
||||
element_settings.event = 'click';
|
||||
}
|
||||
element_settings.dialogType = $(this).data('dialog-type');
|
||||
|
@ -81,6 +90,16 @@
|
|||
|
||||
Drupal.ajax(element_settings);
|
||||
});
|
||||
},
|
||||
|
||||
detach: function (context, settings, trigger) {
|
||||
if (trigger === 'unload') {
|
||||
Drupal.ajax.expired().forEach(function (instance) {
|
||||
// Set this to null and allow garbage collection to reclaim
|
||||
// the memory.
|
||||
Drupal.ajax.instances[instance.instanceIndex] = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -209,6 +228,7 @@
|
|||
* event listeners will be bound.
|
||||
*
|
||||
* @return {Drupal.Ajax}
|
||||
* The created Ajax object.
|
||||
*
|
||||
* @see Drupal.AjaxCommands
|
||||
*/
|
||||
|
@ -237,10 +257,65 @@
|
|||
/**
|
||||
* Contains all created Ajax objects.
|
||||
*
|
||||
* @type {Array.<Drupal.Ajax>}
|
||||
* @type {Array.<Drupal.Ajax|null>}
|
||||
*/
|
||||
Drupal.ajax.instances = [];
|
||||
|
||||
/**
|
||||
* List all objects where the associated element is not in the DOM
|
||||
*
|
||||
* This method ignores {@link Drupal.Ajax} objects not bound to DOM elements
|
||||
* when created with {@link Drupal.ajax}.
|
||||
*
|
||||
* @return {Array.<Drupal.Ajax>}
|
||||
* The list of expired {@link Drupal.Ajax} objects.
|
||||
*/
|
||||
Drupal.ajax.expired = function () {
|
||||
return Drupal.ajax.instances.filter(function (instance) {
|
||||
return instance && instance.element !== false && !document.body.contains(instance.element);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Settings for an Ajax object.
|
||||
*
|
||||
* @typedef {object} Drupal.Ajax~element_settings
|
||||
*
|
||||
* @prop {string} url
|
||||
* Target of the Ajax request.
|
||||
* @prop {?string} [event]
|
||||
* Event bound to settings.element which will trigger the Ajax request.
|
||||
* @prop {bool} [keypress=true]
|
||||
* Triggers a request on keypress events.
|
||||
* @prop {?string} selector
|
||||
* jQuery selector targeting the element to bind events to or used with
|
||||
* {@link Drupal.AjaxCommands}.
|
||||
* @prop {string} [effect='none']
|
||||
* Name of the jQuery method to use for displaying new Ajax content.
|
||||
* @prop {string|number} [speed='none']
|
||||
* Speed with which to apply the effect.
|
||||
* @prop {string} [method]
|
||||
* Name of the jQuery method used to insert new content in the targeted
|
||||
* element.
|
||||
* @prop {object} [progress]
|
||||
* Settings for the display of a user-friendly loader.
|
||||
* @prop {string} [progress.type='throbber']
|
||||
* Type of progress element, core provides `'bar'`, `'throbber'` and
|
||||
* `'fullscreen'`.
|
||||
* @prop {string} [progress.message=Drupal.t('Please wait...')]
|
||||
* Custom message to be used with the bar indicator.
|
||||
* @prop {object} [submit]
|
||||
* Extra data to be sent with the Ajax request.
|
||||
* @prop {bool} [submit.js=true]
|
||||
* Allows the PHP side to know this comes from an Ajax request.
|
||||
* @prop {object} [dialog]
|
||||
* Options for {@link Drupal.dialog}.
|
||||
* @prop {string} [dialogType]
|
||||
* One of `'modal'` or `'dialog'`.
|
||||
* @prop {string} [prevent]
|
||||
* List of events on which to stop default action and stop propagation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Ajax constructor.
|
||||
*
|
||||
|
@ -258,14 +333,8 @@
|
|||
* @param {HTMLElement} [element]
|
||||
* Element parameter of {@link Drupal.Ajax} constructor, element on which
|
||||
* event listeners will be bound.
|
||||
* @param {object} element_settings
|
||||
* @param {string} element_settings.url
|
||||
* Target of the Ajax request.
|
||||
* @param {string} [element_settings.event]
|
||||
* Event bound to settings.element which will trigger the Ajax request.
|
||||
* @param {string} [element_settings.method]
|
||||
* Name of the jQuery method used to insert new content in the targeted
|
||||
* element.
|
||||
* @param {Drupal.Ajax~element_settings} element_settings
|
||||
* Settings for this Ajax object.
|
||||
*/
|
||||
Drupal.Ajax = function (base, element, element_settings) {
|
||||
var defaults = {
|
||||
|
@ -290,6 +359,10 @@
|
|||
* @type {Drupal.AjaxCommands}
|
||||
*/
|
||||
this.commands = new Drupal.AjaxCommands();
|
||||
|
||||
/**
|
||||
* @type {bool|number}
|
||||
*/
|
||||
this.instanceIndex = false;
|
||||
|
||||
// @todo Remove this after refactoring the PHP code to:
|
||||
|
@ -310,7 +383,7 @@
|
|||
this.element = element;
|
||||
|
||||
/**
|
||||
* @type {object}
|
||||
* @type {Drupal.Ajax~element_settings}
|
||||
*/
|
||||
this.element_settings = element_settings;
|
||||
|
||||
|
@ -343,6 +416,12 @@
|
|||
// 3. /nojs? - Followed by a query (e.g. path/nojs?destination=foobar).
|
||||
// 4. /nojs# - Followed by a fragment (e.g.: path/nojs#myfragment).
|
||||
var originalUrl = this.url;
|
||||
|
||||
/**
|
||||
* Processed Ajax URL.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
this.url = this.url.replace(/\/nojs(\/|$|\?|#)/g, '/ajax$1');
|
||||
// If the 'nojs' version of the URL is trusted, also trust the 'ajax'
|
||||
// version.
|
||||
|
@ -355,23 +434,35 @@
|
|||
var ajax = this;
|
||||
|
||||
/**
|
||||
* Options for the ajaxSubmit function.
|
||||
* Options for the jQuery.ajax function.
|
||||
*
|
||||
* @name Drupal.Ajax#options
|
||||
*
|
||||
* @type {object}
|
||||
*
|
||||
* @prop {string} url
|
||||
* Ajax URL to be called.
|
||||
* @prop {object} data
|
||||
* Ajax payload.
|
||||
* @prop {function} beforeSerialize
|
||||
* Implement jQuery beforeSerialize function to call
|
||||
* {@link Drupal.Ajax#beforeSerialize}.
|
||||
* @prop {function} beforeSubmit
|
||||
* Implement jQuery beforeSubmit function to call
|
||||
* {@link Drupal.Ajax#beforeSubmit}.
|
||||
* @prop {function} beforeSend
|
||||
* Implement jQuery beforeSend function to call
|
||||
* {@link Drupal.Ajax#beforeSend}.
|
||||
* @prop {function} success
|
||||
* Implement jQuery success function to call
|
||||
* {@link Drupal.Ajax#success}.
|
||||
* @prop {function} complete
|
||||
* @prop {string} dataType
|
||||
* @prop {object} accepts
|
||||
* @prop {string} accepts.json
|
||||
* @prop {string} type
|
||||
* Implement jQuery success function to clean up ajax state and trigger an
|
||||
* error if needed.
|
||||
* @prop {string} dataType='json'
|
||||
* Type of the response expected.
|
||||
* @prop {string} type='POST'
|
||||
* HTTP method to use for the Ajax request.
|
||||
*/
|
||||
ajax.options = {
|
||||
url: ajax.url,
|
||||
|
@ -469,13 +560,17 @@
|
|||
* modal dialog.
|
||||
*
|
||||
* @const {string}
|
||||
*
|
||||
* @default
|
||||
*/
|
||||
Drupal.ajax.WRAPPER_FORMAT = '_wrapper_format';
|
||||
|
||||
/**
|
||||
* Request parameter to indicate that a request is a Drupal Ajax request.
|
||||
*
|
||||
* @const
|
||||
* @const {string}
|
||||
*
|
||||
* @default
|
||||
*/
|
||||
Drupal.Ajax.AJAX_REQUEST_PARAMETER = '_drupal_ajax';
|
||||
|
||||
|
@ -484,6 +579,11 @@
|
|||
*
|
||||
* Allows developers to execute an Ajax request manually without specifying
|
||||
* an event to respond to.
|
||||
*
|
||||
* @return {object}
|
||||
* Returns the jQuery.Deferred object underlying the Ajax request. If
|
||||
* pre-serialization fails, the Deferred will be returned in the rejected
|
||||
* state.
|
||||
*/
|
||||
Drupal.Ajax.prototype.execute = function () {
|
||||
// Do not perform another ajax command if one is already in progress.
|
||||
|
@ -493,13 +593,17 @@
|
|||
|
||||
try {
|
||||
this.beforeSerialize(this.element, this.options);
|
||||
$.ajax(this.options);
|
||||
// Return the jqXHR so that external code can hook into the Deferred API.
|
||||
return $.ajax(this.options);
|
||||
}
|
||||
catch (e) {
|
||||
// Unset the ajax.ajaxing flag here because it won't be unset during
|
||||
// the complete response.
|
||||
this.ajaxing = false;
|
||||
window.alert('An error occurred while attempting to process ' + this.options.url + ': ' + e.message);
|
||||
// For consistency, return a rejected Deferred (i.e., jqXHR's superclass)
|
||||
// so that calling code can take appropriate action.
|
||||
return $.Deferred().reject();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -514,7 +618,9 @@
|
|||
* SPACE is often used to activate an element without submitting.
|
||||
*
|
||||
* @param {HTMLElement} element
|
||||
* Element the event was triggered on.
|
||||
* @param {jQuery.Event} event
|
||||
* Triggered event.
|
||||
*/
|
||||
Drupal.Ajax.prototype.keypressResponse = function (element, event) {
|
||||
// Create a synonym for this to reduce code confusion.
|
||||
|
@ -542,7 +648,9 @@
|
|||
* Ajax object.
|
||||
*
|
||||
* @param {HTMLElement} element
|
||||
* Element the event was triggered on.
|
||||
* @param {jQuery.Event} event
|
||||
* Triggered event.
|
||||
*/
|
||||
Drupal.Ajax.prototype.eventResponse = function (element, event) {
|
||||
event.preventDefault();
|
||||
|
@ -589,9 +697,10 @@
|
|||
* Runs before the beforeSend() handler (see below), and unlike that one, runs
|
||||
* before field data is collected.
|
||||
*
|
||||
* @param {HTMLElement} element
|
||||
* @param {object} [element]
|
||||
* Ajax object's `element_settings`.
|
||||
* @param {object} options
|
||||
* @param {object} options.data
|
||||
* jQuery.ajax options.
|
||||
*/
|
||||
Drupal.Ajax.prototype.beforeSerialize = function (element, options) {
|
||||
// Allow detaching behaviors to update field values before collecting them.
|
||||
|
@ -621,9 +730,12 @@
|
|||
/**
|
||||
* Modify form values prior to form submission.
|
||||
*
|
||||
* @param {object} form_values
|
||||
* @param {HTMLElement} element
|
||||
* @param {Array.<object>} form_values
|
||||
* Processed form values.
|
||||
* @param {jQuery} element
|
||||
* The form node as a jQuery object.
|
||||
* @param {object} options
|
||||
* jQuery.ajax options.
|
||||
*/
|
||||
Drupal.Ajax.prototype.beforeSubmit = function (form_values, element, options) {
|
||||
// This function is left empty to make it simple to override for modules
|
||||
|
@ -634,8 +746,9 @@
|
|||
* Prepare the Ajax request before it is sent.
|
||||
*
|
||||
* @param {XMLHttpRequest} xmlhttprequest
|
||||
* Native Ajax object.
|
||||
* @param {object} options
|
||||
* @param {object} options.extraData
|
||||
* jQuery.ajax options.
|
||||
*/
|
||||
Drupal.Ajax.prototype.beforeSend = function (xmlhttprequest, options) {
|
||||
// For forms without file inputs, the jQuery Form plugin serializes the
|
||||
|
@ -723,7 +836,9 @@
|
|||
* Handler for the form redirection completion.
|
||||
*
|
||||
* @param {Array.<Drupal.AjaxCommands~commandDefinition>} response
|
||||
* Drupal Ajax response.
|
||||
* @param {number} status
|
||||
* XMLHttpRequest status.
|
||||
*/
|
||||
Drupal.Ajax.prototype.success = function (response, status) {
|
||||
// Remove the progress element.
|
||||
|
@ -786,10 +901,15 @@
|
|||
* Build an effect object to apply an effect when adding new HTML.
|
||||
*
|
||||
* @param {object} response
|
||||
* Drupal Ajax response.
|
||||
* @param {string} [response.effect]
|
||||
* Override the default value of {@link Drupal.Ajax#element_settings}.
|
||||
* @param {string|number} [response.speed]
|
||||
* Override the default value of {@link Drupal.Ajax#element_settings}.
|
||||
*
|
||||
* @return {object}
|
||||
* Returns an object with `showEffect`, `hideEffect` and `showSpeed`
|
||||
* properties.
|
||||
*/
|
||||
Drupal.Ajax.prototype.getEffect = function (response) {
|
||||
var type = response.effect || this.effect;
|
||||
|
@ -819,8 +939,11 @@
|
|||
* Handler for the form redirection error.
|
||||
*
|
||||
* @param {object} xmlhttprequest
|
||||
* Native XMLHttpRequest object.
|
||||
* @param {string} uri
|
||||
* @param {string} customMessage
|
||||
* Ajax Request URI.
|
||||
* @param {string} [customMessage]
|
||||
* Extra message to print with the Ajax error.
|
||||
*/
|
||||
Drupal.Ajax.prototype.error = function (xmlhttprequest, uri, customMessage) {
|
||||
// Remove the progress element.
|
||||
|
@ -877,17 +1000,24 @@
|
|||
* Command to insert new content into the DOM.
|
||||
*
|
||||
* @param {Drupal.Ajax} ajax
|
||||
* {@link Drupal.Ajax} object created by {@link Drupal.ajax}.
|
||||
* @param {object} response
|
||||
* The response from the Ajax request.
|
||||
* @param {string} response.data
|
||||
* The data to use with the jQuery method.
|
||||
* @param {string} [response.method]
|
||||
* The jQuery DOM manipulation method to be used.
|
||||
* @param {string} [response.selector]
|
||||
* A optional jQuery selector string.
|
||||
* @param {object} [response.settings]
|
||||
* An optional array of settings that will be used.
|
||||
* @param {number} [status]
|
||||
* The XMLHttpRequest status.
|
||||
*/
|
||||
insert: function (ajax, response, status) {
|
||||
// Get information from the response. If it is not there, default to
|
||||
// our presets.
|
||||
var wrapper = response.selector ? $(response.selector) : $(ajax.wrapper);
|
||||
var $wrapper = response.selector ? $(response.selector) : $(ajax.wrapper);
|
||||
var method = response.method || ajax.method;
|
||||
var effect = ajax.getEffect(response);
|
||||
var settings;
|
||||
|
@ -897,11 +1027,11 @@
|
|||
// $(response.data) as new HTML rather than a CSS selector. Also, if
|
||||
// response.data contains top-level text nodes, they get lost with either
|
||||
// $(response.data) or $('<div></div>').replaceWith(response.data).
|
||||
var new_content_wrapped = $('<div></div>').html(response.data);
|
||||
var new_content = new_content_wrapped.contents();
|
||||
var $new_content_wrapped = $('<div></div>').html(response.data);
|
||||
var $new_content = $new_content_wrapped.contents();
|
||||
|
||||
// For legacy reasons, the effects processing code assumes that
|
||||
// new_content consists of a single top-level element. Also, it has not
|
||||
// $new_content consists of a single top-level element. Also, it has not
|
||||
// been sufficiently tested whether attachBehaviors() can be successfully
|
||||
// called with a context object that includes top-level text nodes.
|
||||
// However, to give developers full control of the HTML appearing in the
|
||||
|
@ -911,8 +1041,8 @@
|
|||
// top-level element, and only use the container DIV created above when
|
||||
// it doesn't. For more information, please see
|
||||
// https://www.drupal.org/node/736066.
|
||||
if (new_content.length !== 1 || new_content.get(0).nodeType !== 1) {
|
||||
new_content = new_content_wrapped;
|
||||
if ($new_content.length !== 1 || $new_content.get(0).nodeType !== 1) {
|
||||
$new_content = $new_content_wrapped;
|
||||
}
|
||||
|
||||
// If removing content from the wrapper, detach behaviors first.
|
||||
|
@ -923,35 +1053,35 @@
|
|||
case 'empty':
|
||||
case 'remove':
|
||||
settings = response.settings || ajax.settings || drupalSettings;
|
||||
Drupal.detachBehaviors(wrapper.get(0), settings);
|
||||
Drupal.detachBehaviors($wrapper.get(0), settings);
|
||||
}
|
||||
|
||||
// Add the new content to the page.
|
||||
wrapper[method](new_content);
|
||||
$wrapper[method]($new_content);
|
||||
|
||||
// Immediately hide the new content if we're using any effects.
|
||||
if (effect.showEffect !== 'show') {
|
||||
new_content.hide();
|
||||
$new_content.hide();
|
||||
}
|
||||
|
||||
// Determine which effect to use and what content will receive the
|
||||
// effect, then show the new content.
|
||||
if (new_content.find('.ajax-new-content').length > 0) {
|
||||
new_content.find('.ajax-new-content').hide();
|
||||
new_content.show();
|
||||
new_content.find('.ajax-new-content')[effect.showEffect](effect.showSpeed);
|
||||
if ($new_content.find('.ajax-new-content').length > 0) {
|
||||
$new_content.find('.ajax-new-content').hide();
|
||||
$new_content.show();
|
||||
$new_content.find('.ajax-new-content')[effect.showEffect](effect.showSpeed);
|
||||
}
|
||||
else if (effect.showEffect !== 'show') {
|
||||
new_content[effect.showEffect](effect.showSpeed);
|
||||
$new_content[effect.showEffect](effect.showSpeed);
|
||||
}
|
||||
|
||||
// Attach all JavaScript behaviors to the new content, if it was
|
||||
// successfully added to the page, this if statement allows
|
||||
// `#ajax['wrapper']` to be optional.
|
||||
if (new_content.parents('html').length > 0) {
|
||||
if ($new_content.parents('html').length > 0) {
|
||||
// Apply any settings from the returned JSON if available.
|
||||
settings = response.settings || ajax.settings || drupalSettings;
|
||||
Drupal.attachBehaviors(new_content.get(0), settings);
|
||||
Drupal.attachBehaviors($new_content.get(0), settings);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -959,10 +1089,15 @@
|
|||
* Command to remove a chunk from the page.
|
||||
*
|
||||
* @param {Drupal.Ajax} [ajax]
|
||||
* {@link Drupal.Ajax} object created by {@link Drupal.ajax}.
|
||||
* @param {object} response
|
||||
* The response from the Ajax request.
|
||||
* @param {string} response.selector
|
||||
* A jQuery selector string.
|
||||
* @param {object} [response.settings]
|
||||
* An optional array of settings that will be used.
|
||||
* @param {number} [status]
|
||||
* The XMLHttpRequest status.
|
||||
*/
|
||||
remove: function (ajax, response, status) {
|
||||
var settings = response.settings || ajax.settings || drupalSettings;
|
||||
|
@ -976,16 +1111,23 @@
|
|||
* Command to mark a chunk changed.
|
||||
*
|
||||
* @param {Drupal.Ajax} [ajax]
|
||||
* {@link Drupal.Ajax} object created by {@link Drupal.ajax}.
|
||||
* @param {object} response
|
||||
* The JSON response object from the Ajax request.
|
||||
* @param {string} response.selector
|
||||
* A jQuery selector string.
|
||||
* @param {bool} [response.asterisk]
|
||||
* An optional CSS selector. If specified, an asterisk will be
|
||||
* appended to the HTML inside the provided selector.
|
||||
* @param {number} [status]
|
||||
* The request status.
|
||||
*/
|
||||
changed: function (ajax, response, status) {
|
||||
if (!$(response.selector).hasClass('ajax-changed')) {
|
||||
$(response.selector).addClass('ajax-changed');
|
||||
var $element = $(response.selector);
|
||||
if (!$element.hasClass('ajax-changed')) {
|
||||
$element.addClass('ajax-changed');
|
||||
if (response.asterisk) {
|
||||
$(response.selector).find(response.asterisk).append(' <abbr class="ajax-changed" title="' + Drupal.t('Changed') + '">*</abbr> ');
|
||||
$element.find(response.asterisk).append(' <abbr class="ajax-changed" title="' + Drupal.t('Changed') + '">*</abbr> ');
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -994,10 +1136,13 @@
|
|||
* Command to provide an alert.
|
||||
*
|
||||
* @param {Drupal.Ajax} [ajax]
|
||||
* {@link Drupal.Ajax} object created by {@link Drupal.ajax}.
|
||||
* @param {object} response
|
||||
* The JSON response from the Ajax request.
|
||||
* @param {string} response.text
|
||||
* @param {string} response.title
|
||||
* The text that will be displayed in an alert dialog.
|
||||
* @param {number} [status]
|
||||
* The XMLHttpRequest status.
|
||||
*/
|
||||
alert: function (ajax, response, status) {
|
||||
window.alert(response.text, response.title);
|
||||
|
@ -1007,9 +1152,13 @@
|
|||
* Command to set the window.location, redirecting the browser.
|
||||
*
|
||||
* @param {Drupal.Ajax} [ajax]
|
||||
* {@link Drupal.Ajax} object created by {@link Drupal.ajax}.
|
||||
* @param {object} response
|
||||
* The response from the Ajax request.
|
||||
* @param {string} response.url
|
||||
* The URL to redirect to.
|
||||
* @param {number} [status]
|
||||
* The XMLHttpRequest status.
|
||||
*/
|
||||
redirect: function (ajax, response, status) {
|
||||
window.location = response.url;
|
||||
|
@ -1019,9 +1168,15 @@
|
|||
* Command to provide the jQuery css() function.
|
||||
*
|
||||
* @param {Drupal.Ajax} [ajax]
|
||||
* {@link Drupal.Ajax} object created by {@link Drupal.ajax}.
|
||||
* @param {object} response
|
||||
* The response from the Ajax request.
|
||||
* @param {string} response.selector
|
||||
* A jQuery selector string.
|
||||
* @param {object} response.argument
|
||||
* An array of key/value pairs to set in the CSS for the selector.
|
||||
* @param {number} [status]
|
||||
* The XMLHttpRequest status.
|
||||
*/
|
||||
css: function (ajax, response, status) {
|
||||
$(response.selector).css(response.argument);
|
||||
|
@ -1030,13 +1185,37 @@
|
|||
/**
|
||||
* Command to set the settings used for other commands in this response.
|
||||
*
|
||||
* This method will also remove expired `drupalSettings.ajax` settings.
|
||||
*
|
||||
* @param {Drupal.Ajax} [ajax]
|
||||
* {@link Drupal.Ajax} object created by {@link Drupal.ajax}.
|
||||
* @param {object} response
|
||||
* The response from the Ajax request.
|
||||
* @param {bool} response.merge
|
||||
* Determines whether the additional settings should be merged to the
|
||||
* global settings.
|
||||
* @param {object} response.settings
|
||||
* Contains additional settings to add to the global settings.
|
||||
* @param {number} [status]
|
||||
* The XMLHttpRequest status.
|
||||
*/
|
||||
settings: function (ajax, response, status) {
|
||||
var ajaxSettings = drupalSettings.ajax;
|
||||
|
||||
// Clean up drupalSettings.ajax.
|
||||
Drupal.ajax.expired().forEach(function (instance) {
|
||||
// If the Ajax object has been created through drupalSettings.ajax
|
||||
// it will have a selector. When there is no selector the object
|
||||
// has been initialized with a special class name picked up by the
|
||||
// Ajax behavior.
|
||||
if (instance.selector) {
|
||||
var selector = instance.selector.replace('#', '');
|
||||
if (selector in ajaxSettings) {
|
||||
delete ajaxSettings[selector];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (response.merge) {
|
||||
$.extend(true, drupalSettings, response.settings);
|
||||
}
|
||||
|
@ -1049,11 +1228,18 @@
|
|||
* Command to attach data using jQuery's data API.
|
||||
*
|
||||
* @param {Drupal.Ajax} [ajax]
|
||||
* {@link Drupal.Ajax} object created by {@link Drupal.ajax}.
|
||||
* @param {object} response
|
||||
* The response from the Ajax request.
|
||||
* @param {string} response.name
|
||||
* The name or key (in the key value pair) of the data attached to this
|
||||
* selector.
|
||||
* @param {string} response.selector
|
||||
* A jQuery selector string.
|
||||
* @param {string|object} response.value
|
||||
* The value of to be attached.
|
||||
* @param {number} [status]
|
||||
* The XMLHttpRequest status.
|
||||
*/
|
||||
data: function (ajax, response, status) {
|
||||
$(response.selector).data(response.name, response.value);
|
||||
|
@ -1063,11 +1249,17 @@
|
|||
* Command to apply a jQuery method.
|
||||
*
|
||||
* @param {Drupal.Ajax} [ajax]
|
||||
* {@link Drupal.Ajax} object created by {@link Drupal.ajax}.
|
||||
* @param {object} response
|
||||
* The response from the Ajax request.
|
||||
* @param {Array} response.args
|
||||
* An array of arguments to the jQuery method, if any.
|
||||
* @param {string} response.method
|
||||
* The jQuery method to invoke.
|
||||
* @param {string} response.selector
|
||||
* A jQuery selector string.
|
||||
* @param {number} [status]
|
||||
* The XMLHttpRequest status.
|
||||
*/
|
||||
invoke: function (ajax, response, status) {
|
||||
var $element = $(response.selector);
|
||||
|
@ -1078,9 +1270,13 @@
|
|||
* Command to restripe a table.
|
||||
*
|
||||
* @param {Drupal.Ajax} [ajax]
|
||||
* {@link Drupal.Ajax} object created by {@link Drupal.ajax}.
|
||||
* @param {object} response
|
||||
* The response from the Ajax request.
|
||||
* @param {string} response.selector
|
||||
* A jQuery selector string.
|
||||
* @param {number} [status]
|
||||
* The XMLHttpRequest status.
|
||||
*/
|
||||
restripe: function (ajax, response, status) {
|
||||
// :even and :odd are reversed because jQuery counts from 0 and
|
||||
|
@ -1096,10 +1292,15 @@
|
|||
* Command to update a form's build ID.
|
||||
*
|
||||
* @param {Drupal.Ajax} [ajax]
|
||||
* {@link Drupal.Ajax} object created by {@link Drupal.ajax}.
|
||||
* @param {object} response
|
||||
* The response from the Ajax request.
|
||||
* @param {string} response.old
|
||||
* The old form build ID.
|
||||
* @param {string} response.new
|
||||
* The new form build ID.
|
||||
* @param {number} [status]
|
||||
* The XMLHttpRequest status.
|
||||
*/
|
||||
update_build_id: function (ajax, response, status) {
|
||||
$('input[name="form_build_id"][value="' + response.old + '"]').val(response.new);
|
||||
|
@ -1113,9 +1314,13 @@
|
|||
* stylesheets.
|
||||
*
|
||||
* @param {Drupal.Ajax} [ajax]
|
||||
* {@link Drupal.Ajax} object created by {@link Drupal.ajax}.
|
||||
* @param {object} response
|
||||
* The response from the Ajax request.
|
||||
* @param {string} response.data
|
||||
* A string that contains the styles to be added.
|
||||
* @param {number} [status]
|
||||
* The XMLHttpRequest status.
|
||||
*/
|
||||
add_css: function (ajax, response, status) {
|
||||
// Add the styles in the normal way.
|
||||
|
@ -1133,4 +1338,4 @@
|
|||
}
|
||||
};
|
||||
|
||||
})(jQuery, this, Drupal, drupalSettings);
|
||||
})(jQuery, window, Drupal, drupalSettings);
|
||||
|
|
Reference in a new issue