* Extends the Drupal AJAX functionality to integrate the dialog API.
*/
-(function ($, Drupal) {
+(function($, Drupal) {
/**
* Initialize dialogs for Ajax purposes.
*
// Add 'ui-front' jQuery UI class so jQuery UI widgets like autocomplete
// sit on top of dialogs. For more information see
// http://api.jqueryui.com/theming/stacking-elements/.
- $('<div id="drupal-modal" class="ui-front"/>').hide().appendTo('body');
+ $('<div id="drupal-modal" class="ui-front"/>')
+ .hide()
+ .appendTo('body');
}
// Special behaviors specific when attaching content within a dialog.
const originalClose = settings.dialog.close;
// Overwrite the close method to remove the dialog on closing.
- settings.dialog.close = function (event, ...args) {
+ settings.dialog.close = function(event, ...args) {
originalClose.apply(settings.dialog, [event, ...args]);
$(event.target).remove();
};
*/
prepareDialogButtons($dialog) {
const buttons = [];
- const $buttons = $dialog.find('.form-actions input[type=submit], .form-actions a.button');
- $buttons.each(function () {
+ const $buttons = $dialog.find(
+ '.form-actions input[type=submit], .form-actions a.button',
+ );
+ $buttons.each(function() {
// Hidden form buttons need special attention. For browser consistency,
// the button needs to be "visible" in order to have the enter key fire
// the form submit event. So instead of a simple "hide" or
// event will not simulate a click. Use the click method instead.
if ($originalButton.is('a')) {
$originalButton[0].click();
- }
- else {
- $originalButton.trigger('mousedown').trigger('mouseup').trigger('click');
+ } else {
+ $originalButton
+ .trigger('mousedown')
+ .trigger('mouseup')
+ .trigger('click');
e.preventDefault();
}
},
* @return {bool|undefined}
* Returns false if there was no selector property in the response object.
*/
- Drupal.AjaxCommands.prototype.openDialog = function (ajax, response, status) {
+ Drupal.AjaxCommands.prototype.openDialog = function(ajax, response, status) {
if (!response.selector) {
return false;
}
let $dialog = $(response.selector);
if (!$dialog.length) {
// Create the element if needed.
- $dialog = $(`<div id="${response.selector.replace(/^#/, '')}" class="ui-front"/>`).appendTo('body');
+ $dialog = $(
+ `<div id="${response.selector.replace(/^#/, '')}" class="ui-front"/>`,
+ ).appendTo('body');
}
// Set up the wrapper, if there isn't one.
if (!ajax.wrapper) {
// Move the buttons to the jQuery UI dialog buttons area.
if (!response.dialogOptions.buttons) {
response.dialogOptions.drupalAutoButtons = true;
- response.dialogOptions.buttons = Drupal.behaviors.dialog.prepareDialogButtons($dialog);
+ response.dialogOptions.buttons = Drupal.behaviors.dialog.prepareDialogButtons(
+ $dialog,
+ );
}
// Bind dialogButtonsChange.
const dialog = Drupal.dialog($dialog.get(0), response.dialogOptions);
if (response.dialogOptions.modal) {
dialog.showModal();
- }
- else {
+ } else {
dialog.show();
}
// Add the standard Drupal class for buttons for style consistency.
- $dialog.parent().find('.ui-dialog-buttonset').addClass('form-actions');
+ $dialog
+ .parent()
+ .find('.ui-dialog-buttonset')
+ .addClass('form-actions');
};
/**
* @param {number} [status]
* The HTTP status code.
*/
- Drupal.AjaxCommands.prototype.closeDialog = function (ajax, response, status) {
+ Drupal.AjaxCommands.prototype.closeDialog = function(ajax, response, status) {
const $dialog = $(response.selector);
if ($dialog.length) {
Drupal.dialog($dialog.get(0)).close();
* @param {number} [status]
* The HTTP status code.
*/
- Drupal.AjaxCommands.prototype.setDialogOption = function (ajax, response, status) {
+ Drupal.AjaxCommands.prototype.setDialogOption = function(
+ ajax,
+ response,
+ status,
+ ) {
const $dialog = $(response.selector);
if ($dialog.length) {
$dialog.dialog('option', response.optionName, response.optionValue);
* Dialog settings.
*/
$(window).on('dialog:aftercreate', (e, dialog, $element, settings) => {
- $element.on('click.dialog', '.dialog-cancel', (e) => {
+ $element.on('click.dialog', '.dialog-cancel', e => {
dialog.close('cancel');
e.preventDefault();
e.stopPropagation();
$(window).on('dialog:beforeclose', (e, dialog, $element) => {
$element.off('.dialog');
});
-}(jQuery, Drupal));
+})(jQuery, Drupal);