You are here

function sharethis_add_js in ShareThis 6

Same name and namespace in other branches
  1. 5 sharethis.module \sharethis_add_js()

Adds all required ShareThis JavaScript to the page.

2 calls to sharethis_add_js()
sharethis_link in ./sharethis.module
Implementation of hook_link().
theme_sharethis in ./sharethis.module
Themes the ShareThis options given.

File

./sharethis.module, line 124
Provides the ShareThis service.

Code

function sharethis_add_js() {

  // Be sure to add the ShareThis header code only once.
  static $sharethis_added = FALSE;
  if ($sharethis_added === FALSE) {

    // Adds the ShareThis jQuery plugin as well as the related Drupal JavaScript behavior and CSS.
    $path = drupal_get_path('module', 'sharethis');
    drupal_add_js($path . '/sharethis/jquery.sharethis.js');
    drupal_add_js($path . '/sharethis.js');

    // Add the ShareThis code if desired.
    $code = variable_get('sharethis_code', '');
    if (!empty($code)) {
      $code = str_replace('<script type="text/javascript" src="', '', $code);
      $code = str_replace('"></script>', '', $code);
      drupal_add_js(array(
        'sharethisUrl' => $code,
      ), 'setting');
    }

    // Flag that the JavaScript has been registered.
    $sharethis_added = TRUE;
  }
}