? Success

User tests: Successful: Unsuccessful:

avatar andrepereiradasilva
andrepereiradasilva
20 Aug 2016

Summary of Changes

As discussed in #11585 this adds the ability to polyfill js events in older browsers (ex: IE8).

Testing Instructions

  • Apply #11289 and them this patch
  • Add this vanilla js events code in isis index.php
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);
});
");
  • Refresh an admin page you will get an alert message with the body element classes
  • Also, as the code says click the Joomla login in the admin and the admin status bar and check if you have a js alert.
  • Test in all Joomla 3.x supported browsers. https://docs.joomla.org/Joomla_Browser_Support
  • Code review

Documentation Changes Required

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');

Notes

Mantainers, this PR depends on #11585

@Fedik @dgt41 is this it?

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

yes, looks like ?

9f14eeb 20 Aug 2016 avatar andrepereiradasilva doc
avatar dgt41
dgt41 - comment - 20 Aug 2016

Can we add also classList, so I can drop all the polyfill stuff from the new calendar?

avatar Fedik
Fedik - comment - 20 Aug 2016

and maybe dataset ?

avatar andrepereiradasilva
andrepereiradasilva - comment - 20 Aug 2016

Make PR for my andrepereiradasilva:polyfill-behaviour branch

avatar dgt41
dgt41 - comment - 20 Aug 2016

One more thing: how about some logic (check if [if ] exists) to move the tag before the other scripts (on head.php)?

avatar andrepereiradasilva
andrepereiradasilva - comment - 20 Aug 2016

IMHO JDocument::addScript and JDocument::addScriptVersion, and JHtml::script need to support conditional statements somehow.

avatar dgt41
dgt41 - comment - 20 Aug 2016

dataset and classList: https://github.com/remy/polyfills
@andrepereiradasilva @Fedik do you agree?

avatar Fedik
Fedik - comment - 20 Aug 2016

"conditional statements" it is old stuff that should burn in fire ?
but for J3 we have no much chose

@dgt41 that looks fine, but need to test somehow ?

avatar andrepereiradasilva
andrepereiradasilva - comment - 20 Aug 2016

@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.

avatar dgt41
dgt41 - comment - 20 Aug 2016

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...

avatar andrepereiradasilva
andrepereiradasilva - comment - 20 Aug 2016

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.

avatar dgt41
dgt41 - comment - 20 Aug 2016

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');
avatar andrepereiradasilva
andrepereiradasilva - comment - 20 Aug 2016

Element.prototype.classList is also not supported in IE9. Great More IE fun...

The FT library has polyfill for that.

image

10, 11 seems to have partial support

avatar andrepereiradasilva
andrepereiradasilva - comment - 20 Aug 2016

classList polyfill added.

JHtml::_('behavior.polyfill', 'classlist', 'lt IE 10');

avatar dgt41
dgt41 - comment - 20 Aug 2016

@andrepereiradasilva can I propose changing the minified files to use .min.js and the uncompressed palin .js.
This -uncompressed.js really hurts my eyes ?

avatar andrepereiradasilva
andrepereiradasilva - comment - 20 Aug 2016

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 ? .

avatar dgt41
dgt41 - comment - 20 Aug 2016

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

avatar andrepereiradasilva
andrepereiradasilva - comment - 20 Aug 2016

ok so let's levae that for 4.x

avatar andrepereiradasilva
andrepereiradasilva - comment - 20 Aug 2016

default values removed. usage examples:

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

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']);
avatar andrepereiradasilva
andrepereiradasilva - comment - 21 Aug 2016
avatar Fedik
Fedik - comment - 21 Aug 2016

was just note, for now can stay with getAttribute

avatar andrepereiradasilva
andrepereiradasilva - comment - 21 Aug 2016

so for this to work properly, we reallly need JDocument::addScript and JDocument::addScriptVersion, and JHtml::script to accept conditional statements
hum... i guess i have to review my #11289 PR yet again ...

avatar andrepereiradasilva
andrepereiradasilva - comment - 21 Aug 2016

ok so i reviewed my PR again to accept conditinal statements.
#11289

Please test careful since that PR is a sigificant refactor of methods to adding scripts to document.

avatar andrepereiradasilva
andrepereiradasilva - comment - 21 Aug 2016

updated code and test instructions, this PR now depends on #11289

avatar andrepereiradasilva
andrepereiradasilva - comment - 21 Aug 2016

@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

avatar andrepereiradasilva
andrepereiradasilva - comment - 21 Aug 2016

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

avatar Fedik
Fedik - comment - 21 Aug 2016

sorry I was busy with other thing ?
seems you need to check for addEventListener somewhere earlier

avatar andrepereiradasilva
andrepereiradasilva - comment - 21 Aug 2016

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

avatar Fedik
Fedik - comment - 21 Aug 2016

I think you can check for opposite thing

if (this.attachEvent) {
  // it is IE
}
avatar andrepereiradasilva
andrepereiradasilva - comment - 21 Aug 2016

hum i think attachEvent is also availabe in IE9 and IE10.

avatar andrepereiradasilva
andrepereiradasilva - comment - 21 Aug 2016

ok it seems if (!('createEvent' in document)) { works
http://caniuse.com/#feat=customevent

avatar andrepereiradasilva
andrepereiradasilva - comment - 21 Aug 2016

seems to work fine.

avatar Fedik Fedik - test_item - 21 Aug 2016 - Tested successfully
avatar Fedik
Fedik - comment - 21 Aug 2016

I have tested this item successfully on c8781ba

I have tested it in IE8/9 (emulation mode)


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

avatar andrepereiradasilva
andrepereiradasilva - comment - 31 Aug 2016

@dgt41 can you test this so it gets RTC?

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

I have tested this item successfully on c8781ba


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

avatar dgt41 dgt41 - change - 31 Aug 2016
Status Pending Ready to Commit
avatar dgt41
dgt41 - comment - 31 Aug 2016

screen shot 2016-08-31 at 17 56 48

RTC

avatar joomla-cms-bot joomla-cms-bot - change - 31 Aug 2016
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - change - 31 Aug 2016
Category JavaScript Libraries JavaScript
avatar dgt41
dgt41 - comment - 31 Aug 2016

NOTE: #11289 needs to be merged before this one

avatar wilsonge
wilsonge - comment - 4 Sep 2016

Merged with 075a14b

avatar wilsonge wilsonge - close - 4 Sep 2016
avatar joomla-cms-bot joomla-cms-bot - close - 4 Sep 2016
avatar wilsonge wilsonge - change - 4 Sep 2016
Status Ready to Commit Closed
Closed_Date 0000-00-00 00:00:00 2016-09-04 23:31:56
Closed_By wilsonge
avatar joomla-cms-bot joomla-cms-bot - change - 4 Sep 2016
Labels Removed: ?
avatar zero-24
zero-24 - comment - 3 Oct 2016

@andrepereiradasilva can this work without: #11289 ?

avatar andrepereiradasilva
andrepereiradasilva - comment - 3 Oct 2016

no it can't. #11289 adds the hability to add IE contitional statemens tags and polyfill needs it.

Add a Comment

Login with GitHub to post a comment