I am doing a modal dialog using ctools for the content analysis module. I have a problem that only happens in IE (if I had a nickel), works fine in FF and Crome. When the ctools modal loads the modal jumps to the top of the page, e.g. I have to scroll up to get back to it.
The modal dialog has two loading steps, one that launches the modal and loads the ctools content. Then the ctools content loads the content analysis content. The modal is correctly positioned when it first launches, then as soon as the ctools content loads it jumps up the page.
Here is my implementation code:
/**
* Returns Chaos Tools modal popup
*/
function contentanalysis_modal_popup() {
ctools_include('ajax');
ctools_include('modal');
$title = t('Content Analysis Results');
$html = contentanalysis_analyze();
$output[] = ctools_modal_command_display($title, $html);
if (!$output) {
$output = array();
$output[] = ctools_ajax_command_append('#modal-message', '<div id="message">test text</div>');
$output[] = ctools_modal_command_dismiss();
}
ctools_ajax_render($output);
}
/**
* Provides modal popup status bar
*/
function contentanalysis_analyze() {
return '<div id="analysis-modal">' . theme_progress_bar(0, 'Analyzing Content') . '</div>' . $output . '<script>contentanalysis_full_analysis();</script>';
}
I am using this to launch to modal:
$form['clickme'] = array(
'#type' => 'markup',
'#value' => '<div id="contentanalysis-buttons">' . l(t('Analyze content'), base_path() . 'contentanalysis/analyze_js', array('attributes' => array('id' => 'contentanalysis-ininline-analysis-button', 'class' => "contentanalysis-analyze-content contentanalysis-button", "onclick" => "contentanalysis_inline_analysis(); return (false);"))) . '</div>'
);
Any thoughts would be appreciated. Thanks,
Tom
Comments
Comment #1
merlinofchaos commentedHmm. I can't seem to make this happen under normal conditions using already existing modals.
Do you get this behavior when using page manager and editing a panel? I tried editing a panel and using the add content to see if I could get IE7 to do this, and it doesn't.
Perhaps there is something in the content you're sending that's doing this?
Comment #2
jameso4246 commentedI was experiencing the same issue and found the issue in modal.js. I also found that this issue can be duplicated by resizing the window in any browser and only it happens when you open a modal after scrolling down the page.
The cause is that initializing the modal takes in to account how far down the page you have scrolled whereas the modalContentResize function does not. It was happening in IE when the modal was being initialized because the event handler is defined differently for IE and the resize event was being called unnecessarily after init.
I have attached a patch, but if for some reason it doesn't work for you, the solution is to copy the code that sets the variable 'wt' from the modal init positioning section to the modalContentResize function and changing the following line
var mdcTop = ( winHeight / 2 ) - ( modalContent.outerHeight() / 2);to
var mdcTop = wt + ( winHeight / 2 ) - ( modalContent.outerHeight() / 2);Comment #3
rjbrown99 commentedPatch here, changing status.
Comment #4
zoo33 commentedI've seen this happening in Chrome on some pages, not others. Resizing the window always triggers the bug. I made an updated patch with some small changes (avoiding multiple var statements etc.).
Comment #6
eric.chenchao commentedThis issue also happens in Chrome, FF and it applies to 7.x-1.x.
The patch is applied to D7, should also work on D6.
Comment #7
acbramley commentedHad this issue with the Edit button on file fields using the media module widget. While there's still the weird issue where the modal appears to the right of the screen while it's loading, this patch did fix the problem of it being at the top of the screen after load.
Edit: Using 7.x-1.4 of ctools and patch applies cleanly
Comment #8
pivica commentedPatch from #6 works nicely - similar problem for FF and Chrome on modal resize (which happens on ajax load) it is jumping to the top of the page. This patch fix it.
Can we commit this?
Comment #9
joelstein commentedWorks for me.
Comment #10
japerryThis was fixed #2055785: Modal window top and left style values are incorrect after resizing