[#31203] The one way and the one container for store the script options#3072
[#31203] The one way and the one container for store the script options#3072Kubik-Rubik merged 14 commits intojoomla:stagingfrom
Conversation
|
Works without problems and offers a nice way to store javascript options 👍 This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/3072. |
|
It is similar to #6006 but #6006 is more compact This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/3072. |
|
@Kubik-Rubik yes, this is still a very very very very valid feature request 😉 |
|
@Fedik I am not understanding the use of this PR. Can you explain it in more detail? |
There was a problem hiding this comment.
Requires a blank line before the if statement according to codestyle.
|
@roland-d for now if you need to add some JavaScript variable for one of your script you do: $doc->addScriptDeclaration("
var foo = 'blabla';
var bar = ['more', 'blabla'];
");Such approach have couple problem:
With my suggestion you can do: $doc->addScriptOptions('myextension_name', array(
'foo' => 'blabla',
'bar' => ['more', 'blabla']
));and in javascript access to them: console.log(Joomla.optionsStorage.myextension_name.foo);
console.log(Joomla.optionsStorage.myextension_name.bar);As you can see all options under Also you can modify your options at PHP runtime easily, eg. from plugin or where you need to do it. $options = $doc->getScriptOptions('myextension_name');
$options['foo'] = 'ue ue';
$doc->addScriptOptions('myextension_name', $options);
// or more easy:
$doc->addScriptOptions('myextension_name', array('foo' => 'ue ue'));
// it will be merged, and old 'foo' changedInitially I made it for #1260, #6357, as with such approach we can move 99% of inline javascript to the files more easy, and rule them just by using the appropriate options in |
|
This PR has received new commits. CC: @yvesh This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/3072. |
|
@Fedik I was speaking with some PLT members about the possibility to use more the data attributes to pass strings or PHP values. This way we drop the inline script just to pass some simple (or more complex data) from PHP to Javascript. Although a way to do it with inline script MUST also be available. So my idea is to drop JText::script() and replace it with this function you introduce here, and make sure that in most places (at least in the core) we just use data attributes. But that is more a 4.0 thing I guess... |
|
@DGT41 And what means your comment to someone who wants testing patches? No further tests on this one? This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/3072. |
|
@Fedik Can this be used next to what we have now? In that case we may be able to work on this for 3.6 as there seems general consensus this is the way forward. |
|
@roland-d yes, it still valid, |
Conflicts: libraries/joomla/document/html/renderer/head.php
|
This PR has received new commits. CC: @yvesh This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/3072. |
|
@Fedik I had another go at this PR and it's great. I now fully understand what it does and see great potential for it :) Thanks for the follow-up even though it has taken 2 years. Let's get it done for 3.6. |
|
I have tested this item ✅ successfully on 852311a This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/3072. |
|
I have tested this item ✅ successfully on 852311a This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/3072. |
|
We have 2 successful tests, setting to RTC. This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/3072. |
|
Setting to needs review. As the pretty print requires a php version higher than the joomla minimun This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/3072. |
|
@brianteeman $pretyPrint = (JDEBUG && defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : false); |
|
Thanks for confirming that - all good - setting back to RTC This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/3072. |
|
Thank you @Fedik and all testers! |
Wiki: Adding the options to your JavaScript code
Example add the script option:
Access to the options in frontend:
Links: