// $Id: parent.js,v 1.1.2.24 2010/04/16 18:11:25 markuspetrux Exp $ (function ($) { /** * Modal Frame object for parent windows. */ Drupal.modalFrame = Drupal.modalFrame || { dirtyFormsWarning: Drupal.t('Your changes will be lost if you close this popup now.'), options: {}, iframe: { $container: null, $element: null }, isOpen: false, // Flag that tells us if we have a child document loaded. Our window resize // handler will ignore events while no child document is loaded. isChildLoaded: false, // Flag used to control if we have already installed our custom // event handlers to the parent window. parentReady: false, // Provide a unique namespace for event handlers managed by this // Modal Frame instance. uniqueName: 'modalframe-'+ ((new Date()).getTime()) }; /** * Provide a unique name for an event handler. */ Drupal.modalFrame.eventHandlerName = function(name) { var self = this; return name +'.'+ self.uniqueName; }; /** * Open a modal frame. * * Ensure that only one modal frame is opened ever. Use Drupal.modalFrame.load() * if the modal frame is already open but a new page needs to be loaded. * * @param options * Properties of the modal frame to open: * - url: the URL of the page to open in the modal frame. * - width: width of the modal frame in pixels. * - height: height of the modal frame in pixels. * - autoFit: boolean indicating whether the modal frame should be resized to * fit the contents of the document loaded. * - onOpen: callback to invoke when the modal frame is opened. * - onLoad: callback to invoke when the child document in the modal frame is * fully loaded. * - onSubmit: callback to invoke when the modal frame is closed. * @todo: We could rename onSubmit to onClose, however we would be breaking * other modules that rely on it. Maybe when doing a formal port to D7? * - customDialogOptions: an object with custom jQuery UI Dialog options. * * @return * If the modal frame was opened true, otherwise false. */ Drupal.modalFrame.open = function(options) { var self = this; // Just one modal is allowed. if (self.isOpen || $('#modalframe-container').size()) { return false; } // Make sure the modal frame is not resized until a child document is loaded. self.isChildLoaded = false; // If not ready yet, install custom event handlers to the parent window // for proper communication with the child window. if (!self.parentReady) { // Install a custom event handler to allow child windows to tell us they // have just loaded a document. $(window).bind(self.eventHandlerName('childLoad'), function(event, iFrameWindow, isClosing) { self.bindChild(iFrameWindow, isClosing); }); // Install a custom event handler to allow child windows to tell us they // are unloading the document. $(window).bind(self.eventHandlerName('childUnload'), function(event, iFrameWindow) { self.unbindChild(iFrameWindow); }); // Install a custom event handler to allow child windows to tell us they // want to close the Modal Frame. $(window).bind(self.eventHandlerName('childClose'), function(event, args, statusMessages) { self.close(args, statusMessages); }); // Ok, so we're ready to properly communicate with child windows. self.parentReady = true; } // For some reason, onblur events attached by the Drupal autocomplete // behavior do not fire after a Modal Frame has been closed. I spent a lot // of time trying to figure out the cause, but I've been unable to. :( // Anyway, here's a temporary fix that makes sure the autocomplete popup // is hidden as soon as the user selects a candidate. I'm not enterily // happy with this solution, but it seems to solve the problem for now. // Please, see the following issue: http://drupal.org/node/635754 if (Drupal.jsAC && !Drupal.jsAC.prototype.modalFrameSelect) { Drupal.jsAC.prototype.modalFrameSelect = Drupal.jsAC.prototype.select; Drupal.jsAC.prototype.select = function(node) { this.modalFrameSelect(node); this.hidePopup(); }; } // Build the modal frame options structure. self.options = { url: options.url, width: options.width, height: options.height, autoFit: (options.autoFit == undefined || options.autoFit), draggable: (options.draggable == undefined || options.draggable), onOpen: options.onOpen, onLoad: options.onLoad, onSubmit: options.onSubmit, customDialogOptions: options.customDialogOptions }; // Create the dialog and related DOM elements. self.create(); // Open the dialog offscreen where we can set its size, etc. self.iframe.$container.dialog('option', {position: ['-999em', '-999em']}).dialog('open'); return true; }; /** * Create the modal dialog. */ Drupal.modalFrame.create = function() { var self = this; // Note: We use scrolling="yes" for IE as a workaround to yet another IE bug // where the horizontal scrollbar is always rendered, no matter how wide the // iframe element is defined. IE also requires a few more non-std properties. self.iframe.$element = $('