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

Fix for potential issues with getInheritedTheme#2778

Closed
ronchalant wants to merge 4 commits intojquery-archive:masterfrom
ronchalant:master
Closed

Fix for potential issues with getInheritedTheme#2778
ronchalant wants to merge 4 commits intojquery-archive:masterfrom
ronchalant:master

Conversation

@ronchalant
Copy link

per: #2770

I think the safest approach is to turn this into a recursive function. Normally I'd reuse closest(), but unless we put in a jQuery expr to support our regex (which seems a bit much for this) this seems the best approach.

It also allows you to get an inherited theme right from a jQuery object, i.e. $("#field-one").inheritedTheme()

Copy link
Contributor

Choose a reason for hiding this comment

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

@ronchalant

Thanks for pointing out the possibility for a false positive, the original code didn't have the \b in it so I added that when I was trying to get rid of all the duplicate code. This function gets called quite a bit, especially since it is used in buttonMarkup. I would prefer if it wasn't recursive so we don't have to incur the recursive function call costs. It might be better to simply call parents() and loop manually over the resulting list.

@ronchalant
Copy link
Author

I committed another change to utilize parents() using the selector from the original couple with a regex check in an each() block. In a quick test getting the inheritedTheme of a button 10,000 times with each approach the results were virtually identical, around 900ms.

I did find that my check to stop infinite recursion was bad; I needed p.parent().length in the check not p.parent() by itself.

@johnbender
Copy link
Contributor

@ronchalant

We appreciate the update, but since the associated issue has been closed I'm going to do the same here. In general we're going to try to avoid adding functions to $.fn since it's a namespace used by plugins. In fact we're guilty (mostly me) of having too much there already.

Further commentary is welcome.

@johnbender johnbender closed this Dec 9, 2011
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants