Hi,

I am using ctools_automodal to generate the ctools modal popup.
I want to display the modal popup on page load.
Can anyone suggest me how to do this?

Thanks

Comments

merlinofchaos’s picture

Status: Active » Fixed

You'd probably need to use jQuery ready function and call Drupal.CTools.Modal.show() and then fill in the data you want from the modal. You could also simulate a click on a link that loads a modal via AJAX using jQuery's trigger() method.

jaykainthola’s picture

@merlinofchaos

Thanks for your comment. I have explored the Ctools and ajax and resolved the problem.

/**
 * @file
 * Display the popup on page load
 */

(function($) {
  /**
   * Add an extra function to the Drupal ajax object which allows us to trigger
   * an ajax response without an element that triggers it.
   */
  Drupal.ajax.prototype.goalspopup = function() {
    var ajax = this;

    // Do not perform another ajax command if one is already in progress.
    if (ajax.ajaxing) {
      return false;
    }

    try {
      $.ajax(ajax.options);
    } catch (err) {
      //alert('An error occurred while attempting to process ' + ajax.options.url);
      return false;
    }

    return false;
  };

  Drupal.behaviors.podium_goals_popup = {
    attach : function(context) {

     /**
     * Define a custom ajax action not associated with an element.
     */
      $(document).ready(function() {
        if (Drupal.settings.podium_goals_popup.url != '') {
          Drupal.ajax[$('.goals-popup a.ctools-use-modal').attr('href')].goalspopup();          
        }        
      });
    }
  };
})(jQuery);
jaykainthola’s picture

@merlinofchaos
Thanks for your comment. I have resolved the issue by using following code.

 Drupal.ajax[$('.goals-popup a.ctools-use-modal').attr('href')].goalspopup();         

$('.goals-popup a.ctools-use-modal') is the ctools modal link and I created a new function as.

Drupal.ajax.prototype.goalspopup = function() {
    var ajax = this;

    // Do not perform another ajax command if one is already in progress.
    if (ajax.ajaxing) {
      return false;
    }

    try {
      $.ajax(ajax.options);
    } catch (err) {
      //alert('An error occurred while attempting to process ' + ajax.options.url);
      return false;
    }

    return false;
  };

its working fine for me.

jaykainthola’s picture

Status: Fixed » Closed (fixed)