array()); $js_added = drupal_add_js($data = NULL, 'setting'); if (is_array($options)) { foreach ($options as $beautytip => $content) { // Make sure the js settings are not added more than once if (is_array($js_added['setting'])) { foreach ($js_added['setting'] as $setting) { if (is_array($setting['beautytips'])) { if (array_key_exists($beautytip, $setting['beautytips'])) { unset($content); } } } } // Setup the settings array for adding js if (is_array($content)) { $settings['beautytips'][$beautytip] = $content; $get_keys = array_keys($content); $keys_no_add = array('cssSelect', 'list', 'text'); $count = 0; for ($i = 0; $i < count($content); $i++) { $key = $get_keys[$i]; if (!in_array($key, $keys_no_add)) { $settings['beautytips'][$beautytip]['list'][$count] = $key; $count++; } } } } if ($added && !empty($settings['beautytips'])) { drupal_add_js($settings, 'setting'); } } // Add beautytips jQuery plugin if (!$added) { $path = drupal_get_path('module', 'beautytips'); drupal_add_js($path .'/js/jquery.bt.min.js'); drupal_add_css($path .'/js/jquery.bt.css'); drupal_add_js($path .'/js/beautytips.js'); //for IE add this $expath = $path .'/other_libs/excanvas_r3'; if (count(file_scan_directory($expath, 'excanvas.js', array('.', '..', 'CVS'), 0, FALSE))) { drupal_add_js($expath .'/excanvas.js'); } // Set the defaults $settings['beautytips_defaults'] = variable_get('beautytips_defaults', array('cssStyles' => array())); $settings['beautytips_always_add'] = variable_get('beautytips_always_add', 0); $settings['beautytips_defaults']['list'] = array_keys($settings['beautytips_defaults']); if (isset($settings['beautytips_defaults']['cssStyles'])) { $settings['beautytips_defaults']['css_list'] = array_keys($settings['beautytips_defaults']['cssStyles']); } drupal_add_js( $settings, 'setting' ); $added = TRUE; } } /** * Implementation of hook_init(). * */ function beautytips_init() { if (variable_get('beautytips_always_add', 0)) { beautytips_add_beautytips(); } } /** * Implementation of hook_menu(). */ function beautytips_menu() { $items['admin/settings/beautytips'] = array( 'title' => 'BeautyTips', 'page callback' => 'drupal_get_form', 'page arguments' => array('beautytips_admin'), 'access arguments' => array('administer site configuration'), ); return $items; } /** * Menu callback - beautytips admin settings form */ function beautytips_admin() { $form['beautytips_always_add'] = array( '#title' => t('Add beautytips js to every page'), '#description' => t('This allows you to give the class \'beautytips\' to any element on a page and the title attribute will popup as a beautytip.'), '#type' => 'checkbox', '#default_value' => variable_get('beautytips_always_add', 0), ); if (module_exists('beautytips_ui')) { beautytips_ui_admin_settings($form); $form['#submit'][] = 'beautytips_ui_admin_submit'; } else { $form['#submit'][] = 'beautytips_admin_submit'; } return system_settings_form($form); } /** * Submit function for beautytips_admin form */ function beautytips_admin_submit($form, $form_state) { variable_set('beautytips_always_add', $form_state['values']['beautytips_always_add']); }