public function JuiceboxGallery::renderJavascript in Juicebox HTML5 Responsive Image Galleries 8.2
Same name and namespace in other branches
- 8.3 src/JuiceboxGallery.php \Drupal\juicebox\JuiceboxGallery::renderJavascript()
Get javascript code for Juicebox gallery once images and options are added.
Parameters
string $xml_url: The URL to the Juicebox XML for this gallery.
bool $add_script_tags: Whether-or-not to add <script> tags to wrap the output.
bool $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
- src/
JuiceboxGallery.php, line 264
Class
- JuiceboxGallery
- Class to generate the script and markup for a Juicebox gallery.
Namespace
Drupal\juiceboxCode
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";
}