User tests: Successful: Unsuccessful:
As discussed in #11585 this adds the ability to polyfill js events in older browsers (ex: IE8).
JHtml::_('behavior.polyfill', 'event', 'lt IE 9');
JHtml::_('behavior.polyfill', 'classlist', 'lt IE 11');
$this->addScriptDeclaration("
document.addEventListener('DOMContentLoaded', function() {
this.getElementById('status').addEventListener('click', function() {
alert('clicked the status bar');
});
this.querySelector('.container-logo').addEventListener('click', function() {
alert('clicked the logo');
});
alert(this.body.classList);
});
");
Don't know. Usage examples:
JHtml::_('behavior.polyfill', 'event');
JHtml::_('behavior.polyfill', 'event', 'lt IE 9');
JHtml::_('behavior.polyfill', 'classlist', 'lt IE 11');
JHtml::_('behavior.polyfill', array('classlist'), 'lt IE 11');
JHtml::_('behavior.polyfill', array('event', 'classlist'));
JHtml::_('behavior.polyfill', array('event', 'classlist'), 'lte IE 11');
Mantainers, this PR depends on #11585
Can we add also classList, so I can drop all the polyfill stuff from the new calendar?
and maybe dataset
?
Make PR for my andrepereiradasilva:polyfill-behaviour
branch
One more thing: how about some logic (check if [if ]
exists) to move the tag before the other scripts (on head.php)?
IMHO JDocument::addScript and JDocument::addScriptVersion, and JHtml::script need to support conditional statements somehow.
dataset and classList: https://github.com/remy/polyfills
@andrepereiradasilva @Fedik do you agree?
@dgt41 the Ft was a nice API to build the js
Check
If that library supports dataset and classList IMHO we should stick to it.
I really don;t mind where the code comes from as long as it works and it well written.
So I was checking FT:
Element.prototype.classList is also not supported in IE9. Great More IE fun...
I really don;t mind where the code comes from as long as it works and it well written.
i thnk the same but for me is better mantainence if we could use the same api to have the polyfills.
dataset is not provided by FT, but for me this is not essential as you can still do
document.querySelector('.something').getAttribute('data-fantastic');
Which isn't that bad even compared to jQuery
jQuery('.something').data('fantastic');
classList polyfill added.
JHtml::_('behavior.polyfill', 'classlist', 'lt IE 10');
@andrepereiradasilva can I propose changing the minified files to use .min.js and the uncompressed palin .js.
This -uncompressed.js really hurts my eyes
can I propose changing the minified files to use .min.js and the uncompressed palin .js.
This -uncompressed.js really hurts my eyes?
lol i followed the same logic of all files in system/js dir
See https://github.com/joomla/joomla-cms/tree/staging/media/system/js
IMO if you want to change that you need to make a PR for change them all or you can use sunglasses
It can't be done in 3.x otherwise I would have done that PR, but for J4 I will and also separate the joomla (system) from the external ones
ok so let's levae that for 4.x
default values removed. usage examples:
Category | ⇒ | JavaScript |
Status | New | ⇒ | Pending |
nativ dataset
works like:
<div data-foo-bar="blabla" class="something"></div>
var element = document.querySelector('.something')[0];
console.log(element.dataset.fooBar);
//or
console.log(element.dataset['foo-bar']);
was just note, for now can stay with getAttribute
@Fedik @dgt41 need your help here.
Somehow the polyfills are not working in IE8 . any toughts?
example: https://cdn.polyfill.io/v2/polyfill.js?features=Element.prototype.classList&flags=always,gated
ok, i was wrong. so i discovered where the issue cames from.
the problem is the https://github.com/joomla/joomla-cms/pull/11686/files#diff-0d0a277d1b9b770848b694a026f09fd4R465 check
if (!('addEventListener' in this)) {
does not makes sens because we already added the addEventListener a few lines above
sorry I was busy with other thing
seems you need to check for addEventListener
somewhere earlier
yeah i know, but don't really want to change the code from the polyfill service, if i change it's harder to update later.
This file is from https://cdn.polyfill.io/v2/polyfill.js?features=Event.DOMContentLoaded&flags=always,gated
I think you can check for opposite thing
if (this.attachEvent) {
// it is IE
}
hum i think attachEvent is also availabe in IE9 and IE10.
ok it seems if (!('createEvent' in document)) {
works
http://caniuse.com/#feat=customevent
seems to work fine.
I have tested this item
I have tested it in IE8/9 (emulation mode)
I have tested this item
Status | Pending | ⇒ | Ready to Commit |
Labels |
Added:
?
|
Category | JavaScript | ⇒ | Libraries JavaScript |
Status | Ready to Commit | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2016-09-04 23:31:56 |
Closed_By | ⇒ | wilsonge |
Labels |
Removed:
?
|
@andrepereiradasilva can this work without: #11289 ?
yes, looks like?