Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions libraries/joomla/document/document.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ class JDocument
*/
public $_script = array();

/**
* Array of scripts options
*
* @var array
*/
public $_script_options = array();

/**
* Array of linked style sheets
*
Expand Down Expand Up @@ -526,6 +533,40 @@ public function addScriptDeclaration($content, $type = 'text/javascript')
return $this;
}

/**
* Add option for script
*
* @param string $name a full extension name e.g. plg_name, com_name
* @param array $options - scrip options as array
*
* @return JDocument instance of $this to allow chaining
*
*/
public function setScriptOptions($options, $name)
{
$this->_script_options[$name] = $options;
return $this;
}

/**
* Get script(s) options
*
* @param string $name a full extension name e.g. plg_name, com_name
*
* @return array that contain optios for script/extension by name or all options
*
*/
public function getScriptOptions($name = null)
{
if ($name)
{
return (empty($this->_script_options[$name])) ? array() : $this->_script_options[$name];
}
else {
return $this->_script_options;
}
}

/**
* Adds a linked stylesheet to the page
*
Expand Down
19 changes: 19 additions & 0 deletions libraries/joomla/document/html/renderer/head.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public function fetchHead($document)
$app = JFactory::getApplication();
$app->triggerEvent('onBeforeCompileHead');

// Whether debug enabled
$debug = JFactory::getConfig()->get('debug');

// Get line endings
$lnEnd = $document->_getLineEnd();
$tab = $document->_getTab();
Expand Down Expand Up @@ -195,6 +198,22 @@ public function fetchHead($document)
$buffer .= '></script>' . $lnEnd;
}

// Generate scripts options
if (!empty($document->_script_options))
{
$buffer .= $tab . '<script type="text/javascript">' . $lnEnd;
//TODO: use .extend(Joomla.optionsStorage, options)
//when it will be safe
$buffer .= $tab . 'var Joomla = Joomla || {};' . $lnEnd;
$buffer .= $tab . 'Joomla.optionsStorage = '
. json_encode(
$document->_script_options,
($debug && defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : false)
)
. ';' . $lnEnd;
$buffer .= $tab . '</script>' . $lnEnd;
}

// Generate script declarations
foreach ($document->_script as $type => $content)
{
Expand Down