You are here

function _easy_social_add_js in Easy Social 8.4

Same name and namespace in other branches
  1. 8.3 easy_social.module \_easy_social_add_js()

Helper function that adds javscript includes for widgets asynchronously.

@TODO this assumes script are external and might break if otherwise.

Parameters

array: The variables passed to the theme function.

string: Any extra markup to append to the script tag. This is used by some widgets to pass extra configuration.

See also

theme_easy_social()

File

./easy_social.module, line 483
Easy Social module.

Code

function _easy_social_add_js($variables, $extra = '') {
  $script = <<<JS
(function() {
  !x
})();
JS;
  $includes = '';
  foreach ($variables as $var) {
    $url = $var['data'];
    $includes .= <<<EOT
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = '{<span class="php-variable">$url</span>}'; {<span class="php-variable">$extra</span>}
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
EOT;
  }
  $script = str_replace('!x', $includes, $script);

  // drupal_add_js($script, 'inline');
}