Index: js/mc.js =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/ctools/js/mc.js,v retrieving revision 1.3.2.1 diff -u -p -r1.3.2.1 mc.js --- js/mc.js 5 Oct 2009 23:38:33 -0000 1.3.2.1 +++ js/mc.js 10 Nov 2009 18:23:45 -0000 @@ -87,13 +87,11 @@ // Create our content div, get the dimensions, and hide it var modalContent = $('#modalContent').css('top','-1000px'); - var mdcTop = wt + ( winHeight / 2 ) - ( modalContent.outerHeight() / 2); - var mdcLeft = ( winWidth / 2 ) - ( modalContent.outerWidth() / 2); $('#modalBackdrop').css(css).css('top', 0).css('height', docHeight + 'px').css('width', docWidth + 'px').show(); - modalContent.css({top: mdcTop + 'px', left: mdcLeft + 'px'}).hide()[animation](speed); // Bind a click for closing the modalContent modalContentClose = function(){close(); return false;}; + modalContentResize = function() { Drupal.CTools.modal.centerModal(); }; $('.close').bind('click', modalContentClose); // Close the open modal content and backdrop @@ -117,25 +115,7 @@ $('#modalBackdrop').remove(); }; - // Move and resize the modalBackdrop and modalContent on resize of the window - modalContentResize = function(){ - // Get our heights - var docHeight = $(document).outerHeight(); - var docWidth = $(document).innerWidth(); - var winHeight = $(window).height(); - var winWidth = $(window).width(); - if( docHeight < winHeight ) docHeight = winHeight; - - // Get where we should move content to - var modalContent = $('#modalContent'); - var mdcTop = ( winHeight / 2 ) - ( modalContent.outerHeight() / 2); - var mdcLeft = ( winWidth / 2 ) - ( modalContent.outerWidth() / 2); - - // Apply the changes - $('#modalBackdrop').css('height', docHeight + 'px').css('width', docWidth + 'px').show(); - modalContent.css('top', mdcTop + 'px').css('left', mdcLeft + 'px').show(); - }; - $(window).bind('resize', modalContentResize); + $(window).bind('resize', Drupal.CTools.Modal.centerModal); $('#modalContent').focus(); }; @@ -157,7 +137,7 @@ if ( !speed ) var speed = 'fast'; // Unbind the events we bound - $(window).unbind('resize', modalContentResize); + $(window).unbind('resize', Drupal.CTools.centerModal); $('body').unbind('focus', modalEventHandler); $('body').unbind('keypress', modalEventHandler); $('.close').unbind('click', modalContentClose); @@ -175,4 +155,42 @@ } }); }; + + /** + * Center the modal in the Viewport + */ + Drupal.CTools.Modal.centerModal = function() { + var modalContent = $('#modalContent'); + // Get the document height & width. + var docHeight = $(document).outerHeight() + 50; + var docWidth = $(document).innerWidth(); + + // position code lifted from http://www.quirksmode.org/viewport/compatibility.html + if (self.pageYOffset) { // all except Explorer + var wt = self.pageYOffset; + } else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict + var wt = document.documentElement.scrollTop; + } else if (document.body) { // all other Explorers + var wt = document.body.scrollTop; + } + + // Get the window height & width. + var winHeight = $(window).innerHeight(); + var winWidth = $(window).innerWidth(); + + // Before getting modal height & width, we need to move modal to top left so that the values are as accurate as possible. + // This is especially needed when the modal content is very wide and fills up most of the available screen width. + modalContent.css('visibility', 'hidden'); + modalContent.css('top', '15px').css('left', '15px'); + var mdcTop = wt + (winHeight / 2) - (modalContent.height() / 2); + var mdcLeft = (winWidth / 2) - (modalContent.width() / 2); + + // If popup is taller or wider than viewable area, snap popup to top or left of viewable area - adding 15px padding. + (mdcTop < (15 + wt)) ? mdcTop = wt + 15 : null; + (mdcLeft < 15) ? mdcLeft = 15 : null; + + // Apply the changes. + $('#modalBackdrop').css('height', docHeight + 'px').css('width', docWidth + 'px').css('opacity', '0.55').show(); + modalContent.css('top', mdcTop + 'px').css('left', mdcLeft + 'px').css('visibility', 'visible').show(); + } })(jQuery); Index: js/modal.js =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/ctools/js/modal.js,v retrieving revision 1.17.2.3 diff -u -p -r1.17.2.3 modal.js --- js/modal.js 27 Oct 2009 22:51:05 -0000 1.17.2.3 +++ js/modal.js 10 Nov 2009 18:23:45 -0000 @@ -18,26 +18,11 @@ * Display the modal */ Drupal.CTools.Modal.show = function() { - var resize = function(e) { - // For reasons I do not understand, when creating the modal the context must be - // Drupal.CTools.Modal.modal but otherwise the context must be more than that. - var context = e ? document : Drupal.CTools.Modal.modal; - $('div.ctools-modal-content', context).css({ - 'width': $(window).width() * .8 + 'px', - 'height': $(window).height() * .8 + 'px' - }); - $('div.ctools-modal-content .modal-content', context).css({ - 'width': ($(window).width() * .8 - 25) + 'px', - 'height': ($(window).height() * .8 - 35) + 'px' - }); - } - if (!Drupal.CTools.Modal.modal) { Drupal.CTools.Modal.modal = $(Drupal.theme('CToolsModalDialog')); - $(window).bind('resize', resize); + $(window).bind('resize', Drupal.CTools.Modal.centerModal); } - - resize(); + $('span.modal-title', Drupal.CTools.Modal.modal).html(Drupal.t('Loading...')); var opts = { // @todo this should be elsewhere. @@ -46,7 +31,9 @@ }; Drupal.CTools.Modal.modalContent(Drupal.CTools.Modal.modal, opts); - $('#modalContent .modal-content').html(Drupal.theme('CToolsModalThrobber')); + + // AJAX commands expect object, but in this case, it expects an empty object + Drupal.CTools.AJAX.commands.modal_loading(); }; /** @@ -233,6 +220,11 @@ Drupal.CTools.AJAX.commands.modal_display = function(command) { $('#modal-title').html(command.title); $('#modal-content').html(command.output); + + // Center the modal in the viewport. + Drupal.CTools.Modal.centerModal(); + + // Attach the behaviors to the new content. Drupal.attachBehaviors($('#modal-content')); }