views:

114

answers:

1

I'm creating a site using drupal where I'd like to prompt my new users to create their profiles on the first login after they register.

To do this I'm using ModalFrame API. What I've done so far is create a special role for users 'first timers' which they are assigned once they register on my site.

I check in my code for the 'first timer' role assignment and use the ModalFrame API to pop up a modal dialog. My intent is to assign a different role once the user completes their profile.

Because, I'd like this dialog to popup without user interaction I'm using the ready event in my jquery code.

Drupal.behaviors.modalFrameRegister = function(context) {
  $('a.modalframe-register:not(.modalframe-register-processed)', context)

    // Now that we have matched an element, we add a CSS class, so that
    // we do not process the same element more than once.
    .addClass('modalframe-register-processed')

    .ready(Drupal.modalFrameRegister.loadURL)
};

**
 * Ready event handler.
 */
Drupal.modalFrameRegister.loadURL = function() {
  // Define the onSubmit callback for the Modal Frame.
  var onSubmitCallback = function(args) {
    if (args.redirect) {
      // Redirect to specified destination.
      setTimeout(function() { window.location = args.redirect; }, 1);
    }
    else {
       // Refresh the page after closing the modal window.
      location.reload();
    }
  };

  // The URL of the same link will be opened within a modal frame.
  Drupal.modalFrame.open({
    url: <my popup form>,
    width: 515,
    height: 700,
    onSubmit: onSubmitCallback
  });

  // Return false so that we cancel the default link behavior.
  return false;
};

I've noticed that this works well in principle but it seems that the ready event handler is passed through each subsequent iframe so when the modal frame comes up, it recursively loads additional modal frames within each one.

My question is what's the best way to prevent this recursive behavior?

A: 

insert this before the ready handler.

// set the ready handler only for the parent frame
if (window.location == window.parent.location)
    $('body', context).ready(Drupal.modalFrameRegister.loadURL);
Rasputin Jones