You are here

function dialog_add_js in Dialog 6

Add all the necessary javascript (and css) to be able to display a dialog on the current page. This must be used on any page that could possibly contain a dialog. It is safe to call this function repeatedly.

3 calls to dialog_add_js()
dialog_comment_link_alter in modules/dialog_comment/dialog_comment.module
Implementation of hook_link_alter().
dialog_example_page in example/dialog_example.module
dialog_user_block in modules/dialog_user/dialog_user.module
Implementation of hook_block().

File

./dialog.module, line 38

Code

function dialog_add_js() {

  // Provide a gate so we only do this once.
  static $done = FALSE;
  if ($done) {
    return;
  }

  // Include CTools ajax so it can preprocess the page's CSS and JS. Helps avoid
  // issues with cache clears.
  ctools_include('ajax');
  $settings = array(
    'Dialog' => array(
      'throbber' => theme('image', ctools_image_path('throbber.gif'), t('Loading...'), t('Loading')),
      'height' => variable_get('dialog_default_height', 'auto'),
      'width' => variable_get('dialog_default_width', '600px'),
    ),
  );
  drupal_add_js($settings, 'setting');
  drupal_add_js('misc/jquery.form.js');
  ctools_add_js('ajax-responder');

  // Add jquery_ui js and css.
  jquery_ui_add(array(
    'ui.core',
    'ui.resizable',
    'ui.draggable',
    'ui.dialog',
  ));

  // Get the correct CSS path based on jQuery UI version.
  $version_16 = version_compare(jquery_ui_get_version(), '1.7.0', '<');
  $css_path = $version_16 ? 'default' : 'base';
  drupal_add_css(JQUERY_UI_PATH . '/themes/' . $css_path . '/ui.all.css');

  // And finally, the dialog js.
  drupal_add_js(drupal_get_path('module', 'dialog') . '/dialog.js');

  // Close the gate.
  $done = TRUE;
}