You are here

public function JuiceboxGallery::renderJavascript in Juicebox HTML5 Responsive Image Galleries 7.2

Get the javascript code for a Juicebox gallery once images and options have been added.

Parameters

string $xml_url: The URL to the Juicebox XML for this gallery.

boolean $add_script_tags: Whether-or-not to add <script> tags to wrap the output.

boolean $jquery_defer: Whether-or-not to defer the execution of the javascript until after the DOM is ready using jQuery(document).ready. This can be useful if the code will be included inline before the main Juicebox library. Requires that the jQuery library is already included.

Return value

string Javascript code describing a gallery.

Overrides JuiceboxGalleryInterface::renderJavascript

File

includes/JuiceboxGallery.inc, line 249
A php-only set of methods to create the script and markup components of a Juicebox gallery.

Class

JuiceboxGallery
Class to generate the script and markup for a Juicebox gallery.

Code

public function renderJavascript($xml_url, $add_script_tags = FALSE, $jquery_defer = FALSE) {

  // Get variable inputs for the juicebox object and represent them as a
  // string.
  $vars_json = json_encode($this
    ->getJavascriptVars($xml_url));

  // Set the Juicebox-specific code.
  $output = "new juicebox(" . $vars_json . ");";

  // Set wrappers.
  $script_wrap_prefix = $script_wrap_suffix = $inner_wrap_prefix = $inner_wrap_suffix = '';
  if ($add_script_tags) {
    $script_wrap_prefix = '<script type="text/javascript">' . "\n<!--//--><![CDATA[//><!--\n";
    $script_wrap_suffix = "\n//--><!]]>\n" . '</script>';
  }
  if ($jquery_defer) {
    $inner_wrap_prefix = 'jQuery(document).ready(function () {';
    $inner_wrap_suffix = '});';
  }
  return "\n" . $script_wrap_prefix . $inner_wrap_prefix . $output . $inner_wrap_suffix . $script_wrap_suffix . "\n";
}