Class: AjaxCommands

Drupal. AjaxCommands

new Drupal.AjaxCommands()

Provide a series of commands that the client will perform.

Methods

add_css(ajax, response, status)

Command to add css.

Uses the proprietary addImport method if available as browsers which support that method ignore @import statements in dynamically added stylesheets.

Name Type Description
ajax Drupal.Ajax optional

Drupal.Ajax object created by Drupal.ajax.

response object

The response from the Ajax request.

Name Type Description
data string

A string that contains the styles to be added.

status number optional

The XMLHttpRequest status.

alert(ajax, response, status)

Command to provide an alert.

Name Type Description
ajax Drupal.Ajax optional

Drupal.Ajax object created by Drupal.ajax.

response object

The JSON response from the Ajax request.

Name Type Description
text string

The text that will be displayed in an alert dialog.

status number optional

The XMLHttpRequest status.

changed(ajax, response, status)

Command to mark a chunk changed.

Name Type Description
ajax Drupal.Ajax optional

Drupal.Ajax object created by Drupal.ajax.

response object

The JSON response object from the Ajax request.

Name Type Description
selector string

A jQuery selector string.

asterisk bool optional

An optional CSS selector. If specified, an asterisk will be appended to the HTML inside the provided selector.

status number optional

The request status.

closeDialog(ajax, response, status)

Command to close a dialog.

If no selector is given, it defaults to trying to close the modal.

Name Type Description
ajax Drupal.Ajax optional

The ajax object.

response object

Object holding the server response.

Name Type Description
selector string

The selector of the dialog.

persist bool

Whether to persist the dialog element or not.

status number optional

The HTTP status code.

css(ajax, response, status)

Command to provide the jQuery css() function.

Name Type Description
ajax Drupal.Ajax optional

Drupal.Ajax object created by Drupal.ajax.

response object

The response from the Ajax request.

Name Type Description
selector string

A jQuery selector string.

argument object

An array of key/value pairs to set in the CSS for the selector.

status number optional

The XMLHttpRequest status.

data(ajax, response, status)

Command to attach data using jQuery's data API.

Name Type Description
ajax Drupal.Ajax optional

Drupal.Ajax object created by Drupal.ajax.

response object

The response from the Ajax request.

Name Type Description
name string

The name or key (in the key value pair) of the data attached to this selector.

selector string

A jQuery selector string.

value string | object

The value of to be attached.

status number optional

The XMLHttpRequest status.

editorDialogSave(ajax, response, status)

Command to save the contents of an editor-provided modal.

This command does not close the open modal. It should be followed by a call to Drupal.AjaxCommands.prototype.closeDialog. Editors that are integrated with dialogs must independently listen for an editor:dialogsave event to save the changes into the contents of their interface.

Name Type Description
ajax Drupal.Ajax optional

The Drupal.Ajax object.

response object

The server response from the ajax request.

Name Type Description
values Array

The values that were saved.

status number optional

The status code from the ajax request.

Fires:
  • event:editor:dialogsave

insert(ajax, response, status)

Command to insert new content into the DOM.

Name Type Description
ajax Drupal.Ajax

Drupal.Ajax object created by Drupal.ajax.

response object

The response from the Ajax request.

Name Type Description
data string

The data to use with the jQuery method.

method string optional

The jQuery DOM manipulation method to be used.

selector string optional

A optional jQuery selector string.

settings object optional

An optional array of settings that will be used.

status number optional

The XMLHttpRequest status.

invoke(ajax, response, status)

Command to apply a jQuery method.

Name Type Description
ajax Drupal.Ajax optional

Drupal.Ajax object created by Drupal.ajax.

response object

The response from the Ajax request.

Name Type Description
args Array

An array of arguments to the jQuery method, if any.

method string

The jQuery method to invoke.

selector string

A jQuery selector string.

status number optional

The XMLHttpRequest status.

openDialog(ajax, response, status){bool|undefined}

Command to open a dialog.

Name Type Description
ajax Drupal.Ajax

The Drupal Ajax object.

response object

Object holding the server response.

status number optional

The HTTP status code.

Returns:
Type Description
bool | undefined Returns false if there was no selector property in the response object.

redirect(ajax, response, status)

Command to set the window.location, redirecting the browser.

Name Type Description
ajax Drupal.Ajax optional

Drupal.Ajax object created by Drupal.ajax.

response object

The response from the Ajax request.

Name Type Description
url string

The URL to redirect to.

status number optional

The XMLHttpRequest status.

remove(ajax, response, status)

Command to remove a chunk from the page.

Name Type Description
ajax Drupal.Ajax optional

Drupal.Ajax object created by Drupal.ajax.

response object

The response from the Ajax request.

Name Type Description
selector string

A jQuery selector string.

settings object optional

An optional array of settings that will be used.

status number optional

The XMLHttpRequest status.

restripe(ajax, response, status)

Command to restripe a table.

Name Type Description
ajax Drupal.Ajax optional

Drupal.Ajax object created by Drupal.ajax.

response object

The response from the Ajax request.

Name Type Description
selector string

A jQuery selector string.

status number optional

The XMLHttpRequest status.

setDialogOption(ajax, response, status)

Command to set a dialog property.

JQuery UI specific way of setting dialog options.

Name Type Description
ajax Drupal.Ajax optional

The Drupal Ajax object.

response object

Object holding the server response.

Name Type Description
selector string

Selector for the dialog element.

optionsName string

Name of a key to set.

optionValue string

Value to set.

status number optional

The HTTP status code.

settings(ajax, response, status)

Command to set the settings used for other commands in this response.

This method will also remove expired drupalSettings.ajax settings.

Name Type Description
ajax Drupal.Ajax optional

Drupal.Ajax object created by Drupal.ajax.

response object

The response from the Ajax request.

Name Type Description
merge bool

Determines whether the additional settings should be merged to the global settings.

settings object

Contains additional settings to add to the global settings.

status number optional

The XMLHttpRequest status.

setToolbarSubtrees(ajax, response, status)

Ajax command to set the toolbar subtrees.

Name Type Description
ajax Drupal.Ajax

Drupal.Ajax object created by Drupal.ajax.

response object

JSON response from the Ajax request.

status number optional

XMLHttpRequest status.

update_build_id(ajax, response, status)

Command to update a form's build ID.

Name Type Description
ajax Drupal.Ajax optional

Drupal.Ajax object created by Drupal.ajax.

response object

The response from the Ajax request.

Name Type Description
old string

The old form build ID.

new string

The new form build ID.

status number optional

The XMLHttpRequest status.

viewsHighlight(ajax, response, status)

Ajax command for highlighting elements.

Name Type Description
ajax Drupal.Ajax optional

An Ajax object.

response object

The Ajax response.

Name Type Description
selector string

The selector in question.

status number optional

The HTTP status code.

viewsReplaceTitle(ajax, response, status)

Ajax command to replace the title of a page.

Name Type Description
ajax Drupal.Ajax optional

An Ajax object.

response object

The Ajax response.

Name Type Description
siteName string

The site name.

title string

The new page title.

status number optional

The HTTP status code.

viewsScrollTop(ajax, response)

Views scroll to top ajax command.

Name Type Description
ajax Drupal.Ajax optional

A Drupal.ajax object.

response object

Ajax response.

Name Type Description
selector string

Selector to use.

viewsSetForm(ajax, response, status)

Ajax command to set the form submit action in the views modal edit form.

Name Type Description
ajax Drupal.Ajax optional

An Ajax object.

response object

The Ajax response. Contains .url

status string optional

The XHR status code?

viewsShowButtons(ajax, response, status)

Ajax command to show certain buttons in the views edit form.

Name Type Description
ajax Drupal.Ajax optional

An Ajax object.

response object

The Ajax response.

Name Type Description
changed bool

Whether the state changed for the buttons or not.

status number optional

The HTTP status code.

viewsTriggerPreview(ajax, response, status)

Ajax command for triggering preview.

Name Type Description
ajax Drupal.Ajax optional

An Ajax object.

response object optional

The Ajax response.

status number optional

The HTTP status code.

Type Definitions

commandDefinitionobject

Properties:
Name Type Argument Description
command string
method string <optional>
selector string <optional>
data string <optional>
settings object <optional>
asterisk bool <optional>
text string <optional>
title string <optional>
url string <optional>
argument object <optional>
name string <optional>
value string <optional>
old string <optional>
new string <optional>
merge bool <optional>
args Array <optional>
See: