-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
[WebProfilerBundle] Fixes event listener attaching error in IE #13636
Conversation
@@ -67,6 +67,14 @@ | |||
localStorage.setItem(profilerStorageKey + name, value); | |||
}, | |||
|
|||
addEvent = function (element, eventName, callback) { | |||
if (document.all) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 😄
There was a problem hiding this comment.
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.
7afae0d
to
b033350
Compare
} | ||
|
||
if (e.target) { | ||
target = e.target; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in ecc30cc
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. |
I meant plain polyfills |
Some of polyfills, but I don't think that we need one yet: |
ecc30cc
to
fef1eaf
Compare
fef1eaf
to
21693e4
Compare
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. |
👍 |
Thank you @aik099. |
…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
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
…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.
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
I haven't tested the change, because I don't any working Symfony installation at hand. By the looks of changes it should work.