Hi there,
I try to open a modal from within an iframe.
with this:
...
<a href="#" onclick="parent.Drupal.open_upload_modal();" title="Save changes and continue">Open node add form</a>
How could I call the function "Drupal.modalFrame.open(modalOptions);"
I try to use a js file like that :
...
// $Id: automodal_upload.js,v 1.1.2.7 2009/12/28 02:21:20 Exp $
(function ($) {
Drupal.behaviors.automodalupload = function() {
// $('.modalframe-example-child:not(.modalframe-example-processed)').addClass('modalframe-example-processed').click(function() {
var element = this;
// This is our onSubmit callback that will be called from the child window
// when it is requested by a call to modalframe_close_dialog() performed
// from server-side submit handlers.
function onSubmitCallbackExample(args, statusMessages) {
// Display status messages generated during submit processing.
if (statusMessages) {
$('.modalframe-example-messages').hide().html(statusMessages).show('slow');
}
if (args && args.message) {
// Provide a simple feedback alert deferred a little.
setTimeout(function() { alert(args.message); }, 500);
}
}
// Hide the messages are before opening a new dialog.
$('.modalframe-example-messages').hide('fast');
//});
};
Drupal.open_upload_modal = function(){
pathArray = location.pathname.split('/');
var path = location.host + '/node/add/upload?gids[]=' + pathArray[3];
// Build modal frame options.
var modalOptions = {
url: $(path).attr('href'),
autoFit: true,
onSubmit: onSubmitCallbackExample
};
// Try to obtain the dialog size from the className of the element.
var regExp = /^.*modalframe-example-size\[\s*([0-9]*\s*,\s*[0-9]*)\s*\].*$/;
if (typeof element.className == 'string' && regExp.test(element.className)) {
var size = element.className.replace(regExp, '$1').split(',');
modalOptions.width = parseInt(size[0].replace(/ /g, ''));
modalOptions.height = parseInt(size[1].replace(/ /g, ''));
}
// Open the modal frame dialog.
Drupal.modalFrame.open(modalOptions);
// Prevent default action of the link click event.
//return false;
};
})(jQuery);
the "Drupal.open_upload_modal()" is called, but the modal isn't opening.. what I have to change?
Thanks Apfl007
Comments
Comment #1
markus_petrux commentedTry loading the javascript files in the iframe, and then invoke those.
jQuery does not work well crossing frames. It is best to invoke each method from its own DOM namespace.
ie. try making it work as if your page was not on a iframe.
This is bad:
This is better:
Comment #2
Apfel007 commentedhi markus,
thanx for your help. It got a modal, but something is missing - it's not closing.. child.js is loaded, parent.js is loaded.. what could be the cause? It seems that the submit handler isnot loaded..
Comment #3
markus_petrux commentedAttach your submit handler to $form['buttons']['#submit'] rather than $form['#submit']. The node edit form is a bit more complex than other forms. See node_form_submit_build_node() and how it is used in node.pages.inc.
$js_variables seems to be undefined.
Comment #4
dsnopekLooks like @markus_petrux handled all of his questions. Closing.