From b33d98227c3c0fba0c53dc06aababe61aaedf486 Mon Sep 17 00:00:00 2001 From: Fedik Date: Sat, 15 Jun 2013 14:15:23 +0300 Subject: [PATCH 1/8] set/get script options --- libraries/joomla/document/document.php | 41 ++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/libraries/joomla/document/document.php b/libraries/joomla/document/document.php index 23db4618f0162..c3dcea7315581 100644 --- a/libraries/joomla/document/document.php +++ b/libraries/joomla/document/document.php @@ -147,6 +147,13 @@ class JDocument */ public $_script = array(); + /** + * Array of scripts options + * + * @var array + */ + public $_scripts_otions = array(); + /** * Array of linked style sheets * @@ -481,6 +488,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->_scripts_otions[$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->_scripts_otions[$name])) ? array() : $this->_scripts_otions[$name]; + } + else { + return $this->_scripts_otions; + } + } + /** * Adds a linked stylesheet to the page * From b8208223f70594b58509eebc55418d5ad3147c9d Mon Sep 17 00:00:00 2001 From: Fedik Date: Sat, 15 Jun 2013 14:20:39 +0300 Subject: [PATCH 2/8] render script options --- libraries/joomla/document/html/renderer/head.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libraries/joomla/document/html/renderer/head.php b/libraries/joomla/document/html/renderer/head.php index f397687986b60..74a1c18e1706d 100644 --- a/libraries/joomla/document/html/renderer/head.php +++ b/libraries/joomla/document/html/renderer/head.php @@ -180,6 +180,15 @@ public function fetchHead($document) $buffer .= '>' . $lnEnd; } + //render scripts options + if (!empty($document->_scripts_otions)) + { + $buffer .= $tab . '' . $lnEnd; + } + // Generate script declarations foreach ($document->_script as $type => $content) { From ab4e87dd353bad27ea97459420bacba4726fba33 Mon Sep 17 00:00:00 2001 From: Fedik Date: Sat, 15 Jun 2013 14:29:38 +0300 Subject: [PATCH 3/8] rename to JoptionsStorage --- libraries/joomla/document/html/renderer/head.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/joomla/document/html/renderer/head.php b/libraries/joomla/document/html/renderer/head.php index 74a1c18e1706d..a474c52d3e042 100644 --- a/libraries/joomla/document/html/renderer/head.php +++ b/libraries/joomla/document/html/renderer/head.php @@ -184,8 +184,9 @@ public function fetchHead($document) if (!empty($document->_scripts_otions)) { $buffer .= $tab . '' . $lnEnd; } From 2bb8da3077c53c24750b9f7f068ffa8ad7129a7a Mon Sep 17 00:00:00 2001 From: Fedik Date: Fri, 21 Jun 2013 19:51:18 +0300 Subject: [PATCH 4/8] use Joomla.optionsStorage --- libraries/joomla/document/html/renderer/head.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libraries/joomla/document/html/renderer/head.php b/libraries/joomla/document/html/renderer/head.php index a474c52d3e042..f9aa9aa05dbf9 100644 --- a/libraries/joomla/document/html/renderer/head.php +++ b/libraries/joomla/document/html/renderer/head.php @@ -180,13 +180,14 @@ public function fetchHead($document) $buffer .= '>' . $lnEnd; } - //render scripts options + // Generate scripts options if (!empty($document->_scripts_otions)) { $buffer .= $tab . '' . $lnEnd; } From 1ea535cefbc16f72a6b0f32549bf3c1da3294557 Mon Sep 17 00:00:00 2001 From: Fedik Date: Sat, 22 Jun 2013 19:59:52 +0300 Subject: [PATCH 5/8] use JSON_PRETtY_PRINT when debug enabled --- libraries/joomla/document/html/renderer/head.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libraries/joomla/document/html/renderer/head.php b/libraries/joomla/document/html/renderer/head.php index f9aa9aa05dbf9..2c3fce5d6b471 100644 --- a/libraries/joomla/document/html/renderer/head.php +++ b/libraries/joomla/document/html/renderer/head.php @@ -63,6 +63,9 @@ public function fetchHead($document) $app = JFactory::getApplication(); $app->triggerEvent('onBeforeCompileHead'); + // Wheather debug enabled + $debug = JFactory::getConfig()->get('debug'); + // Get line endings $lnEnd = $document->_getLineEnd(); $tab = $document->_getTab(); @@ -187,7 +190,12 @@ public function fetchHead($document) //TODO: use .extend(Joomla.optionsStorage, options) //when it will be safe $buffer .= $tab . 'var Joomla = Joomla || {};' . $lnEnd; - $buffer .= $tab . 'Joomla.optionsStorage = ' . json_encode($document->_scripts_otions) . ';' . $lnEnd; + $buffer .= $tab . 'Joomla.optionsStorage = ' + . json_encode( + $document->_scripts_otions, + ($debug && defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : false) + ) + . ';' . $lnEnd; $buffer .= $tab . '' . $lnEnd; } From 8f664daff90956fd1652965cdebeea4c9979d953 Mon Sep 17 00:00:00 2001 From: Fedik Date: Sat, 22 Jun 2013 20:03:51 +0300 Subject: [PATCH 6/8] fix typo _scripts_options => _script_options --- libraries/joomla/document/document.php | 8 ++++---- libraries/joomla/document/html/renderer/head.php | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/joomla/document/document.php b/libraries/joomla/document/document.php index c3dcea7315581..b2094391d034a 100644 --- a/libraries/joomla/document/document.php +++ b/libraries/joomla/document/document.php @@ -152,7 +152,7 @@ class JDocument * * @var array */ - public $_scripts_otions = array(); + public $_script_otions = array(); /** * Array of linked style sheets @@ -499,7 +499,7 @@ public function addScriptDeclaration($content, $type = 'text/javascript') */ public function setScriptOptions($options, $name) { - $this->_scripts_otions[$name] = $options; + $this->_script_otions[$name] = $options; return $this; } @@ -515,10 +515,10 @@ public function getScriptOptions($name = null) { if ($name) { - return (empty($this->_scripts_otions[$name])) ? array() : $this->_scripts_otions[$name]; + return (empty($this->_script_otions[$name])) ? array() : $this->_script_otions[$name]; } else { - return $this->_scripts_otions; + return $this->_script_otions; } } diff --git a/libraries/joomla/document/html/renderer/head.php b/libraries/joomla/document/html/renderer/head.php index 2c3fce5d6b471..86c6cce8a07aa 100644 --- a/libraries/joomla/document/html/renderer/head.php +++ b/libraries/joomla/document/html/renderer/head.php @@ -184,7 +184,7 @@ public function fetchHead($document) } // Generate scripts options - if (!empty($document->_scripts_otions)) + if (!empty($document->_script_otions)) { $buffer .= $tab . '