- Patch #658720 by casey, David_Rothstein: clean up overlay_close_dialog() and related code.
parent
9f8de06ce5
commit
cf76edd3df
modules/overlay
|
@ -37,7 +37,7 @@ Drupal.behaviors.overlayChild = {
|
|||
// We need to store the parent variable locally because it will
|
||||
// disappear as soon as we close the iframe.
|
||||
var p = parent;
|
||||
p.Drupal.overlay.close(settings.args, settings.statusMessages);
|
||||
p.Drupal.overlay.close();
|
||||
if (typeof settings.redirect == 'string') {
|
||||
p.Drupal.overlay.redirect(settings.redirect);
|
||||
}
|
||||
|
|
|
@ -39,9 +39,6 @@ Drupal.overlay = Drupal.overlay || {
|
|||
isClosing: false,
|
||||
isLoading: false,
|
||||
|
||||
onOverlayCloseArgs: null,
|
||||
onOverlayCloseStatusMessages: null,
|
||||
|
||||
resizeTimeoutID: null,
|
||||
lastHeight: 0,
|
||||
|
||||
|
@ -220,10 +217,8 @@ Drupal.overlay.create = function () {
|
|||
self.lastHeight = 0;
|
||||
|
||||
if ($.isFunction(self.options.onOverlayClose)) {
|
||||
self.options.onOverlayClose(self.onOverlayCloseArgs, self.onOverlayCloseStatusMessages);
|
||||
self.options.onOverlayClose();
|
||||
}
|
||||
self.onOverlayCloseArgs = null;
|
||||
self.onOverlayCloseStatusMessages = null;
|
||||
};
|
||||
|
||||
// Default jQuery UI Dialog options.
|
||||
|
@ -358,13 +353,8 @@ Drupal.overlay.load = function (url) {
|
|||
/**
|
||||
* Close the overlay and remove markup related to it from the document.
|
||||
*/
|
||||
Drupal.overlay.close = function (args, statusMessages) {
|
||||
var self = this;
|
||||
|
||||
self.onOverlayCloseArgs = args;
|
||||
self.onOverlayCloseStatusMessages = statusMessages;
|
||||
|
||||
return self.$container.dialog('close');
|
||||
Drupal.overlay.close = function () {
|
||||
return this.$container.dialog('close');
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -59,17 +59,18 @@ function overlay_init() {
|
|||
// Only act if the user has access to administration pages. Other modules can
|
||||
// also enable the overlay directly for other uses of the JavaScript.
|
||||
if (user_access('access overlay')) {
|
||||
$current_path = current_path();
|
||||
// After overlay is enabled on the modules page, redirect to
|
||||
// <front>#overlay=admin/modules to actually enable the overlay.
|
||||
if (isset($_SESSION['overlay_enable_redirect']) && $_SESSION['overlay_enable_redirect']) {
|
||||
unset($_SESSION['overlay_enable_redirect']);
|
||||
drupal_goto('<front>', array('fragment' => 'overlay=' . current_path()));
|
||||
drupal_goto('<front>', array('fragment' => 'overlay=' . $current_path));
|
||||
}
|
||||
|
||||
if (isset($_GET['render']) && $_GET['render'] == 'overlay') {
|
||||
// If this page shouldn't be rendered here, redirect to the parent.
|
||||
if (!path_is_admin($_GET['q'])) {
|
||||
overlay_close_dialog();
|
||||
if (!path_is_admin($current_path)) {
|
||||
overlay_close_dialog($current_path);
|
||||
}
|
||||
// If system module did not switch the theme yet (i.e. this is not an
|
||||
// admin page, per se), we should switch the theme here.
|
||||
|
@ -85,7 +86,7 @@ function overlay_init() {
|
|||
unset($_GET['render']);
|
||||
}
|
||||
// Do not enable the overlay if we already are on an admin page.
|
||||
else if (!path_is_admin(current_path())) {
|
||||
else if (!path_is_admin($current_path)) {
|
||||
// Otherwise add overlay parent code and our behavior.
|
||||
overlay_set_mode('parent');
|
||||
}
|
||||
|
@ -337,31 +338,15 @@ function overlay_form_after_build($form, &$form_state) {
|
|||
* Generic form submit handler.
|
||||
*
|
||||
* When we are requested to close an overlay, we don't want Form API to
|
||||
* perform any redirection once the submitted form has been processed.
|
||||
*
|
||||
* When $form_state['redirect'] is set to FALSE, then Form API will simply
|
||||
* re-render the current page. This is all we need in order to output the
|
||||
* JavaScript that will tell the parent window to close the child dialog, so
|
||||
* we store a variable which will cause the page to be rendered by a delivery
|
||||
* callback function that does not actually print visible HTML, thereby
|
||||
* allowing the dialog to be closed faster and with less interruption.
|
||||
* perform any redirection once the submitted form has been processed. Instead,
|
||||
* we set $form_state['redirect'] to FALSE so that Form API will simply
|
||||
* re-render the current page, and pass the redirect information on to the
|
||||
* overlay JavaScript so that the redirection can be performed there.
|
||||
*
|
||||
* @see overlay_get_mode()
|
||||
* @see overlay_page_delivery_callback_alter()
|
||||
* @ingroup forms
|
||||
*/
|
||||
function overlay_form_submit($form, &$form_state) {
|
||||
$settings = &drupal_static(__FUNCTION__);
|
||||
|
||||
// Check if we have a request to close the overlay.
|
||||
$args = overlay_request_dialog_close();
|
||||
|
||||
// Close the overlay if the overlay module has been disabled
|
||||
if (!module_exists('overlay')) {
|
||||
$args = overlay_request_dialog_close(TRUE);
|
||||
}
|
||||
|
||||
// If there is a form redirect to a non-admin page, close the overlay.
|
||||
if (isset($form_state['redirect'])) {
|
||||
// A destination set in the URL trumps $form_state['redirect'].
|
||||
if (isset($_GET['destination'])) {
|
||||
|
@ -376,40 +361,30 @@ function overlay_form_submit($form, &$form_state) {
|
|||
$url = $form_state['redirect'];
|
||||
$url_settings = array();
|
||||
}
|
||||
if (!path_is_admin($url)) {
|
||||
$args = overlay_request_dialog_close(TRUE);
|
||||
// Close the overlay if we are redirecting to a non-admin page or if the
|
||||
// overlay module has just been disabled.
|
||||
if (!path_is_admin($url) || !module_exists('overlay')) {
|
||||
overlay_close_dialog($url, $url_settings);
|
||||
// Tell FAPI to stay on the same page after all submit callbacks have
|
||||
// been processed.
|
||||
$form_state['redirect'] = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// If the overlay is to be closed, pass that information through JavaScript.
|
||||
if ($args !== FALSE) {
|
||||
if (!isset($settings)) {
|
||||
$settings = array(
|
||||
'overlayChild' => array(
|
||||
'closeOverlay' => TRUE,
|
||||
'statusMessages' => theme('status_messages'),
|
||||
'args' => $args,
|
||||
),
|
||||
);
|
||||
// Tell the child window to perform the redirection when requested to.
|
||||
if (!empty($form_state['redirect'])) {
|
||||
$settings['overlayChild']['redirect'] = url($url, $settings);
|
||||
}
|
||||
drupal_add_js($settings, array('type' => 'setting'));
|
||||
}
|
||||
// Request that an empty page be displayed.
|
||||
overlay_display_empty_page(TRUE);
|
||||
// Tell FAPI to stay on the same page after all submit callbacks have been
|
||||
// processed.
|
||||
$form_state['redirect'] = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to request that the overlay display an empty page.
|
||||
*
|
||||
* This is used to prevent a submitted form which closes the overlay from being
|
||||
* fully re-rendered before the overlay is closed.
|
||||
* This is used to prevent a page request which closes the overlay (for
|
||||
* example, a form submission) from being fully re-rendered before the overlay
|
||||
* is closed. Instead, we store a variable which will cause the page to be
|
||||
* rendered by a delivery callback function that does not actually print
|
||||
* visible HTML (but rather only the bare minimum scripts and styles necessary
|
||||
* to trigger the overlay to close), thereby allowing the dialog to be closed
|
||||
* faster and with less interruption, and also allowing the display of messages
|
||||
* to be deferred to the parent window (rather than displaying them in the
|
||||
* child window, which will close before the user has had a chance to read
|
||||
* them).
|
||||
*
|
||||
* @param $value
|
||||
* By default, an empty page will not be displayed. Set to TRUE to request
|
||||
|
@ -418,6 +393,8 @@ function overlay_form_submit($form, &$form_state) {
|
|||
*
|
||||
* @return
|
||||
* TRUE if the current behavior is to display an empty page, or FALSE if not.
|
||||
*
|
||||
* @see overlay_page_delivery_callback_alter()
|
||||
*/
|
||||
function overlay_display_empty_page($value = NULL) {
|
||||
$display_empty_page = &drupal_static(__FUNCTION__, FALSE);
|
||||
|
@ -551,46 +528,33 @@ function overlay_overlay_child_initialize() {
|
|||
}
|
||||
|
||||
/**
|
||||
* Callback to request that the overlay close on the next page load.
|
||||
*
|
||||
* @param $value
|
||||
* By default, the dialog will not close. Set to TRUE or a value evaluating to
|
||||
* TRUE to request the dialog to close. Use FALSE to disable closing the
|
||||
* dialog (if it was previously enabled). The value passed will be forwarded
|
||||
* to the onOverlayClose callback of the overlay.
|
||||
*
|
||||
* @return
|
||||
* The current overlay close dialog mode, a value evaluating to TRUE if the
|
||||
* overlay should close or FALSE if it should not (default).
|
||||
*/
|
||||
function overlay_request_dialog_close($value = NULL) {
|
||||
$close = &drupal_static(__FUNCTION__, FALSE);
|
||||
if (isset($value)) {
|
||||
$close = $value;
|
||||
}
|
||||
return $close;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the overlay and redirect the parent window to a new path.
|
||||
* Callback to request that the overlay close as soon as the page is displayed.
|
||||
*
|
||||
* @param $redirect
|
||||
* The path that should open in the parent window after the overlay closes.
|
||||
* (optional) The path that should open in the parent window after the
|
||||
* overlay closes. If not set, no redirect will be performed on the parent
|
||||
* window.
|
||||
* @param $redirect_options
|
||||
* (optional) An associative array of options to use when generating the
|
||||
* redirect URL.
|
||||
*/
|
||||
function overlay_close_dialog($redirect = NULL) {
|
||||
if (!isset($redirect)) {
|
||||
$redirect = current_path();
|
||||
}
|
||||
function overlay_close_dialog($redirect = NULL, $redirect_options = array()) {
|
||||
$settings = array(
|
||||
'overlayChild' => array(
|
||||
'closeOverlay' => TRUE,
|
||||
'statusMessages' => theme('status_messages'),
|
||||
'args' => $args,
|
||||
'redirect' => url($redirect),
|
||||
),
|
||||
);
|
||||
|
||||
// Tell the child window to perform the redirection when requested to.
|
||||
if (isset($redirect)) {
|
||||
$settings['overlayChild']['redirect'] = url($redirect, $redirect_options);
|
||||
}
|
||||
|
||||
drupal_add_js($settings, array('type' => 'setting'));
|
||||
return $settings;
|
||||
|
||||
// Since we are closing the overlay as soon as the page is displayed, we do
|
||||
// not want to show any of the page's actual content.
|
||||
overlay_display_empty_page(TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue