? ? Pending

User tests: Successful: Unsuccessful:

avatar Fedik
Fedik
19 Aug 2016

Here is idea of 'lazy' loading for Joomla.optionsStorage.
The idea is very simple. Use custom <script type="application/json"></script> and load it only when it requested by Joomla.getOptions().

You see the script but it is not JavaScript :neckbeard:

It should be part of #3072, but unfortunately I did not had this idea on that time ?

Testing Instructions

Place in index.php of Isis template the test options:

$this->addScriptOptions('com_alert', 'Ta da!');
$this->addScriptOptions('com_foobar', array(
    array('selector' => 'body', 'color' => 'orange'),
    array('selector' => 'table tr:nth-child(2n)>td', 'color' => 'green'),
));

Place in template.js of Isis template the test JavaScript:

alert(Joomla.getOptions('com_alert'));

jQuery(document).ready(function($){
    var myOptions = Joomla.getOptions('com_foobar');
    if(myOptions){
        for(var i = 0, l = myOptions.length; i < l; i++){
            $(myOptions[i].selector).css('color', myOptions[i].color);
        }
    }
});

Open some page with table view (example Plugins).
You should get alert "Ta da!" and then after domready you should see all text in the table is yellow, and each even row is green.

Similar can be done for Joomla.JText. I can do it, if this idea will be accepted.

@dgt41 It is what I told you some time ago ?

Wiki: Adding the options to your JavaScript code

avatar Fedik Fedik - open - 19 Aug 2016
avatar andrepereiradasilva
andrepereiradasilva - comment - 19 Aug 2016

is "text/joomla-script-options" a w3c valid html script tag type attribute mime type?

The type attribute gives the language of the script or format of the data. If the attribute is present, its value must be a valid MIME type. The charset parameter must not be specified. The default, which is used if the attribute is absent, is "text/javascript".

https://www.w3.org/TR/html5/scripting-1.html#attr-script-type

Also http://www.iana.org/assignments/media-types/media-types.xhtml#text

avatar dgt41
dgt41 - comment - 19 Aug 2016

WOW, now I need to redo some stuff! Great work @Fedik ?

avatar Fedik
Fedik - comment - 19 Aug 2016

@andrepereiradasilva If I right remember there can be anything, cannot find quick explanation,
but only text/javascrip browser will parse as JavaScript

avatar andrepereiradasilva
andrepereiradasilva - comment - 19 Aug 2016

@Fedik this

If the attribute is present, its value must be a valid MIME type.

A string is a valid MIME type if it matches the media-type rule defined in section 3.1.1.1 "Media Types" of RFC 7231. In particular, a valid MIME type may include MIME type parameters.

Is the HTML5 specification. So it can't. it must be a valid mime type.

Internet media types ought to be registered with IANA according to the procedures defined in [BCP13].

See https://tools.ietf.org/html/rfc7231#section-3.1.1.1

avatar Fedik
Fedik - comment - 19 Aug 2016

@andrepereiradasilva I found this https://www.w3.org/TR/html401/interact/scripts.html#idx-scripting_language

As HTML does not rely on a specific scripting language, document authors must explicitly tell user agents the language of each script

It used a loot as the template holder, for different JavaScript libraries.

avatar andrepereiradasilva
andrepereiradasilva - comment - 19 Aug 2016

that's HTML 4.01 ....

avatar dgt41
dgt41 - comment - 19 Aug 2016

what will happen if you append text/html ?

avatar Fedik
Fedik - comment - 19 Aug 2016

A loot people use similar hack, so I think it should be fine ?

avatar andrepereiradasilva
andrepereiradasilva - comment - 19 Aug 2016

i'm sorry to disagree ... if it's not allowed by the HTML specification IMO joomla shouldn't do it.
i remember one browser that did things not allowed by specifications ... ie

don't know if this would help in this case, but why not adding those as data attributes in the script tag. This PR #11289 allows to do that ... if only people spend time testing ... ;)

avatar dgt41
dgt41 - comment - 19 Aug 2016

@andrepereiradasilva I support data attributes (and have tested that pr) but the benefit here is that you have well structured data, which makes life a bit easier in javascript

avatar andrepereiradasilva
andrepereiradasilva - comment - 19 Aug 2016

ok if you want structered then use json mimetype right? application/json i think
http://www.iana.org/assignments/media-types/application/json

PS: for instance i have live sites with microdata in JSON LD format

<script type="application/ld+json"> [ { ... } ]</script>

So application/json should be good too.

avatar dgt41
dgt41 - comment - 19 Aug 2016

you got a point here, @Fedik ?

avatar Fedik
Fedik - comment - 19 Aug 2016

we can name it as you like, for me no difference ?

avatar andrepereiradasilva
andrepereiradasilva - comment - 19 Aug 2016

ok, if mimetype changed seems a good concept to me and also for use in javascript JText.

avatar Fedik
Fedik - comment - 19 Aug 2016

@andrepereiradasilva you suggest application/json ?
do you found full list?
I found this http://www.iana.org/assignments/media-types/media-types.xhtml

avatar andrepereiradasilva
andrepereiradasilva - comment - 19 Aug 2016

do you found full list?
I found this http://www.iana.org/assignments/media-types/media-types.xhtml

That the IANA official list. They are resposnible for registering the mimetypes so it's oficial.
Search for json in that page and you see it there.

avatar andrepereiradasilva
andrepereiradasilva - comment - 19 Aug 2016

the type just as to represent what's inside the script tag, if you are dumping json there, then the type should be application/json
ok course after you need to test browser support (IE8+ essencially)

avatar dgt41
dgt41 - comment - 19 Aug 2016

application/json works fine:
screen shot 2016-08-19 at 19 41 32

avatar Fedik
Fedik - comment - 19 Aug 2016

thanks, I have changed to application/json

avatar andrepereiradasilva andrepereiradasilva - test_item - 19 Aug 2016 - Tested successfully
avatar andrepereiradasilva
andrepereiradasilva - comment - 19 Aug 2016

I have tested this item successfully on 14151a3

Tested in Chrome, Firefox, Opera (latest versions)
Tested in IE10 (IE10, compatibiliy mode, IE9 emulation mode and IE8 emulation mode)

Needs also to be tested in a IE8/IE9 browsers


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/11671.

avatar dgt41 dgt41 - test_item - 19 Aug 2016 - Tested successfully
avatar dgt41
dgt41 - comment - 19 Aug 2016

I have tested this item successfully on 14151a3


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/11671.

avatar andrepereiradasilva
andrepereiradasilva - comment - 19 Aug 2016

one question related to this PR.
Shouldn't the Joomla JS core.js have since versions tags in their functions doc blocks?

avatar Fedik
Fedik - comment - 19 Aug 2016

@andrepereiradasilva I have no idea when it can be merged, so I skip this part

avatar andrepereiradasilva
andrepereiradasilva - comment - 19 Aug 2016

just use @since __DEPLOY_VERSION__ the bump.php script the mantainers use will take care of the rest for us
https://github.com/joomla/joomla-cms/blob/staging/build/bump.php#L319

avatar andrepereiradasilva andrepereiradasilva - test_item - 19 Aug 2016 - Tested successfully
avatar andrepereiradasilva
andrepereiradasilva - comment - 19 Aug 2016

I have tested this item successfully on 14151a3

just since tags changed


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/11671.

avatar dgt41
dgt41 - comment - 19 Aug 2016

So I guess I have to redo #11654 to use this and NOT create a bunch of unneeded elements

avatar andrepereiradasilva
andrepereiradasilva - comment - 19 Aug 2016

(side note)
@dgt41 IMHO you should only add data with data-* attributes when the data inside is related somehow to the HTML tag itself where you have the data-* attributes.
-1 for creating empty HTML elements for dumping data in data-* attributes :)

avatar dgt41
dgt41 - comment - 19 Aug 2016

I know, I know ?. Anyways after this PR that one will get much prettier ?

avatar andrepereiradasilva andrepereiradasilva - test_item - 19 Aug 2016 - Tested successfully
avatar andrepereiradasilva
andrepereiradasilva - comment - 19 Aug 2016

I have tested this item successfully on 1fc35e5


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/11671.

avatar dgt41 dgt41 - test_item - 19 Aug 2016 - Tested successfully
avatar dgt41
dgt41 - comment - 19 Aug 2016

I have tested this item successfully on 1fc35e5


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/11671.

avatar andrepereiradasilva
andrepereiradasilva - comment - 20 Aug 2016

so will this be RTC ?

avatar dgt41
dgt41 - comment - 20 Aug 2016

I think we need a test with IE8 before RTC

avatar andrepereiradasilva
andrepereiradasilva - comment - 20 Aug 2016

i tough you tested ?

avatar Fedik
Fedik - comment - 20 Aug 2016

in IE8/9/10 (emulation mode) works for me, but need independent confirmation ?

avatar andrepereiradasilva
andrepereiradasilva - comment - 20 Aug 2016

Does anyone knows a simple way to test in a real IE8 ?

BTW, in IE8/9/10 (emulation mode) also works for me.

But we need a test in a real IE8.

avatar Fedik
Fedik - comment - 20 Aug 2016

I do not know where the dinosaurs live ?

avatar dgt41
dgt41 - comment - 20 Aug 2016

if you are on windows < 10 then http://www.my-debugbar.com/wiki/IETester/HomePage should be good

avatar andrepereiradasilva
andrepereiradasilva - comment - 20 Aug 2016

not on windows < 10

avatar Fedik
Fedik - comment - 20 Aug 2016

I made same for Joomla.JText #11690

avatar brianteeman brianteeman - change - 20 Aug 2016
Category JavaScript Libraries
avatar brianteeman brianteeman - change - 20 Aug 2016
Status New Pending
avatar Fedik
Fedik - comment - 21 Aug 2016

One more improvement.
Now the options available even before domready. That is good if someone need them in js file.

I have updated the testing instruction also.

avatar andrepereiradasilva
andrepereiradasilva - comment - 21 Aug 2016

good thinking :)

avatar Fedik
Fedik - comment - 21 Aug 2016

I found one small drawback, if content loaded with ajax, and there exists <script type="application/json" id="joomla-script-options"> then the new options will be ignored.

For now such thing not used in the core.
But maybe some template developers want use ajax like
jQuery('.div-block').load('/blabla?tmpl=component')

Any thoughts?

avatar Fedik
Fedik - comment - 21 Aug 2016

ok, should be good now,
I also have added the testing code for Core Joomla.getOptions

wow, getElementsByClassName does not work in IE8? surprise ?
I was wrong, everything is broken

fixed :neckbeard:

avatar dgt41 dgt41 - test_item - 26 Aug 2016 - Tested successfully
avatar dgt41
dgt41 - comment - 26 Aug 2016

I have tested this item successfully on a97c69d


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/11671.

avatar wilsonge
wilsonge - comment - 3 Sep 2016

Based on indirect testing in #11690 which is RTC and with the extensive code review by various people and the test by @dgt41 here - I'm going to set this RTC

avatar wilsonge wilsonge - change - 3 Sep 2016
Milestone Added:
Status Pending Ready to Commit
avatar wilsonge
wilsonge - comment - 3 Sep 2016

Merged with 611cb2e

@Fedik would you please write some documentation for this in the wiki please!

avatar wilsonge wilsonge - change - 3 Sep 2016
Status Ready to Commit Closed
Closed_Date 0000-00-00 00:00:00 2016-09-03 11:18:56
Closed_By wilsonge
avatar wilsonge wilsonge - close - 3 Sep 2016
avatar joomla-cms-bot joomla-cms-bot - change - 3 Sep 2016
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - change - 3 Sep 2016
Labels Added: ?
Removed: ?
avatar joomla-cms-bot joomla-cms-bot - change - 3 Sep 2016
Category JavaScript Libraries Libraries JavaScript Unit Tests
avatar Fedik
Fedik - comment - 3 Sep 2016

@wilsonge yes, I need to think about it

avatar Fedik
Fedik - comment - 4 Sep 2016

wiki section https://docs.joomla.org/J3.x:Adding_JavaScript_and_CSS_to_the_page#Adding_the_options_to_your_JavaScript_code

would be cool if someone with good English knowledge review it ?

avatar Fedik Fedik - change - 4 Sep 2016
The description was changed

Add a Comment

Login with GitHub to post a comment