Programatically attach cTools AJAX to Modal links

Public

How to programatically enable AJAX cTools links.

Get raw version
php
  1. /**
  2.   * Programatically enable all the AJAX ctools modal links.
  3.   */
  4. $('.ctools-use-modal:not(.ctools-use-modal-processed)').each(function(i, obj) {
  5. var url = $(obj).attr('href');
  6. // This is to pop up the modal as soon as the user clicks the element.
  7. $(obj).click(Drupal.CTools.Modal.clickAjaxLink);
  8.  
  9. var element_settings = {};
  10. element_settings.url = url;
  11. element_settings.event = 'click';
  12. element_settings.progress = { type: 'throbber' };
  13. var base = url;
  14. Drupal.ajax[base] = new Drupal.ajax(base, obj, element_settings);
  15. $(obj).addClass('ctools-use-modal-processed');
  16. });