-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Remove id dependency #1360
Remove id dependency #1360
Conversation
there's no need to manually update the visibility of an option.
Removing ID dependencies will allow us to remove some ugly code down the road. I like that.
a requirment for Chosen to function. If a select has an ID, give Chosen an appropriately named ID. If it doesn't have an ID, keep calm and carry on.
@@ -152,7 +150,7 @@ class Chosen extends AbstractChosen | |||
|
|||
|
|||
test_active_click: (evt) -> | |||
if $(evt.target).parents('#' + @container_id).length | |||
if @container[0] is $(evt.target).parents('.chzn-container')[0] |
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.
Probably not a big deal, but you can also access the element with @container.get(0)
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.
instead of getting all parents matching .chzn-container
and getting the first one in it, it would be more efficient to use .closest('.chzn-container')
so that it stops traversing the DOM once it finds the first one
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.
I actually prefer the array syntax to get(0)
.
c335d5f switches to closest
@@ -152,7 +150,7 @@ class Chosen extends AbstractChosen | |||
|
|||
|
|||
test_active_click: (evt) -> | |||
if $(evt.target).parents('#' + @container_id).length | |||
if @container[0] is $(evt.target).closest('.chzn-container')[0] |
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 don't need the [0]
. You can pass the jquery collection to .is()
. The collection return by .closest
has at most as many elements as the original collection anyway (as it can find 0 or 1 closest matching parent for each element in the collection) so it will only contain 0 or 1 element here.
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.
@@ -87,11 +85,10 @@ class AbstractChosen | |||
|
|||
style = if option.style.cssText != "" then " style=\"#{option.style}\"" else "" |
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 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.
Also, I'd love to get rid of the double quote escaping and just use single quote.
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.
I don't really like changing unrelated lines. We can open a separate PR
This looks good to me. Just one small comment above. |
@kenearley @stof @koenpunt
Some time ago, we made a change in Chosen that made the plugin less dependent on HTML IDs. This had two major benefits: 1) the code became less brittle and 2) it became possible to initialize Chosen outside of a DOM context. Chosen still has some remnants of this ID requirement and I've finally gotten around to cleaning them up in this PR.
Notes about this PR