You are here

function _addtoany_create_script in AddToAny Share Buttons 6.2

Same name and namespace in other branches
  1. 5.0 addtoany.module \_addtoany_create_script()
  2. 6.3 addtoany.module \_addtoany_create_script()
  3. 7.4 addtoany.module \_addtoany_create_script()
  4. 7 addtoany.module \_addtoany_create_script()
  5. 7.3 addtoany.module \_addtoany_create_script()

Internal function to create asynchronous load JavaScript after first button, and create the on-ready JS for footer.

Parameters

object $id_num:

object $link_name:

object $link_url:

Return value

String containing the asynchronous load JavaScript for the first button.

1 call to _addtoany_create_script()
_addtoany_create_button in ./addtoany.module
Internal function to generate code for AddToAny button

File

./addtoany.module, line 136
Standalone module file to handle AddToAny button integration

Code

function _addtoany_create_script($id_num, $link_name, $link_url) {
  global $_addtoany_script, $_addtoany_script_init;
  $_addtoany_script .= "a2a_config.linkname='" . check_plain($link_name) . "'; a2a_config.linkurl='" . check_plain($link_url) . "'; a2a.init('page', {target: '#da2a_" . $id_num . "'});\n";
  if (!$_addtoany_script_init) {
    $script_url = $_SERVER['HTTPS'] ? 'https://static.addtoany.com/menu/page.js' : 'http://static.addtoany.com/menu/page.js';
    $javascript_async = "<script type=\"text/javascript\">\n" . "function da2a_script_onready() { da2a_script_ready = true; if(da2a_html_ready) da2a_init(); }\n" . "var a2a_config = a2a_config || {}, da2a_html_ready = da2a_script_ready = false; a2a_config.tracking_callback = ['ready', da2a_script_onready];" . variable_get('addtoany_additional_js', '') . "\n(function(){var a = document.createElement('script');a.type = 'text/javascript';a.async = true;a.src = '" . $script_url . "';var s = document.getElementsByTagName('script')[0];s.parentNode.insertBefore(a, s);})();\n" . "</script>";
  }
  else {
    $javascript_async = "";
  }
  $_addtoany_script_init = TRUE;
  return $javascript_async;
}