You are here

public function SharethisManager::sharethisIncludeJs in ShareThis 8.2

Include st js scripts.

Overrides SharethisManagerInterface::sharethisIncludeJs

File

src/SharethisManager.php, line 147

Class

SharethisManager
Defines an SharethisManager service.

Namespace

Drupal\sharethis

Code

public function sharethisIncludeJs() {
  $has_run = $this->sharethisJS;
  if (!$has_run) {

    // These are the ShareThis scripts:
    $data_options = $this
      ->getOptions();
    $st_js_options = [];
    $st_js_options['switchTo5x'] = $data_options['widget'] == 'st_multi' ? TRUE : FALSE;
    if ($data_options['late_load']) {
      $st_js_options['__st_loadLate'] = TRUE;
    }
    $st_js = '';
    foreach ($st_js_options as $name => $value) {
      $st_js .= 'var ' . $name . ' = ' . Json::decode($value) . ';';
    }
    $st_js = $this
      ->getShareThisLightOptions($data_options);
    $has_run = TRUE;
    $this->sharethisJS = $has_run;
    return $st_js;
  }
}