diff --git a/libraries/joomla/document/document.php b/libraries/joomla/document/document.php index fe4af66dc82d5..e06cd054b7d2e 100644 --- a/libraries/joomla/document/document.php +++ b/libraries/joomla/document/document.php @@ -143,6 +143,13 @@ class JDocument */ public $_script = array(); + /** + * Array of scripts options + * + * @var array + */ + protected $scriptOptions = array(); + /** * Array of linked style sheets * @@ -514,6 +521,57 @@ public function addScriptDeclaration($content, $type = 'text/javascript') return $this; } + /** + * Add option for script + * + * @param string $key Name in Storage + * @param mixed $options Scrip options as array or string + * @param bool $merge Whether merge with existing (true) or replace (false) + * + * @return JDocument instance of $this to allow chaining + * + * @since 3.5 + */ + public function addScriptOptions($key, $options, $merge = true) + { + if (empty($this->scriptOptions[$key])) + { + $this->scriptOptions[$key] = array(); + } + + if ($merge && is_array($options)) + { + $this->scriptOptions[$key] = array_merge($this->scriptOptions[$key], $options); + } + else + { + $this->scriptOptions[$key] = $options; + } + + return $this; + } + + /** + * Get script(s) options + * + * @param string $key Name in Storage + * + * @return array Options for given $key, or all script options + * + * @since 3.5 + */ + public function getScriptOptions($key = null) + { + if ($key) + { + return (empty($this->scriptOptions[$key])) ? array() : $this->scriptOptions[$key]; + } + else + { + return $this->scriptOptions; + } + } + /** * Adds a linked stylesheet to the page * diff --git a/libraries/joomla/document/renderer/html/head.php b/libraries/joomla/document/renderer/html/head.php index dda6fe2dd6e8b..9dc776de9eb3f 100644 --- a/libraries/joomla/document/renderer/html/head.php +++ b/libraries/joomla/document/renderer/html/head.php @@ -201,6 +201,36 @@ public function fetchHead($document) $buffer .= '>' . $lnEnd; } + // Generate scripts options + $scriptOptions = $document->getScriptOptions(); + + if (!empty($scriptOptions)) + { + $buffer .= $tab . '' . $lnEnd; + } + // Generate script declarations foreach ($document->_script as $type => $content) {