Success

User tests: Successful: Unsuccessful:

avatar Fedik
Fedik
22 Jun 2013

In current state the developers add the script options as global variables via addScriptDeclaration, that can be not always safe, and not nice. This path allow to store options in the one global object, where the options separated by the extension name.
The options stays as array until header render, that allow to simple overwrite it if need.

Example add the script option:

$options = array(
  'showAlert' => false,
  'consolelog' => true,
  'text' => 'Hi! I am "Text"!',
  'someArray' => array('one', 'two', 'and so on')
);
$doc->setScriptOptions($options, 'plg_examplejs');

Access to the options in frontend:

Joomla.optionsStorage.plg_examplejs;

Links:

avatar Fedik Fedik - open - 22 Jun 2013
avatar Fedik Fedik - reference | - 22 Jun 13
avatar Fedik
Fedik - comment - 22 Jun 2013

nice tip, need to try...
what with a typo you mean? for me looks good :)

about JSON_FORCE_OBJECT I think it no need cause it convert the non-associative array to object that not really nice in case when you need to have the array in the options

avatar piotr-cz
piotr-cz - comment - 22 Jun 2013

I meant you're missing P: _scripts_oPtions

Your are right about JSON_FORCE_OBJECT. I just copied that from my code :)

avatar Fedik
Fedik - comment - 22 Jun 2013

ah hahaha
I thought you mean scriptsoptions ...
thanks! really not seen :)
now should be better ;)

avatar Fedik
Fedik - comment - 8 Feb 2014

pull to staging #3072

avatar Fedik Fedik - close - 8 Feb 2014

Add a Comment

Login with GitHub to post a comment