Skip to content

Commit

Permalink
fix lint errors
Browse files Browse the repository at this point in the history
update max_line_length to 120, because changing all to fit in 80 is
undoable
  • Loading branch information
koenpunt committed Oct 21, 2016
1 parent 9da4ee9 commit 4a90e6e
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 40 deletions.
44 changes: 31 additions & 13 deletions coffee/chosen.jquery.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ class Chosen extends AbstractChosen

@container = ($ "<div />", container_props)

if @is_multiple
@container.html '<ul class="chosen-choices"><li class="search-field"><input type="text" value="' + @default_text + '" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chosen-drop"><ul class="chosen-results"></ul></div>'
# coffeelint: disable=max_line_length
@container.html if @is_multiple
'<ul class="chosen-choices"><li class="search-field"><input type="text" value="' + @default_text + '" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chosen-drop"><ul class="chosen-results"></ul></div>'
else
@container.html '<a class="chosen-single chosen-default"><span>' + @default_text + '</span><div><b></b></div></a><div class="chosen-drop"><div class="chosen-search"><input type="text" autocomplete="off" /></div><ul class="chosen-results"></ul></div>'
'<a class="chosen-single chosen-default"><span>' + @default_text + '</span><div><b></b></div></a><div class="chosen-drop"><div class="chosen-search"><input type="text" autocomplete="off" /></div><ul class="chosen-results"></ul></div>'
# coffeelint: enable=max_line_length

@form_field_jq.hide().after @container
@dropdown = @container.find('div.chosen-drop').first()
Expand Down Expand Up @@ -137,9 +139,10 @@ class Chosen extends AbstractChosen
@search_field.val "" if @is_multiple
$(@container[0].ownerDocument).bind 'click.chosen', @click_test_action
this.results_show()
else if not @is_multiple and evt and (($(evt.target)[0] == @selected_item[0]) || $(evt.target).parents("a.chosen-single").length)
evt.preventDefault()
this.results_toggle()
else if not @is_multiple and evt
if $(evt.target)[0] == @selected_item[0] or $(evt.target).parents("a.chosen-single").length
evt.preventDefault()
this.results_toggle()

this.activate_field()

Expand Down Expand Up @@ -284,18 +287,25 @@ class Chosen extends AbstractChosen
@search_field.removeClass "default"

search_results_mouseup: (evt) ->
target = if $(evt.target).hasClass "active-result" then $(evt.target) else $(evt.target).parents(".active-result").first()
target = if $(evt.target).hasClass "active-result"
$(evt.target)
else
$(evt.target).parents(".active-result").first()
if target.length
@result_highlight = target
this.result_select(evt)
@search_field.focus()

search_results_mouseover: (evt) ->
target = if $(evt.target).hasClass "active-result" then $(evt.target) else $(evt.target).parents(".active-result").first()
target = if $(evt.target).hasClass "active-result"
$(evt.target)
else
$(evt.target).parents(".active-result").first()
this.result_do_highlight( target ) if target

search_results_mouseout: (evt) ->
this.result_clear_highlight() if $(evt.target).hasClass "active-result" or $(evt.target).parents('.active-result').first()
if $(evt.target).hasClass "active-result" or $(evt.target).parents('.active-result').first()
this.result_clear_highlight()

choice_build: (item) ->
choice = $('<li />', { class: "search-choice" }).html("<span>#{this.choice_label(item)}</span>")
Expand Down Expand Up @@ -372,7 +382,8 @@ class Chosen extends AbstractChosen
this.results_hide()
this.show_search_field_default()

this.trigger_form_field_change selected: @form_field.options[item.options_index].value if @is_multiple || @form_field.selectedIndex != @current_selectedIndex
if @is_multiple || @form_field.selectedIndex != @current_selectedIndex
this.trigger_form_field_change selected: @form_field.options[item.options_index].value
@current_selectedIndex = @form_field.selectedIndex

evt.preventDefault()
Expand Down Expand Up @@ -409,7 +420,8 @@ class Chosen extends AbstractChosen

single_deselect_control_build: ->
return unless @allow_single_deselect
@selected_item.find("span").first().after "<abbr class=\"search-choice-close\"></abbr>" unless @selected_item.find("abbr").length
unless @selected_item.find("abbr").length
@selected_item.find("span").first().after "<abbr class=\"search-choice-close\"></abbr>"
@selected_item.addClass("chosen-single-with-deselect")

get_search_field_value: ->
Expand All @@ -423,7 +435,10 @@ class Chosen extends AbstractChosen

winnow_results_set_highlight: ->
selected_results = if not @is_multiple then @search_results.find(".result-selected.active-result") else []
do_high = if selected_results.length then selected_results.first() else @search_results.find(".active-result").first()
do_high = if selected_results.length
selected_results.first()
else
@search_results.find(".active-result").first()

this.result_do_highlight do_high if do_high?

Expand Down Expand Up @@ -479,7 +494,10 @@ class Chosen extends AbstractChosen
w = 0

style_block = "position:absolute; left: -1000px; top: -1000px; display: none; white-space: pre;"
styles = ['font-size', 'font-style', 'font-weight', 'font-family', 'line-height', 'text-transform', 'letter-spacing']
styles = [
'font-size', 'font-style', 'font-weight', 'font-family',
'line-height', 'text-transform', 'letter-spacing'
]

for style in styles
style_block += style + ":" + @search_field.css(style) + ";"
Expand Down
48 changes: 29 additions & 19 deletions coffee/chosen.proto.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ class @Chosen extends AbstractChosen
set_default_values: ->
super()

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

set_up_html: ->
container_classes = ["chosen-container"]
Expand All @@ -24,7 +26,10 @@ class @Chosen extends AbstractChosen

container_props.id = @form_field.id.replace(/[^\w]/g, '_') + "_chosen" if @form_field.id.length

@container = if @is_multiple then new Element('div', container_props).update( @multi_temp.evaluate({ "default": @default_text}) ) else new Element('div', container_props).update( @single_temp.evaluate({ "default":@default_text }) )
@container = if @is_multiple
new Element('div', container_props).update( @multi_temp.evaluate({ "default": @default_text}) )
else
new Element('div', container_props).update( @single_temp.evaluate({ "default":@default_text }) )

@form_field.hide().insert({ after: @container })
@dropdown = @container.down('div.chosen-drop')
Expand Down Expand Up @@ -83,7 +88,7 @@ class @Chosen extends AbstractChosen
if @is_multiple
@search_choices.observe "click", (evt) => this.choices_click(evt)
else
@container.observe "click", (evt) => evt.preventDefault() # gobble click of anchor
@container.observe "click", (evt) -> evt.preventDefault() # gobble click of anchor

destroy: ->
@container.ownerDocument.stopObserving "click", @click_test_action
Expand Down Expand Up @@ -204,22 +209,22 @@ class @Chosen extends AbstractChosen
@parsing = false

result_do_highlight: (el) ->
this.result_clear_highlight()
this.result_clear_highlight()

@result_highlight = el
@result_highlight.addClassName "highlighted"
@result_highlight = el
@result_highlight.addClassName "highlighted"

maxHeight = parseInt @search_results.getStyle('maxHeight'), 10
visible_top = @search_results.scrollTop
visible_bottom = maxHeight + visible_top
maxHeight = parseInt @search_results.getStyle('maxHeight'), 10
visible_top = @search_results.scrollTop
visible_bottom = maxHeight + visible_top

high_top = @result_highlight.positionedOffset().top
high_bottom = high_top + @result_highlight.getHeight()
high_top = @result_highlight.positionedOffset().top
high_bottom = high_top + @result_highlight.getHeight()

if high_bottom >= visible_bottom
@search_results.scrollTop = if (high_bottom - maxHeight) > 0 then (high_bottom - maxHeight) else 0
else if high_top < visible_top
@search_results.scrollTop = high_top
if high_bottom >= visible_bottom
@search_results.scrollTop = if (high_bottom - maxHeight) > 0 then (high_bottom - maxHeight) else 0
else if high_top < visible_top
@search_results.scrollTop = high_top

result_clear_highlight: ->
@result_highlight.removeClassName('highlighted') if @result_highlight
Expand Down Expand Up @@ -399,7 +404,8 @@ class @Chosen extends AbstractChosen

single_deselect_control_build: ->
return unless @allow_single_deselect
@selected_item.down("span").insert { after: "<abbr class=\"search-choice-close\"></abbr>" } unless @selected_item.down("abbr")
unless @selected_item.down("abbr")
@selected_item.down("span").insert { after: "<abbr class=\"search-choice-close\"></abbr>" }
@selected_item.addClassName("chosen-single-with-deselect")

get_search_field_value: ->
Expand Down Expand Up @@ -456,7 +462,8 @@ class @Chosen extends AbstractChosen
this.clear_backstroke()
else
next_available_destroy = @search_container.siblings().last()
if next_available_destroy and next_available_destroy.hasClassName("search-choice") and not next_available_destroy.hasClassName("search-choice-disabled")
if next_available_destroy and next_available_destroy.hasClassName("search-choice") and
not next_available_destroy.hasClassName("search-choice-disabled")
@pending_backstroke = next_available_destroy
@pending_backstroke.addClassName("search-choice-focus") if @pending_backstroke
if @single_backstroke_delete
Expand All @@ -474,7 +481,10 @@ class @Chosen extends AbstractChosen
w = 0

style_block = "position:absolute; left: -1000px; top: -1000px; display: none; white-space: pre;"
styles = ['font-size', 'font-style', 'font-weight', 'font-family', 'line-height', 'text-transform', 'letter-spacing']
styles = [
'font-size', 'font-style', 'font-weight', 'font-family',
'line-height', 'text-transform', 'letter-spacing'
]

for style in styles
style_block += style + ":" + @search_field.getStyle(style) + ";"
Expand Down Expand Up @@ -502,7 +512,7 @@ class @Chosen extends AbstractChosen
evt = new Event(eventType, bubbles: true, cancelable: true)
catch
evt = document.createEvent('HTMLEvents')
evt.initEvent(eventType, true, true);
evt.initEvent(eventType, true, true)
element.dispatchEvent(evt)
else # Old IE:
element.fireEvent("on#{eventType}", document.createEventObject());
element.fireEvent("on#{eventType}", document.createEventObject())
19 changes: 12 additions & 7 deletions coffee/lib/abstract-chosen.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ class AbstractChosen
@results_showing = false
@result_highlighted = null
@is_rtl = @options.rtl || /\bchosen-rtl\b/.test(@form_field.className)
@allow_single_deselect = if @options.allow_single_deselect? and @form_field.options[0]? and @form_field.options[0].text is "" then @options.allow_single_deselect else false
@allow_single_deselect = if @options.allow_single_deselect? and @form_field.options[0]?.text is ""
@options.allow_single_deselect
else
false
@disable_search_threshold = @options.disable_search_threshold || 0
@disable_search = @options.disable_search || false
@enable_split_word_search = if @options.enable_split_word_search? then @options.enable_split_word_search else true
Expand All @@ -38,16 +41,17 @@ class AbstractChosen
@hide_results_on_select = if @options.hide_results_on_select? then @options.hide_results_on_select else true

set_default_text: ->
if @form_field.getAttribute("data-placeholder")
@default_text = @form_field.getAttribute("data-placeholder")
@default_text = if @form_field.getAttribute("data-placeholder")
@form_field.getAttribute("data-placeholder")
else if @is_multiple
@default_text = @options.placeholder_text_multiple || @options.placeholder_text || AbstractChosen.default_multiple_text
@options.placeholder_text_multiple || @options.placeholder_text || AbstractChosen.default_multiple_text
else
@default_text = @options.placeholder_text_single || @options.placeholder_text || AbstractChosen.default_single_text
@options.placeholder_text_single || @options.placeholder_text || AbstractChosen.default_single_text

@default_text = this.escape_html(@default_text)

@results_none_found = @form_field.getAttribute("data-no_results_text") || @options.no_results_text || AbstractChosen.default_no_result_text
@results_none_found = @form_field.getAttribute("data-no_results_text") ||
@options.no_results_text || AbstractChosen.default_no_result_text

choice_label: (item) ->
if @include_group_label_in_selected and item.group_label?
Expand Down Expand Up @@ -194,7 +198,8 @@ class AbstractChosen
if option.search_match
if searchText.length
startpos = option.search_text.search highlightRegex
text = option.search_text.substr(0, startpos + searchText.length) + '</em>' + option.search_text.substr(startpos + searchText.length)
text = option.search_text.substr(0, startpos + searchText.length) + '</em>' +
option.search_text.substr(startpos + searchText.length)
option.search_text = text.substr(0, startpos) + '<em>' + text.substr(startpos)

results_group.group_match = true if results_group?
Expand Down
2 changes: 1 addition & 1 deletion coffeelint.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"value": "unix"
},
"max_line_length": {
"value": 80,
"value": 120,
"level": "error",
"limitComments": true
},
Expand Down

0 comments on commit 4a90e6e

Please sign in to comment.