You are here

function addthis_add_default_js in AddThis 6.3

Load the addthis_widget.js and the configured AddThis defaults.

3 calls to addthis_add_default_js()
addthis_footer in ./addthis.module
Implements hook_footer().
theme_addthis_button in ./addthis.module
Theme function to render an AddThis button.
theme_addthis_toolbox_item in ./addthis.module
Theme function to render an individual toolbox item. This is often, but not necessarily, in the context of an AddThis toolbox.

File

./addthis.module, line 298
Provides integration with the AddThis.com bookmarking & sharing service.

Code

function addthis_add_default_js($footer = FALSE) {
  static $addthis_counter = 0;

  // See if we've done this before.
  if ($footer == TRUE || $addthis_counter++ > 0) {
    return $addthis_counter;
  }

  // Get the base configuration settings array.
  $config = variable_get('addthis_config', array(
    'ui_use_css' => TRUE,
    'data_use_cookies' => TRUE,
  ));

  // If no pubid is given, use an anonymous pubid provided by AddThis.
  // The "email" service code doesn't work if this is not set to something.
  if (empty($config['pubid'])) {
    $config['pubid'] = 'xa-4e2cfd1147868c4e';
  }

  // Determine the current language context and add it to $settings.
  global $language;
  $config['ui_language'] = $language->language;

  // AddThis seems to be fairly strict about variable typing.
  $config['ui_use_css'] = (bool) $config['ui_use_css'];
  $config['data_use_cookies'] = (bool) $config['data_use_cookies'];

  // Not sure if this is still necessary.
  $config['data_use_flash'] = $config['data_use_cookies'];

  // Get any configured share templates.
  $share = array();
  $share['templates']['twitter'] = variable_get('addthis_templates_twitter', '');

  // Add the settings array to the page and process it for the AddThis script.
  $settings = array(
    'addthis' => array(
      'config_default' => $config,
      'share_default' => $share,
    ),
  );
  _addthis_check_plain($settings);
  drupal_add_js($settings, 'setting');
  drupal_add_js('addthis_config = Drupal.settings.addthis.config_default; addthis_share = Drupal.settings.addthis.share_default;', 'inline');
  return $addthis_counter;
}