Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Checkboxradio: Retrieve label correctly#7293

Closed
gabrielschulhof wants to merge 3 commits intomasterfrom
7292-correctly-retrieve-label
Closed

Checkboxradio: Retrieve label correctly#7293
gabrielschulhof wants to merge 3 commits intomasterfrom
7292-correctly-retrieve-label

Conversation

@gabrielschulhof
Copy link
Copy Markdown

This PR does two things. It

  1. centralizes the code for retrieving the label into one function (_findLabel) so it's easily unit-testable
  2. makes use of this.element[ 0 ].labels, if present, otherwise it grabs the labels from this.document[ 0 ].getElementsByTagName( "label" ) and looks for the relevant one

I've run the new unit tests on:

  • phantomjs (obviously :) )
  • Chrome/Desktop
  • WP7.5 (Nokia Lumia 800)
  • WP8 (Nokia Lumia 520)
  • Windows 8/IE 10 (Browserstack)
  • Android 2.3.5 (Samsung Galaxy S II) EDIT
  • iOS 6.1.5 (iPod) EDIT
  • FF27/Linux EDIT

... and all the right ones fail without the change applied, and all of them pass with the change applied.

@gabrielschulhof
Copy link
Copy Markdown
Author

Hmmm ... there seems to be a perf hit especially on Blink: http://jsperf.com/checkboxradio-label-retrieval-non-nested

gabrielschulhof pushed a commit that referenced this pull request Apr 3, 2014
Improves performance a great deal when the .labels property is supported, and
also improves performance when such a property is not supported (FF27).

http://jsperf.com/checkboxradio-label-retrieval-non-nested/5

Closes gh-7293
Fixes gh-7292
Gabriel Schulhof added 2 commits April 3, 2014 12:14
This helps render the code unit-testable.
Improves performance a great deal when the .labels property is supported, and
also improves performance when such a property is not supported (FF27).

http://jsperf.com/checkboxradio-label-retrieval-non-nested/5

Closes gh-7293
Fixes gh-7292
@gabrielschulhof
Copy link
Copy Markdown
Author

OK. Perf issues fixed thanks to @arschmitz, yielding an enormous improvement on platforms that support the .labels property.

@Ruffio
Copy link
Copy Markdown

Ruffio commented Apr 3, 2014

Is this fix only relevant for inputs or are there other form elements that could gain in performance when locating the relevant label?

@Ruffio
Copy link
Copy Markdown

Ruffio commented Apr 10, 2014

anyone?

@gabrielschulhof
Copy link
Copy Markdown
Author

@Ruffio I believe it's only relevant to checkboxes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This sounds like a bug in core have you checked with them about this?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

That wasn't my finding. I moved the comment along with the rest of the code.

@arschmitz
Copy link
Copy Markdown
Contributor

@dmethvin what do you think about a selector not finding an element but filter doing it in WP8? If this is true sounds like a core bug to me.

@dmethvin
Copy link
Copy Markdown
Contributor

Is there a test case?

@gabrielschulhof
Copy link
Copy Markdown
Author

@dmethvin @arschmitz I'll try to see if this is reproducible and if so, I'll try to build up a test case for core.

@dmethvin
Copy link
Copy Markdown
Contributor

Thanks, it sounds like it might be an IE11 issue in general, so the test case will help there and maybe we can get them to fix it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@arschmitz Since we're going to be using getElementsByTagName(), we're keeping the .filter() setup, but not because otherwise it doesn't work on Windows.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why are you searching this.document[0] with getElementsByTagName is this a perf optimization?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It is indeed.

@arschmitz
Copy link
Copy Markdown
Contributor

👍

gabrielschulhof pushed a commit that referenced this pull request May 29, 2014
This moves label-finding code into one function to help render the code
unit-testable. The new code also relies more on native means of getting the
label, which improves performance a great deal when the .labels property is
supported, and also improves performance when such a property is not supported
(such as in FF27).

http://jsperf.com/checkboxradio-label-retrieval-non-nested/5

(cherry picked from commit d9f5d21)

Closes gh-7293
Fixes gh-7292
@gabrielschulhof gabrielschulhof deleted the 7292-correctly-retrieve-label branch May 29, 2014 15:10
agcolom pushed a commit to agcolom/jquery-mobile that referenced this pull request Nov 26, 2014
This moves label-finding code into one function to help render the code
unit-testable. The new code also relies more on native means of getting the
label, which improves performance a great deal when the .labels property is
supported, and also improves performance when such a property is not supported
(such as in FF27).

http://jsperf.com/checkboxradio-label-retrieval-non-nested/5

Closes jquery-archivegh-7293
Fixes jquery-archivegh-7292
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants