Skip to content
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 use of attr(), closes #334 #1385

Merged
merged 7 commits into from
Jul 24, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions coffee/chosen.jquery.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Chosen extends AbstractChosen
if @is_multiple
@container.html '<ul class="chzn-choices"><li class="search-field"><input type="text" value="' + @default_text + '" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chzn-drop"><ul class="chzn-results"></ul></div>'
else
@container.html '<a href="javascript:void(0)" class="chzn-single chzn-default" tabindex="-1"><span>' + @default_text + '</span><div><b></b></div></a><div class="chzn-drop"><div class="chzn-search"><input type="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>'
@container.html '<a class="chzn-single chzn-default" tabindex="-1"><span>' + @default_text + '</span><div><b></b></div></a><div class="chzn-drop"><div class="chzn-search"><input type="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>'

@form_field_jq.hide().after @container
@dropdown = @container.find('div.chzn-drop').first()
Expand Down Expand Up @@ -231,10 +231,10 @@ class Chosen extends AbstractChosen


set_tab_index: (el) ->
if @form_field_jq.attr "tabindex"
ti = @form_field_jq.attr "tabindex"
@form_field_jq.attr "tabindex", -1
@search_field.attr "tabindex", ti
if @form_field.tabIndex
ti = @form_field.tabIndex
@form_field.tabIndex = -1
@search_field[0].tabIndex = ti
Copy link
Contributor

Choose a reason for hiding this comment

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

We should think about storing a reference to @search_field so we can move methods like this to AbstractChosen. Don't worry about doing that for this PR, though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're probably right, also, it is confusing having a _jq suffix for only one jQuery element. Maybe we should have a @search_field and @search_field_jq, but then we actually have to change that for all elements..


set_label_behavior: ->
@form_field_label = @form_field_jq.parents("label") # first check for a parent label
Expand Down Expand Up @@ -272,7 +272,7 @@ class Chosen extends AbstractChosen
if item.disabled
choice.addClass 'search-choice-disabled'
else
close_link = $('<a />', { href: '#', class: 'search-choice-close', rel: item.array_index })
close_link = $('<a />', { class: 'search-choice-close', 'data-option-array-index': item.array_index })
Copy link
Contributor

Choose a reason for hiding this comment

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

One unwanted consequence of removing the href is that the pointer cursor goes away. We either need to add to the CSS or put the href back (if we add it to CSS, we should also remove the href from the Prototype version.

Note: this is also a problem in #1377

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think a general style like .chzn-container a { cursor: pointer; } would suffice.

Copy link
Contributor

Choose a reason for hiding this comment

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

Alright, sold - add it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done!

close_link.click (evt) => this.choice_destroy_link_click(evt)
choice.append close_link

Expand All @@ -284,7 +284,7 @@ class Chosen extends AbstractChosen
this.choice_destroy $(evt.target) unless @is_disabled

choice_destroy: (link) ->
if this.result_deselect (link.attr "rel")
if this.result_deselect( link[0].getAttribute("data-option-array-index") )
this.show_search_field_default()

this.results_hide() if @is_multiple and this.choices_count() > 0 and @search_field.val().length < 1
Expand Down
2 changes: 1 addition & 1 deletion coffee/chosen.proto.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class @Chosen extends AbstractChosen
super()

# HTML Templates
@single_temp = new Template('<a href="javascript:void(0)" class="chzn-single chzn-default" tabindex="-1"><span>#{default}</span><div><b></b></div></a><div class="chzn-drop"><div class="chzn-search"><input type="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>')
@single_temp = new Template('<a class="chzn-single chzn-default" tabindex="-1"><span>#{default}</span><div><b></b></div></a><div class="chzn-drop"><div class="chzn-search"><input type="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>')
@multi_temp = new Template('<ul class="chzn-choices"><li class="search-field"><input type="text" value="#{default}" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chzn-drop"><ul class="chzn-results"></ul></div>')
@no_results_temp = new Template('<li class="no-results">' + @results_none_found + ' "<span>#{terms}</span>"</li>')

Expand Down
3 changes: 3 additions & 0 deletions sass/chosen.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ $chosen-sprite-retina: image-url('[email protected]');
&.chzn-with-drop .chzn-drop {
left: 0;
}
a{
cursor: pointer;
}
}
/* @end */

Expand Down