diff -u b/js/misc/dialog.ajax.js b/js/misc/dialog.ajax.js --- b/js/misc/dialog.ajax.js +++ b/js/misc/dialog.ajax.js @@ -19,7 +19,7 @@ // dialogs. Non-modal dialogs are responsible for creating their own // elements, since there can be multiple non-modal dialogs at a time. if (!$('#drupal-modal').length) { - $(Drupal.theme.bootstrapModal()).appendTo('body'); + $('
').appendTo('body'); } // Special behaviors specific when attaching content within a dialog. @@ -66,6 +66,7 @@ */ prepareDialogButtons: function ($dialog) { var buttons = []; + $dialog.find('.form-actions').css({'height' : '0 !important', 'overflow':'hidden'}); var $buttons = $dialog.find('.form-actions :input[type=submit]'); $buttons.each(function () { // Hidden form buttons need special attention. For browser consistency, @@ -107,19 +108,14 @@ if (!response.selector) { return false; } - var $dialog = $(response.selector); if (!$dialog.length) { // Create the element if needed. - $dialog = $(Drupal.theme.bootstrapModal({ id: response.selector.replace(/^#/, '') })).appendTo('body'); + $dialog = $('
').appendTo('body'); } // Set up the wrapper, if there isn't one. - var id = $dialog.attr('id'); - if (response.selector === '#' + id) { - response.selector = '#' + id + '--body'; - } - else if (!ajax.wrapper) { - ajax.wrapper = id + '--body'; + if (!ajax.wrapper) { + ajax.wrapper = $dialog.attr('id'); } // Use the ajax.js insert command to populate the dialog contents. @@ -133,19 +129,10 @@ response.dialogOptions.buttons = Drupal.behaviors.dialog.prepareDialogButtons($dialog); } - response.dialogOptions = response.dialogOptions || {}; - - // Create the dialog object - var dialog = Drupal.dialog($dialog.get(0), response.dialogOptions); - - // Bind dialogButtonsChange. - $dialog.on('dialogButtonsChange', function () { - var buttons = Drupal.behaviors.dialog.prepareDialogButtons($dialog); - $dialog.modal('option', 'buttons', buttons); - dialog.createButtons($dialog, buttons); - }); // Open the dialog itself. + response.dialogOptions = response.dialogOptions || {}; + var dialog = Drupal.dialog($dialog.get(0), response.dialogOptions); if (response.dialogOptions.modal) { dialog.showModal(); } @@ -153,8 +140,14 @@ dialog.show(); } + // Bind dialogButtonsChange. + $dialog.closest('.modal').once('openDialog').on('dialogButtonsChange', function (e, $context) { + + var buttons = Drupal.behaviors.dialog.prepareDialogButtons($dialog); + Drupal.dialog($dialog).createButtons($dialog, buttons); + }); // 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'); }; /** @@ -172,12 +165,6 @@ var $dialog = $(response.selector); if ($dialog.length) { Drupal.dialog($dialog.get(0)).close(); - if (!response.persist) { - // Wrap this in a timer so animations can finish. - setTimeout(function() { - $dialog.remove(); - }, 1000); - } } // Unbind dialogButtonsChange. @@ -203,6 +190,7 @@ } }; + /** * Binds a listener on dialog before creation to setup title and buttons. * @@ -223,11 +211,6 @@ // Remove any existing buttons. $element.find('.modal-footer').remove(); - - // Add new buttons. - if (settings.buttons && settings.buttons.length) { - dialog.createButtons($element, settings.buttons); - } }); /** diff -u b/js/misc/dialog.js b/js/misc/dialog.js --- b/js/misc/dialog.js +++ b/js/misc/dialog.js @@ -60,91 +60,111 @@ * @return {Drupal.dialog~dialogDefinition} */ Drupal.dialog = function (element, options) { - var elementIsString = typeof element == 'string'; var $element = $(element); - if (elementIsString) { - $('body').append(Drupal.theme.bootstrapModal({'title': options.title || ''})); - } + var dialog = $element.data('drupalDialog') || { + open: false, + returnValue: void(0), + options: options, + show: function () { + alert('non-modal/movable dialog not yet supported.'); + }, + showModal: function () { + openDialog({show: true}); + }, + close: closeDialog, + createButtons: function($element, buttons) { + createButtons($element, buttons); + } + }; + options = $.extend(dialog.options, options); function openDialog(settings) { settings = $.extend({}, drupalSettings.dialog, options, settings); + + // Get the modal and add the content + var $modal = getModal(); + $modal.find('.modal-body').html($element); + + // Add new buttons. jQuery UI dialog widget handles this in core. + if (settings.buttons && settings.buttons.length) { + dialog.createButtons($element, settings.buttons); + } // Trigger a global event to allow scripts to bind events to the dialog. $(window).trigger('dialog:beforecreate', [dialog, $element, settings]); - $element - .modal(settings) - .on('shown.bs.modal.drupal', function () { + $modal + .modal(settings).once('bootstrapModal') + .on('shown.bs.modal.drupal', function (e) { dialog.open = true; $(window).trigger('dialog:aftercreate', [dialog, $element, settings]); }) - ; - } - - function closeDialog(value) { - $(window).trigger('dialog:beforeclose', [dialog, $element]); - $element - .on('hidden.bs.modal.drupal', function () { - dialog.returnValue = value; + .on('hide.bs.modal.drupal', function(e) { + $(window).trigger('dialog:beforeclose', [dialog, $element]); + }) + .on('hidden.bs.modal.drupal', function (e) { dialog.open = false; + settings.close(e); + $modal.find('.modal-body, .modal-footer-buttons').empty(); $(window).trigger('dialog:afterclose', [dialog, $element]); + $element.remove(); }) - .modal('hide'); + ; + } - if (elementIsString) { - window.setTimeout(function() { - $element.remove(); - }, 2000); - } + function closeDialog(value) { + getModal().on('hidden.bs.modal.drupal', function () { + dialog.returnValue = value; + }).modal('hide'); } function createButtons($element, buttons) { + console.log('create buttons'); buttons = buttons || options.buttons; + var $modal = getModal(); if (!buttons) { - $element.find('.modal-footer-buttons').remove(); - if ($el = $element.find('.modal-footer').is(':empty')) { + $modal.find('.modal-footer-buttons').remove(); + if ($el = $modal.find('.modal-footer').is(':empty')) { $el.remove(); } return; } - var $footer = $element.find('.modal-footer'); + var $footer = $modal.find('.modal-footer'); if (!$footer.length) { - $footer = $('