User tests: Successful: Unsuccessful:
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
It should be part of #3072, but unfortunately I did not had this idea on that time
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
@andrepereiradasilva If I right remember there can be anything, cannot find quick explanation,
but only text/javascrip
browser will parse as JavaScript
@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].
@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.
that's HTML 4.01 ....
what will happen if you append text/html
?
A loot people use similar hack, so I think it should be fine
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 ... ;)
@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
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.
we can name it as you like, for me no difference
ok, if mimetype changed seems a good concept to me and also for use in javascript JText.
@andrepereiradasilva you suggest application/json
?
do you found full list?
I found this http://www.iana.org/assignments/media-types/media-types.xhtml
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.
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)
thanks, I have changed to application/json
I have tested this item
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
I have tested this item
one question related to this PR.
Shouldn't the Joomla JS core.js have since versions tags in their functions doc blocks?
@andrepereiradasilva I have no idea when it can be merged, so I skip this part
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
I have tested this item
just since tags changed
I know, I know
I have tested this item
I have tested this item
so will this be RTC ?
I think we need a test with IE8 before RTC
i tough you tested
in IE8/9/10 (emulation mode) works for me, but need independent confirmation
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.
I do not know where the dinosaurs live
if you are on windows < 10 then http://www.my-debugbar.com/wiki/IETester/HomePage should be good
not on windows < 10
Category | ⇒ | JavaScript Libraries |
Status | New | ⇒ | Pending |
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.
good thinking :)
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?
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
I have tested this item
Milestone |
Added: |
||
Status | Pending | ⇒ | Ready to Commit |
Status | Ready to Commit | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2016-09-03 11:18:56 |
Closed_By | ⇒ | wilsonge |
Labels |
Added:
?
|
Labels |
Added:
?
Removed: ? |
Category | JavaScript Libraries | ⇒ | Libraries JavaScript Unit Tests |
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
is "text/joomla-script-options" a w3c valid html script tag type attribute mime type?
https://www.w3.org/TR/html5/scripting-1.html#attr-script-type
Also http://www.iana.org/assignments/media-types/media-types.xhtml#text