Skip to content

Commit

Permalink
Merge branch 'core-getoptions' into jtext-noscript
Browse files Browse the repository at this point in the history
  • Loading branch information
Fedik committed Aug 21, 2016
2 parents f582a93 + be7c703 commit b498871
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 19 deletions.
26 changes: 8 additions & 18 deletions libraries/joomla/document/renderer/html/head.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public function fetchHead($document)
$document->_metaTags['name']['tags'] = implode(', ', $tagsHelper->getTagNames($document->_metaTags['name']['tags']));
}

if ($document->getScriptOptions())
{
JHtml::_('behavior.core');
}

// Trigger the onBeforeCompileHead event
$app = JFactory::getApplication();
$app->triggerEvent('onBeforeCompileHead');
Expand Down Expand Up @@ -224,29 +229,14 @@ public function fetchHead($document)

if (!empty($scriptOptions))
{
$buffer .= $tab . '<script type="text/javascript">' . $lnEnd;

// This is for full XHTML support.
if ($document->_mime != 'text/html')
{
$buffer .= $tab . $tab . '//<![CDATA[' . $lnEnd;
}
$buffer .= $tab . '<script type="application/json" id="joomla-script-options">';

$pretyPrint = (JDEBUG && defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : false);
$jsonOptions = json_encode($scriptOptions, $pretyPrint);
$jsonOptions = $jsonOptions ? $jsonOptions : '{}';

// TODO: use .extend(Joomla.optionsStorage, options) when it will be safe
$buffer .= $tab . 'var Joomla = Joomla || {};' . $lnEnd;
$buffer .= $tab . 'Joomla.optionsStorage = ' . $jsonOptions . ';' . $lnEnd;

// See above note
if ($document->_mime != 'text/html')
{
$buffer .= $tab . $tab . '//]]>' . $lnEnd;
}

$buffer .= $tab . '</script>' . $lnEnd;
$buffer .= $jsonOptions;
$buffer .= '</script>' . $lnEnd;
}

// Generate script declarations
Expand Down
33 changes: 33 additions & 0 deletions media/system/js/core-uncompressed.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,39 @@ Joomla.editors.instances = Joomla.editors.instances || {};
}
};

/**
* Joomla options storage
*
* @type {{}}
*
* @since __DEPLOY_VERSION__
*/
Joomla.optionsStorage = Joomla.optionsStorage || null;

/**
* Get script(s) options
*
* @param {String} key Name in Storage
* @param mixed def Default value if nothing found
*
* @return mixed
*
* @since __DEPLOY_VERSION__
*/
Joomla.getOptions = function( key, def) {

// Load options if they not exists
if (!Joomla.optionsStorage) {
var element = document.getElementById('joomla-script-options'),
str = element ? (element.text || element.textContent) : null,
options = str ? JSON.parse(str) : null;

Joomla.optionsStorage = options || {};
}

return Joomla.optionsStorage[key] || def;
};

/**
* Method to replace all request tokens on the page with a new one.
* Used in Joomla Installation
Expand Down
2 changes: 1 addition & 1 deletion media/system/js/core.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b498871

Please sign in to comment.