Skip to content

[2.8][WebProfilerBundle] Fix search button click listener #15928

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

Merged
merged 1 commit into from
Sep 27, 2015

Conversation

xelaris
Copy link
Contributor

@xelaris xelaris commented Sep 26, 2015

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

This fixes an issue when clicking the sidebar "Search" button text instead of the button. Then the click event target/srcElement is the span child-element, instead of the listening a element, which causes errors in the listener, since it expects the listening element. In consequence of that the search form isn't shown.

To fix this, the same technique is used, as for the navigation tabs. Traversing the DOM up to the expected a element.

@@ -349,7 +349,7 @@
}

tabNavigation[j].addEventListener('click', function(e) {
var activeTab = e.target || e.srcElement;
var activeTab = this;
Copy link
Member

Choose a reason for hiding this comment

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

is this set to the current element in a consistent way cross-browser ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point @stof. When using native addEventListener I'm quite sure that this references the target element in all browsers, but I just notice Sfjs.addEventListener falls back to attachEvent if addEventListener isn't avialable (especially for IE<9) since #13636. In listeners attached with attachEvent this doesn't references the target element, without further effort.

When looking too lines below, it turns out that the navigation tab listener already considers the case of embedded html by traversing the DOM tree up to the expected tag. I overlooked that before. I will update this PR to revert this listener and use the same technique for the search button listener.

@xelaris xelaris changed the title [WebProfilerBundle] Fix button/tab click listener [2.8][WebProfilerBundle] Fix search button click listener Sep 26, 2015
@xelaris
Copy link
Contributor Author

xelaris commented Sep 26, 2015

The PR has been updated, as @stof pointed out an issue with the usage of this in the event listener, which isn't available in IE<9 because of the usage of attachEvent there.

Is a list of supported browser versions available for the profiler? I think IE 8 must be the oldest supported IE because of the usage of querySelector and querySelectorAll, right?

@@ -372,7 +372,7 @@
},

createToggles: function() {
var toggles = document.querySelectorAll('.sf-toggle');
var toggles = document.querySelectorAll('a.sf-toggle');
Copy link
Member

Choose a reason for hiding this comment

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

why forcing it on <a> elements ? You could keep the class-only selector and use hasClass(toggle) in your while loop

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right. I adopt it from the navigation tabs, where the li elements don't have a class and the tag name is used. I agree, in case of the toggle button, verifying the class name is smarter.

@xelaris
Copy link
Contributor Author

xelaris commented Sep 26, 2015

Thanks @stof, the PR has been updated again, considering your hint.

@javiereguiluz
Copy link
Member

👍 thanks @xelaris

@fabpot
Copy link
Member

fabpot commented Sep 27, 2015

Thank you @xelaris.

@fabpot fabpot merged commit f9ddddb into symfony:2.8 Sep 27, 2015
fabpot added a commit that referenced this pull request Sep 27, 2015
…(xelaris)

This PR was merged into the 2.8 branch.

Discussion
----------

[2.8][WebProfilerBundle] Fix search button click listener

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

This fixes an issue when clicking the sidebar "Search" button **text** instead of the **button**. Then the click event target/srcElement is the *span* child-element, instead of the listening *a* element, which causes errors in the listener, since it expects the listening element. In consequence of that the search form isn't shown.

To fix this, the same technique is used, as for the navigation tabs. Traversing the DOM up to the expected *a* element.

Commits
-------

f9ddddb [WebProfilerBundle] Fix search button click listener
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants