Сегодня я покажу, что нужно сделать, чтобы модальное окно закрывалось с задержкой. Для этого мы напишем небольшой модуль, в котором создадим новую AJAX команду, которая будет использоваться вместо ctools_modal_command_dismiss().
Шаг 1. Создаем в своем модуле файл *.js и в нем создаем новую команду, у меня она будет называться example_modal_dismiss:
(function ($) {
/**
* Command to dismiss the modal.
*/
Drupal.ajax.prototype.commands.example_modal_dismiss = function(ajax, response, status) {
setTimeout(function () {
Drupal.CTools.Modal.dismiss();
$('link.ctools-temporary-css').remove();
}, response.delay);
}
})(jQuery);
Шаг 2.В файле *.module создаем команду:
/**
* Creates a Drupal Ajax 'example_modal_dismiss' command.
*
* This command is implemented by
* Drupal.ajax.prototype.commands.example_modal_dismiss().
*
* @param int $delay
* The delay before closing the window in milliseconds.
*
* @return array
* An array suitable for use with the ajax_render() function.
*/
function example_ctools_modal_command_dismiss($delay = 0) {
return array(
'command' => 'example_modal_dismiss',
'delay' => $delay,
);
}
Пример использования:
if (!empty($form_state['executed'])) {
ctools_add_js('ajax', 'example');
$commands = array();
$commands[] = example_ctools_modal_command_dismiss(3000);
}
return array('#type' => 'ajax', '#commands' => $commands);
P.S. Не забываем подключать js, в котором создана команда перед использованием.