Skip to content

[WebProfilerBundle] Fixes event listener attaching error in IE #13636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

aik099
Copy link

@aik099 aik099 commented Feb 10, 2015

I haven't tested the change, because I don't any working Symfony installation at hand. By the looks of changes it should work.

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? not sure (do we have JS tests?)
Fixed tickets #13447
License MIT
Doc PR

@@ -67,6 +67,14 @@
localStorage.setItem(profilerStorageKey + name, value);
},

addEvent = function (element, eventName, callback) {
if (document.all) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better to check the existence of element.addEventListener, don't you think?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also a drawback, in ie8 the reference to this in the event handler refers to the document object instead of the caller object. So eventHandlers using this should have an alternative to the caller object

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aik099 could you do this check around the function definition instead of doing it at runtime to do it only once ? And checking for document.addEventListener would indeed be better than document.all

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you do this check around the function definition instead of doing it at runtime to do it only once

@stof, what do you mean? If I'll be checking for existence of element.addEventListener then I can't do this outside the addEvent function

There's also a drawback, in ie8 the reference to this in the event handler refers to the document object instead of the caller object. So eventHandlers using this should have an alternative to the caller object

@wvdweij , what do you mean? I haven't changed this reference inside the callback if you're referring to it. And in JavaScript the this can be changed dynamically when needed and it's up to callback itself to preserve it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aik099 This is why I suggested checking on document rather than element (document is available at definition time). The benefit is that you choose the right implementation of the function only once instead of doing the check for each call

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the method .attachEvent() in IE, In normal browsers, using .addEventListener, the var this points to the element, while in IE it points to the window object.

So using this on the button events will probably break.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the method .attachEvent() in IE, In normal browsers, using .addEventListener, the var this points to the element, while in IE it points to the window object.

@wvdweij , I've pushed changes for this usage. Now we have lots of boilerplate code for cross-browser event handling 😄

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is why I suggested checking on document rather than element (document is available at definition time). The benefit is that you choose the right implementation of the function only once instead of doing the check for each call

@stof , done.

@aik099 aik099 force-pushed the 13447-symfony-2-profiler-bar-throws-javascript-error-in-ie8 branch from 7afae0d to b033350 Compare February 10, 2015 10:48
}

if (e.target) {
target = e.target;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are missing the variable delcaration for this variable in the function. It should be a local variable

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in ecc30cc

@wouterj
Copy link
Member

wouterj commented Feb 10, 2015

Is there a reason not to use the common polyfill? That would catch more edge cases

@aik099
Copy link
Author

aik099 commented Feb 10, 2015

Is there a reason not to use the common polyfill? That would catch more edge cases

I have no idea, why we're using plain JS here. I guess jQuery isn't used to prevent any conflicts with jQuery used from website slice up on which profiler is included.

@wouterj
Copy link
Member

wouterj commented Feb 10, 2015

I meant plain polyfills

@aik099
Copy link
Author

aik099 commented Feb 10, 2015

@fabpot
Copy link
Member

fabpot commented Feb 10, 2015

@aik099 Looks like @stof does not have any more comments :)

@aik099 aik099 force-pushed the 13447-symfony-2-profiler-bar-throws-javascript-error-in-ie8 branch from ecc30cc to fef1eaf Compare February 10, 2015 16:31
@aik099 aik099 force-pushed the 13447-symfony-2-profiler-bar-throws-javascript-error-in-ie8 branch from fef1eaf to 21693e4 Compare February 10, 2015 16:33
@aik099
Copy link
Author

aik099 commented Feb 10, 2015

All done, but polyfill, which is a bit unclear. I must remind, that I haven't tested this anywhere, so if you can please test in IE and any other browser.

@stof
Copy link
Member

stof commented Feb 10, 2015

👍

@fabpot
Copy link
Member

fabpot commented Feb 11, 2015

Thank you @aik099.

@fabpot fabpot merged commit 21693e4 into symfony:2.6 Feb 11, 2015
fabpot added a commit that referenced this pull request Feb 11, 2015
…n IE (aik099)

This PR was merged into the 2.6 branch.

Discussion
----------

[WebProfilerBundle] Fixes event listener attaching error in IE

I haven't tested the change, because I don't any working Symfony installation at hand. By the looks of changes it should work.

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | not sure (do we have JS tests?)
| Fixed tickets | #13447
| License       | MIT
| Doc PR        |

Commits
-------

21693e4 [WebProfilerBundle] Fixes event listener attaching error in IE
@aik099 aik099 deleted the 13447-symfony-2-profiler-bar-throws-javascript-error-in-ie8 branch February 11, 2015 10:42
@stof stof mentioned this pull request Feb 18, 2015
fabpot added a commit that referenced this pull request Feb 24, 2015
This PR was merged into the 2.6 branch.

Discussion
----------

Fix the toolbar JS for IE

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | n/a

- fix the binding of listeners on XMLHttpRequest to always use the addEventListener method. It does not make sense to change it to attachEvent as it is about binding listeners on DOM elements.
- fix the feature detection for the event binding on DOM elements:
    - the attachEvent and addEventListener methods are on DOM elements, not on the document object
    - the standard method should be preferred in IE versions supporting both methods
- avoid JS errors when XMLHttpRequest is not defined by avoiding to override its open method when the object is not there (old IE versions will still not intercept ajax calls though)

this is the complete fix for the code submitted in #13636 (the fix in #13684 was incomplete).

Commits
-------

b7aa171 Fix the toolbar JS for IE
fabpot added a commit that referenced this pull request Mar 21, 2015
…boudad)

This PR was merged into the 2.6 branch.

Discussion
----------

[WebProfilerBundle] fixed undefined buttons variable.

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Fixed tickets  | #13974, #13636
| Tests pass?   | yes
| License       | MIT

Commits
-------

a8c4da1 [WebProfilerBundle] fixed undefined buttons.
ostrolucky pushed a commit to ostrolucky/symfony that referenced this pull request Mar 25, 2018
This PR was merged into the 2.6 branch.

Discussion
----------

Fix the toolbar JS for IE

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | n/a

- fix the binding of listeners on XMLHttpRequest to always use the addEventListener method. It does not make sense to change it to attachEvent as it is about binding listeners on DOM elements.
- fix the feature detection for the event binding on DOM elements:
    - the attachEvent and addEventListener methods are on DOM elements, not on the document object
    - the standard method should be preferred in IE versions supporting both methods
- avoid JS errors when XMLHttpRequest is not defined by avoiding to override its open method when the object is not there (old IE versions will still not intercept ajax calls though)

this is the complete fix for the code submitted in symfony#13636 (the fix in symfony#13684 was incomplete).

Commits
-------

b7aa171 Fix the toolbar JS for IE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.