You are here

function sharethis_include_js in ShareThis 7.2

Include st js scripts.

3 calls to sharethis_include_js()
sharethis_block_contents in ./sharethis.module
Implements of sharethis_block_contents().
sharethis_handler_field_link::renderSharethisLink in views/sharethis_handler_field_link.inc
Renders sharethis link.
sharethis_node_view in ./sharethis.module
Implements hook_node_view().

File

./sharethis.module, line 385
A module that adds one of the ShareThis widget to your website.

Code

function sharethis_include_js() {
  $has_run =& drupal_static(__FUNCTION__, FALSE);
  if (!$has_run) {

    // These are the ShareThis scripts:
    $data_options = sharethis_get_options_array();
    $st_js_options = array();
    $st_js_options['switchTo5x'] = $data_options['widget'] == 'st_multi' ? TRUE : FALSE;
    if ($data_options['late_load']) {
      $st_js_options['__st_loadLate'] = TRUE;
    }
    if (isset($data_options['fastshare'])) {
      $st_js_options['useFastShare'] = $data_options['fastshare'];
    }
    $st_js = "";
    foreach ($st_js_options as $name => $value) {
      $st_js .= 'var ' . $name . ' = ' . drupal_json_encode($value) . ';';
    }
    drupal_add_js($st_js, 'inline');
    if (isset($_SERVER['HTTPS']) && drupal_strtolower($_SERVER['HTTPS']) == 'on' || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && drupal_strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https') {
      $external = "https://ws.sharethis.com/button/buttons.js";
    }
    else {
      $external = "http://w.sharethis.com/button/buttons.js";
    }
    drupal_add_js($external, 'external');
    $stlight = sharethis_get_light_options($data_options);
    $st_js = "if (typeof stLight !== 'undefined') { stLight.options({$stlight}); }";
    drupal_add_js($st_js, 'inline');
    $has_run = TRUE;
  }
  return $has_run;
}