From 2197ca36127bc54651ca4b5c772ba5680fbcdad7 Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Sat, 22 Oct 2016 00:39:00 +0200 Subject: [PATCH] update coffeelint rules and code accordingly --- coffee/chosen.jquery.coffee | 154 +++++++++++----------- coffee/chosen.proto.coffee | 208 +++++++++++++++--------------- coffee/lib/abstract-chosen.coffee | 63 +++++---- coffee/lib/select-parser.coffee | 20 +-- coffeelint.json | 26 ++-- 5 files changed, 235 insertions(+), 236 deletions(-) diff --git a/coffee/chosen.jquery.coffee b/coffee/chosen.jquery.coffee index 3b642d2e766..5ec0eef386a 100644 --- a/coffee/chosen.jquery.coffee +++ b/coffee/chosen.jquery.coffee @@ -26,19 +26,19 @@ class Chosen extends AbstractChosen @current_selectedIndex = @form_field.selectedIndex set_up_html: -> - container_classes = ["chosen-container"] - container_classes.push "chosen-container-" + (if @is_multiple then "multi" else "single") + container_classes = ['chosen-container'] + container_classes.push 'chosen-container-' + (if @is_multiple then 'multi' else 'single') container_classes.push @form_field.className if @inherit_select_classes && @form_field.className - container_classes.push "chosen-rtl" if @is_rtl + container_classes.push 'chosen-rtl' if @is_rtl container_props = - 'class': container_classes.join ' ' - 'style': "width: #{this.container_width()};" - 'title': @form_field.title + class: container_classes.join ' ' + style: "width: #{this.container_width()};" + title: @form_field.title - container_props.id = @form_field.id.replace(/[^\w]/g, '_') + "_chosen" if @form_field.id.length + container_props.id = @form_field.id.replace(/[^\w]/g, '_') + '_chosen' if @form_field.id.length - @container = ($ "
", container_props) + @container = ($ '
', container_props) # coffeelint: disable=max_line_length @container.html if @is_multiple @@ -68,7 +68,7 @@ class Chosen extends AbstractChosen this.set_label_behavior() on_ready: -> - @form_field_jq.trigger("chosen:ready", {chosen: this}) + @form_field_jq.trigger('chosen:ready', { chosen: this }) register_observers: -> @container.bind 'touchstart.chosen', (evt) => this.container_mousedown(evt); evt.preventDefault() @@ -88,10 +88,10 @@ class Chosen extends AbstractChosen @search_results.bind 'touchmove.chosen', (evt) => this.search_results_touchmove(evt); return @search_results.bind 'touchend.chosen', (evt) => this.search_results_touchend(evt); return - @form_field_jq.bind "chosen:updated.chosen", (evt) => this.results_update_field(evt); return - @form_field_jq.bind "chosen:activate.chosen", (evt) => this.activate_field(evt); return - @form_field_jq.bind "chosen:open.chosen", (evt) => this.container_mousedown(evt); return - @form_field_jq.bind "chosen:close.chosen", (evt) => this.close_field(evt); return + @form_field_jq.bind 'chosen:updated.chosen', (evt) => this.results_update_field(evt); return + @form_field_jq.bind 'chosen:activate.chosen', (evt) => this.activate_field(evt); return + @form_field_jq.bind 'chosen:open.chosen', (evt) => this.container_mousedown(evt); return + @form_field_jq.bind 'chosen:close.chosen', (evt) => this.close_field(evt); return @search_field.bind 'blur.chosen', (evt) => this.input_blur(evt); return @search_field.bind 'keyup.chosen', (evt) => this.keyup_checker(evt); return @@ -121,33 +121,33 @@ class Chosen extends AbstractChosen if(@is_disabled) @container.addClass 'chosen-disabled' @search_field[0].disabled = true - @selected_item.unbind "focus.chosen", @activate_action if !@is_multiple + @selected_item.unbind 'focus.chosen', @activate_action if !@is_multiple this.close_field() else @container.removeClass 'chosen-disabled' @search_field[0].disabled = false - @selected_item.bind "focus.chosen", @activate_action if !@is_multiple + @selected_item.bind 'focus.chosen', @activate_action if !@is_multiple container_mousedown: (evt) -> return if @is_disabled - if evt and evt.type is "mousedown" and not @results_showing + if evt and evt.type is 'mousedown' and not @results_showing evt.preventDefault() - if not (evt? and ($ evt.target).hasClass "search-choice-close") + if not (evt? and ($ evt.target).hasClass 'search-choice-close') if not @active_field - @search_field.val "" if @is_multiple + @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 - if $(evt.target)[0] == @selected_item[0] or $(evt.target).parents("a.chosen-single").length + if $(evt.target)[0] == @selected_item[0] or $(evt.target).parents('a.chosen-single').length evt.preventDefault() this.results_toggle() this.activate_field() container_mouseup: (evt) -> - this.results_reset(evt) if evt.target.nodeName is "ABBR" and not @is_disabled + this.results_reset(evt) if evt.target.nodeName is 'ABBR' and not @is_disabled search_results_mousewheel: (evt) -> delta = evt.originalEvent.deltaY or -evt.originalEvent.wheelDelta or evt.originalEvent.detail if evt.originalEvent @@ -157,15 +157,15 @@ class Chosen extends AbstractChosen @search_results.scrollTop(delta + @search_results.scrollTop()) blur_test: (evt) -> - this.close_field() if not @active_field and @container.hasClass "chosen-container-active" + this.close_field() if not @active_field and @container.hasClass 'chosen-container-active' close_field: -> - $(@container[0].ownerDocument).unbind "click.chosen", @click_test_action + $(@container[0].ownerDocument).unbind 'click.chosen', @click_test_action @active_field = false this.results_hide() - @container.removeClass "chosen-container-active" + @container.removeClass 'chosen-container-active' this.clear_backstroke() this.show_search_field_default() @@ -175,7 +175,7 @@ class Chosen extends AbstractChosen activate_field: -> return if @is_disabled - @container.addClass "chosen-container-active" + @container.addClass 'chosen-container-active' @active_field = true @search_field.val(@search_field.val()) @@ -196,17 +196,17 @@ class Chosen extends AbstractChosen @results_data = SelectParser.select_to_array @form_field if @is_multiple - @search_choices.find("li.search-choice").remove() + @search_choices.find('li.search-choice').remove() else if not @is_multiple this.single_set_selected_text() if @disable_search or @form_field.options.length <= @disable_search_threshold @search_field[0].readOnly = true - @container.addClass "chosen-container-single-nosearch" + @container.addClass 'chosen-container-single-nosearch' else @search_field[0].readOnly = false - @container.removeClass "chosen-container-single-nosearch" + @container.removeClass 'chosen-container-single-nosearch' - this.update_results_content this.results_option_build({first:true}) + this.update_results_content this.results_option_build({ first: true }) this.search_field_disabled() this.show_search_field_default() @@ -219,9 +219,9 @@ class Chosen extends AbstractChosen this.result_clear_highlight() @result_highlight = el - @result_highlight.addClass "highlighted" + @result_highlight.addClass 'highlighted' - maxHeight = parseInt @search_results.css("maxHeight"), 10 + maxHeight = parseInt @search_results.css('maxHeight'), 10 visible_top = @search_results.scrollTop() visible_bottom = maxHeight + visible_top @@ -234,22 +234,22 @@ class Chosen extends AbstractChosen @search_results.scrollTop high_top result_clear_highlight: -> - @result_highlight.removeClass "highlighted" if @result_highlight + @result_highlight.removeClass 'highlighted' if @result_highlight @result_highlight = null results_show: -> if @is_multiple and @max_selected_options <= this.choices_count() - @form_field_jq.trigger("chosen:maxselected", {chosen: this}) + @form_field_jq.trigger('chosen:maxselected', { chosen: this }) return false - @container.addClass "chosen-with-drop" + @container.addClass 'chosen-with-drop' @results_showing = true @search_field.focus() @search_field.val this.get_search_field_value() this.winnow_results() - @form_field_jq.trigger("chosen:showing_dropdown", {chosen: this}) + @form_field_jq.trigger('chosen:showing_dropdown', { chosen: this }) update_results_content: (content) -> @search_results.html content @@ -258,8 +258,8 @@ class Chosen extends AbstractChosen if @results_showing this.result_clear_highlight() - @container.removeClass "chosen-with-drop" - @form_field_jq.trigger("chosen:hiding_dropdown", {chosen: this}) + @container.removeClass 'chosen-with-drop' + @form_field_jq.trigger('chosen:hiding_dropdown', { chosen: this }) @results_showing = false @@ -271,7 +271,7 @@ class Chosen extends AbstractChosen @search_field[0].tabIndex = ti set_label_behavior: -> - @form_field_label = @form_field_jq.parents("label") # first check for a parent label + @form_field_label = @form_field_jq.parents('label') # first check for a parent label if not @form_field_label.length and @form_field.id.length @form_field_label = $("label[for='#{@form_field.id}']") #next check for a for=#{id} @@ -281,34 +281,34 @@ class Chosen extends AbstractChosen show_search_field_default: -> if @is_multiple and this.choices_count() < 1 and not @active_field @search_field.val(@default_text) - @search_field.addClass "default" + @search_field.addClass 'default' else - @search_field.val("") - @search_field.removeClass "default" + @search_field.val('') + @search_field.removeClass 'default' search_results_mouseup: (evt) -> - target = if $(evt.target).hasClass "active-result" + target = if $(evt.target).hasClass 'active-result' $(evt.target) else - $(evt.target).parents(".active-result").first() + $(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" + target = if $(evt.target).hasClass 'active-result' $(evt.target) else - $(evt.target).parents(".active-result").first() + $(evt.target).parents('.active-result').first() this.result_do_highlight( target ) if target search_results_mouseout: (evt) -> - 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 = $('
  • ', { class: "search-choice" }).html("#{this.choice_label(item)}") + choice = $('
  • ', { class: 'search-choice' }).html("#{this.choice_label(item)}") if item.disabled choice.addClass 'search-choice-disabled' @@ -325,7 +325,7 @@ class Chosen extends AbstractChosen this.choice_destroy $(evt.target) unless @is_disabled choice_destroy: (link) -> - if this.result_deselect( link[0].getAttribute("data-option-array-index") ) + if this.result_deselect( link[0].getAttribute('data-option-array-index') ) if @active_field @search_field.focus() else @@ -348,7 +348,7 @@ class Chosen extends AbstractChosen results_reset_cleanup: -> @current_selectedIndex = @form_field.selectedIndex - @selected_item.find("abbr").remove() + @selected_item.find('abbr').remove() result_select: (evt) -> if @result_highlight @@ -357,17 +357,17 @@ class Chosen extends AbstractChosen this.result_clear_highlight() if @is_multiple and @max_selected_options <= this.choices_count() - @form_field_jq.trigger("chosen:maxselected", {chosen: this}) + @form_field_jq.trigger('chosen:maxselected', { chosen: this }) return false if @is_multiple - high.removeClass("active-result") + high.removeClass('active-result') else this.reset_single_select_options() - high.addClass("result-selected") + high.addClass('result-selected') - item = @results_data[ high[0].getAttribute("data-option-array-index") ] + item = @results_data[ high[0].getAttribute('data-option-array-index') ] item.selected = true @form_field.options[item.options_index].selected = true @@ -390,14 +390,14 @@ class Chosen extends AbstractChosen this.search_field_scale() - single_set_selected_text: (text=@default_text) -> + single_set_selected_text: (text = @default_text) -> if text is @default_text - @selected_item.addClass("chosen-default") + @selected_item.addClass('chosen-default') else this.single_deselect_control_build() - @selected_item.removeClass("chosen-default") + @selected_item.removeClass('chosen-default') - @selected_item.find("span").html(text) + @selected_item.find('span').html(text) result_deselect: (pos) -> result_data = @results_data[pos] @@ -420,9 +420,9 @@ class Chosen extends AbstractChosen single_deselect_control_build: -> return unless @allow_single_deselect - unless @selected_item.find("abbr").length - @selected_item.find("span").first().after "" - @selected_item.addClass("chosen-single-with-deselect") + unless @selected_item.find('abbr').length + @selected_item.find('span').first().after '' + @selected_item.addClass('chosen-single-with-deselect') get_search_field_value: -> @search_field.val() @@ -434,27 +434,27 @@ class Chosen extends AbstractChosen $('
    ').text(text).html() winnow_results_set_highlight: -> - selected_results = if not @is_multiple then @search_results.find(".result-selected.active-result") else [] + selected_results = if not @is_multiple then @search_results.find('.result-selected.active-result') else [] do_high = if selected_results.length selected_results.first() else - @search_results.find(".active-result").first() + @search_results.find('.active-result').first() this.result_do_highlight do_high if do_high? no_results: (terms) -> no_results_html = $('
  • ' + @results_none_found + ' ""
  • ') - no_results_html.find("span").first().html(terms) + no_results_html.find('span').first().html(terms) @search_results.append no_results_html - @form_field_jq.trigger("chosen:no_results", {chosen:this}) + @form_field_jq.trigger('chosen:no_results', { chosen: this }) no_results_clear: -> - @search_results.find(".no-results").remove() + @search_results.find('.no-results').remove() keydown_arrow: -> if @results_showing and @result_highlight - next_sib = @result_highlight.nextAll("li.active-result").first() + next_sib = @result_highlight.nextAll('li.active-result').first() this.result_do_highlight next_sib if next_sib else this.results_show() @@ -463,7 +463,7 @@ class Chosen extends AbstractChosen if not @results_showing and not @is_multiple this.results_show() else if @result_highlight - prev_sibs = @result_highlight.prevAll("li.active-result") + prev_sibs = @result_highlight.prevAll('li.active-result') if prev_sibs.length this.result_do_highlight prev_sibs.first() @@ -473,19 +473,19 @@ class Chosen extends AbstractChosen keydown_backstroke: -> if @pending_backstroke - this.choice_destroy @pending_backstroke.find("a").first() + this.choice_destroy @pending_backstroke.find('a').first() this.clear_backstroke() else - next_available_destroy = @search_container.siblings("li.search-choice").last() - if next_available_destroy.length and not next_available_destroy.hasClass("search-choice-disabled") + next_available_destroy = @search_container.siblings('li.search-choice').last() + if next_available_destroy.length and not next_available_destroy.hasClass('search-choice-disabled') @pending_backstroke = next_available_destroy if @single_backstroke_delete @keydown_backstroke() else - @pending_backstroke.addClass "search-choice-focus" + @pending_backstroke.addClass 'search-choice-focus' clear_backstroke: -> - @pending_backstroke.removeClass "search-choice-focus" if @pending_backstroke + @pending_backstroke.removeClass 'search-choice-focus' if @pending_backstroke @pending_backstroke = null search_field_scale: -> @@ -493,16 +493,16 @@ class Chosen extends AbstractChosen h = 0 w = 0 - style_block = "position:absolute; left: -1000px; top: -1000px; display: none; white-space: pre;" + 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' ] for style in styles - style_block += style + ":" + @search_field.css(style) + ";" + style_block += style + ':' + @search_field.css(style) + ';' - div = $('
    ', { 'style' : style_block }) + div = $('
    ', { style: style_block }) div.text this.get_search_field_value() $('body').append div @@ -514,8 +514,8 @@ class Chosen extends AbstractChosen if( w > f_width - 10 ) w = f_width - 10 - @search_field.css({'width': w + 'px'}) + @search_field.css({ width: w + 'px' }) trigger_form_field_change: (extra) -> - @form_field_jq.trigger "input", extra - @form_field_jq.trigger "change", extra + @form_field_jq.trigger 'input', extra + @form_field_jq.trigger 'change', extra diff --git a/coffee/chosen.proto.coffee b/coffee/chosen.proto.coffee index 47a74bffa4f..295ef6cbdbc 100644 --- a/coffee/chosen.proto.coffee +++ b/coffee/chosen.proto.coffee @@ -14,22 +14,22 @@ class @Chosen extends AbstractChosen # coffeelint: enable=max_line_length set_up_html: -> - container_classes = ["chosen-container"] - container_classes.push "chosen-container-" + (if @is_multiple then "multi" else "single") + container_classes = ['chosen-container'] + container_classes.push 'chosen-container-' + (if @is_multiple then 'multi' else 'single') container_classes.push @form_field.className if @inherit_select_classes && @form_field.className - container_classes.push "chosen-rtl" if @is_rtl + container_classes.push 'chosen-rtl' if @is_rtl container_props = - 'class': container_classes.join ' ' - 'style': "width: #{this.container_width()};" - 'title': @form_field.title + class: container_classes.join ' ' + style: "width: #{this.container_width()};" + title: @form_field.title - container_props.id = @form_field.id.replace(/[^\w]/g, '_') + "_chosen" if @form_field.id.length + container_props.id = @form_field.id.replace(/[^\w]/g, '_') + '_chosen' if @form_field.id.length - @container = if @is_multiple - new Element('div', container_props).update( @multi_temp.evaluate({ "default": @default_text}) ) + @container = new Element('div', container_props).update if @is_multiple + @multi_temp.evaluate({ default: @default_text }) else - new Element('div', container_props).update( @single_temp.evaluate({ "default":@default_text }) ) + @single_temp.evaluate({ default: @default_text }) @form_field.hide().insert({ after: @container }) @dropdown = @container.down('div.chosen-drop') @@ -52,46 +52,46 @@ class @Chosen extends AbstractChosen this.set_label_behavior() on_ready: -> - @form_field.fire("chosen:ready", {chosen: this}) + @form_field.fire('chosen:ready', { chosen: this }) register_observers: -> - @container.observe "touchstart", (evt) => this.container_mousedown(evt); evt.preventDefault() - @container.observe "touchend", (evt) => this.container_mouseup(evt); evt.preventDefault() - - @container.observe "mousedown", (evt) => this.container_mousedown(evt) - @container.observe "mouseup", (evt) => this.container_mouseup(evt) - @container.observe "mouseenter", (evt) => this.mouse_enter(evt) - @container.observe "mouseleave", (evt) => this.mouse_leave(evt) - - @search_results.observe "mouseup", (evt) => this.search_results_mouseup(evt) - @search_results.observe "mouseover", (evt) => this.search_results_mouseover(evt) - @search_results.observe "mouseout", (evt) => this.search_results_mouseout(evt) - @search_results.observe "mousewheel", (evt) => this.search_results_mousewheel(evt) - @search_results.observe "DOMMouseScroll", (evt) => this.search_results_mousewheel(evt) - - @search_results.observe "touchstart", (evt) => this.search_results_touchstart(evt) - @search_results.observe "touchmove", (evt) => this.search_results_touchmove(evt) - @search_results.observe "touchend", (evt) => this.search_results_touchend(evt) - - @form_field.observe "chosen:updated", (evt) => this.results_update_field(evt) - @form_field.observe "chosen:activate", (evt) => this.activate_field(evt) - @form_field.observe "chosen:open", (evt) => this.container_mousedown(evt) - @form_field.observe "chosen:close", (evt) => this.close_field(evt) - - @search_field.observe "blur", (evt) => this.input_blur(evt) - @search_field.observe "keyup", (evt) => this.keyup_checker(evt) - @search_field.observe "keydown", (evt) => this.keydown_checker(evt) - @search_field.observe "focus", (evt) => this.input_focus(evt) - @search_field.observe "cut", (evt) => this.clipboard_event_checker(evt) - @search_field.observe "paste", (evt) => this.clipboard_event_checker(evt) + @container.observe 'touchstart', (evt) => this.container_mousedown(evt); evt.preventDefault() + @container.observe 'touchend', (evt) => this.container_mouseup(evt); evt.preventDefault() + + @container.observe 'mousedown', (evt) => this.container_mousedown(evt) + @container.observe 'mouseup', (evt) => this.container_mouseup(evt) + @container.observe 'mouseenter', (evt) => this.mouse_enter(evt) + @container.observe 'mouseleave', (evt) => this.mouse_leave(evt) + + @search_results.observe 'mouseup', (evt) => this.search_results_mouseup(evt) + @search_results.observe 'mouseover', (evt) => this.search_results_mouseover(evt) + @search_results.observe 'mouseout', (evt) => this.search_results_mouseout(evt) + @search_results.observe 'mousewheel', (evt) => this.search_results_mousewheel(evt) + @search_results.observe 'DOMMouseScroll', (evt) => this.search_results_mousewheel(evt) + + @search_results.observe 'touchstart', (evt) => this.search_results_touchstart(evt) + @search_results.observe 'touchmove', (evt) => this.search_results_touchmove(evt) + @search_results.observe 'touchend', (evt) => this.search_results_touchend(evt) + + @form_field.observe 'chosen:updated', (evt) => this.results_update_field(evt) + @form_field.observe 'chosen:activate', (evt) => this.activate_field(evt) + @form_field.observe 'chosen:open', (evt) => this.container_mousedown(evt) + @form_field.observe 'chosen:close', (evt) => this.close_field(evt) + + @search_field.observe 'blur', (evt) => this.input_blur(evt) + @search_field.observe 'keyup', (evt) => this.keyup_checker(evt) + @search_field.observe 'keydown', (evt) => this.keydown_checker(evt) + @search_field.observe 'focus', (evt) => this.input_focus(evt) + @search_field.observe 'cut', (evt) => this.clipboard_event_checker(evt) + @search_field.observe 'paste', (evt) => this.clipboard_event_checker(evt) if @is_multiple - @search_choices.observe "click", (evt) => this.choices_click(evt) + @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 + @container.ownerDocument.stopObserving 'click', @click_test_action for event in ['chosen:updated', 'chosen:activate', 'chosen:open', 'chosen:close'] @form_field.stopObserving(event) @@ -103,7 +103,7 @@ class @Chosen extends AbstractChosen if @is_multiple @search_choices.stopObserving() - @container.select(".search-choice-close").each (choice) -> + @container.select('.search-choice-close').each (choice) -> choice.stopObserving() else @selected_item.stopObserving() @@ -119,31 +119,31 @@ class @Chosen extends AbstractChosen if(@is_disabled) @container.addClassName 'chosen-disabled' @search_field.disabled = true - @selected_item.stopObserving "focus", @activate_action if !@is_multiple + @selected_item.stopObserving 'focus', @activate_action if !@is_multiple this.close_field() else @container.removeClassName 'chosen-disabled' @search_field.disabled = false - @selected_item.observe "focus", @activate_action if !@is_multiple + @selected_item.observe 'focus', @activate_action if !@is_multiple container_mousedown: (evt) -> return if @is_disabled - if evt and evt.type is "mousedown" and not @results_showing + if evt and evt.type is 'mousedown' and not @results_showing evt.stop() - if not (evt? and evt.target.hasClassName "search-choice-close") + if not (evt? and evt.target.hasClassName 'search-choice-close') if not @active_field @search_field.clear() if @is_multiple - @container.ownerDocument.observe "click", @click_test_action + @container.ownerDocument.observe 'click', @click_test_action this.results_show() - else if not @is_multiple and evt and (evt.target is @selected_item || evt.target.up("a.chosen-single")) + else if not @is_multiple and evt and (evt.target is @selected_item || evt.target.up('a.chosen-single')) this.results_toggle() this.activate_field() container_mouseup: (evt) -> - this.results_reset(evt) if evt.target.nodeName is "ABBR" and not @is_disabled + this.results_reset(evt) if evt.target.nodeName is 'ABBR' and not @is_disabled search_results_mousewheel: (evt) -> delta = evt.deltaY or -evt.wheelDelta or evt.detail @@ -153,15 +153,15 @@ class @Chosen extends AbstractChosen @search_results.scrollTop = delta + @search_results.scrollTop blur_test: (evt) -> - this.close_field() if not @active_field and @container.hasClassName("chosen-container-active") + this.close_field() if not @active_field and @container.hasClassName('chosen-container-active') close_field: -> - @container.ownerDocument.stopObserving "click", @click_test_action + @container.ownerDocument.stopObserving 'click', @click_test_action @active_field = false this.results_hide() - @container.removeClassName "chosen-container-active" + @container.removeClassName 'chosen-container-active' this.clear_backstroke() this.show_search_field_default() @@ -171,7 +171,7 @@ class @Chosen extends AbstractChosen activate_field: -> return if @is_disabled - @container.addClassName "chosen-container-active" + @container.addClassName 'chosen-container-active' @active_field = true @search_field.value = this.get_search_field_value() @@ -190,17 +190,17 @@ class @Chosen extends AbstractChosen @results_data = SelectParser.select_to_array @form_field if @is_multiple - @search_choices.select("li.search-choice").invoke("remove") + @search_choices.select('li.search-choice').invoke('remove') else if not @is_multiple this.single_set_selected_text() if @disable_search or @form_field.options.length <= @disable_search_threshold @search_field.readOnly = true - @container.addClassName "chosen-container-single-nosearch" + @container.addClassName 'chosen-container-single-nosearch' else @search_field.readOnly = false - @container.removeClassName "chosen-container-single-nosearch" + @container.removeClassName 'chosen-container-single-nosearch' - this.update_results_content this.results_option_build({first:true}) + this.update_results_content this.results_option_build({ first: true }) this.search_field_disabled() this.show_search_field_default() @@ -212,7 +212,7 @@ class @Chosen extends AbstractChosen this.result_clear_highlight() @result_highlight = el - @result_highlight.addClassName "highlighted" + @result_highlight.addClassName 'highlighted' maxHeight = parseInt @search_results.getStyle('maxHeight'), 10 visible_top = @search_results.scrollTop @@ -232,17 +232,17 @@ class @Chosen extends AbstractChosen results_show: -> if @is_multiple and @max_selected_options <= this.choices_count() - @form_field.fire("chosen:maxselected", {chosen: this}) + @form_field.fire('chosen:maxselected', { chosen: this }) return false - @container.addClassName "chosen-with-drop" + @container.addClassName 'chosen-with-drop' @results_showing = true @search_field.focus() @search_field.value = this.get_search_field_value() this.winnow_results() - @form_field.fire("chosen:showing_dropdown", {chosen: this}) + @form_field.fire('chosen:showing_dropdown', { chosen: this }) update_results_content: (content) -> @search_results.update content @@ -251,8 +251,8 @@ class @Chosen extends AbstractChosen if @results_showing this.result_clear_highlight() - @container.removeClassName "chosen-with-drop" - @form_field.fire("chosen:hiding_dropdown", {chosen: this}) + @container.removeClassName 'chosen-with-drop' + @form_field.fire('chosen:hiding_dropdown', { chosen: this }) @results_showing = false @@ -264,43 +264,43 @@ class @Chosen extends AbstractChosen @search_field.tabIndex = ti set_label_behavior: -> - @form_field_label = @form_field.up("label") # first check for a parent label + @form_field_label = @form_field.up('label') # first check for a parent label if not @form_field_label? @form_field_label = $$("label[for='#{@form_field.id}']").first() #next check for a for=#{id} if @form_field_label? - @form_field_label.observe "click", this.label_click_handler + @form_field_label.observe 'click', this.label_click_handler show_search_field_default: -> if @is_multiple and this.choices_count() < 1 and not @active_field @search_field.value = @default_text - @search_field.addClassName "default" + @search_field.addClassName 'default' else - @search_field.value = "" - @search_field.removeClassName "default" + @search_field.value = '' + @search_field.removeClassName 'default' search_results_mouseup: (evt) -> - target = if evt.target.hasClassName("active-result") then evt.target else evt.target.up(".active-result") + target = if evt.target.hasClassName('active-result') then evt.target else evt.target.up('.active-result') if target @result_highlight = target this.result_select(evt) @search_field.focus() search_results_mouseover: (evt) -> - target = if evt.target.hasClassName("active-result") then evt.target else evt.target.up(".active-result") + target = if evt.target.hasClassName('active-result') then evt.target else evt.target.up('.active-result') this.result_do_highlight( target ) if target search_results_mouseout: (evt) -> this.result_clear_highlight() if evt.target.hasClassName('active-result') or evt.target.up('.active-result') choice_build: (item) -> - choice = new Element('li', { class: "search-choice" }).update("#{this.choice_label(item)}") + choice = new Element('li', { class: 'search-choice' }).update("#{this.choice_label(item)}") if item.disabled choice.addClassName 'search-choice-disabled' else close_link = new Element('a', { href: '#', class: 'search-choice-close', rel: item.array_index }) - close_link.observe "click", (evt) => this.choice_destroy_link_click(evt) + close_link.observe 'click', (evt) => this.choice_destroy_link_click(evt) choice.insert close_link @search_container.insert { before: choice } @@ -311,7 +311,7 @@ class @Chosen extends AbstractChosen this.choice_destroy evt.target unless @is_disabled choice_destroy: (link) -> - if this.result_deselect link.readAttribute("rel") + if this.result_deselect link.readAttribute('rel') if @active_field @search_field.focus() else @@ -334,7 +334,7 @@ class @Chosen extends AbstractChosen results_reset_cleanup: -> @current_selectedIndex = @form_field.selectedIndex - deselect_trigger = @selected_item.down("abbr") + deselect_trigger = @selected_item.down('abbr') deselect_trigger.remove() if(deselect_trigger) result_select: (evt) -> @@ -343,17 +343,17 @@ class @Chosen extends AbstractChosen this.result_clear_highlight() if @is_multiple and @max_selected_options <= this.choices_count() - @form_field.fire("chosen:maxselected", {chosen: this}) + @form_field.fire('chosen:maxselected', { chosen: this }) return false if @is_multiple - high.removeClassName("active-result") + high.removeClassName('active-result') else this.reset_single_select_options() - high.addClassName("result-selected") + high.addClassName('result-selected') - item = @results_data[ high.getAttribute("data-option-array-index") ] + item = @results_data[ high.getAttribute('data-option-array-index') ] item.selected = true @form_field.options[item.options_index].selected = true @@ -375,14 +375,14 @@ class @Chosen extends AbstractChosen this.search_field_scale() - single_set_selected_text: (text=@default_text) -> + single_set_selected_text: (text = @default_text) -> if text is @default_text - @selected_item.addClassName("chosen-default") + @selected_item.addClassName('chosen-default') else this.single_deselect_control_build() - @selected_item.removeClassName("chosen-default") + @selected_item.removeClassName('chosen-default') - @selected_item.down("span").update(text) + @selected_item.down('span').update(text) result_deselect: (pos) -> result_data = @results_data[pos] @@ -404,9 +404,9 @@ class @Chosen extends AbstractChosen single_deselect_control_build: -> return unless @allow_single_deselect - unless @selected_item.down("abbr") - @selected_item.down("span").insert { after: "" } - @selected_item.addClassName("chosen-single-with-deselect") + unless @selected_item.down('abbr') + @selected_item.down('span').insert { after: '' } + @selected_item.addClassName('chosen-single-with-deselect') get_search_field_value: -> @search_field.value @@ -419,20 +419,20 @@ class @Chosen extends AbstractChosen winnow_results_set_highlight: -> if not @is_multiple - do_high = @search_results.down(".result-selected.active-result") + do_high = @search_results.down('.result-selected.active-result') if not do_high? - do_high = @search_results.down(".active-result") + do_high = @search_results.down('.active-result') this.result_do_highlight do_high if do_high? no_results: (terms) -> @search_results.insert @no_results_temp.evaluate( terms: terms ) - @form_field.fire("chosen:no_results", {chosen: this}) + @form_field.fire('chosen:no_results', { chosen: this }) no_results_clear: -> nr = null - nr.remove() while nr = @search_results.down(".no-results") + nr.remove() while nr = @search_results.down('.no-results') keydown_arrow: -> @@ -447,7 +447,7 @@ class @Chosen extends AbstractChosen this.results_show() else if @result_highlight sibs = @result_highlight.previousSiblings() - actives = @search_results.select("li.active-result") + actives = @search_results.select('li.active-result') prevs = sibs.intersect(actives) if prevs.length @@ -458,21 +458,21 @@ class @Chosen extends AbstractChosen keydown_backstroke: -> if @pending_backstroke - this.choice_destroy @pending_backstroke.down("a") + this.choice_destroy @pending_backstroke.down('a') 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 + @pending_backstroke.addClassName('search-choice-focus') if @pending_backstroke if @single_backstroke_delete @keydown_backstroke() else - @pending_backstroke.addClassName("search-choice-focus") + @pending_backstroke.addClassName('search-choice-focus') clear_backstroke: -> - @pending_backstroke.removeClassName("search-choice-focus") if @pending_backstroke + @pending_backstroke.removeClassName('search-choice-focus') if @pending_backstroke @pending_backstroke = null search_field_scale: -> @@ -480,16 +480,16 @@ class @Chosen extends AbstractChosen h = 0 w = 0 - style_block = "position:absolute; left: -1000px; top: -1000px; display: none; white-space: pre;" + 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' ] for style in styles - style_block += style + ":" + @search_field.getStyle(style) + ";" + style_block += style + ':' + @search_field.getStyle(style) + ';' - div = new Element('div', { 'style' : style_block }).update(this.get_search_field_value().escapeHTML()) + div = new Element('div', { style: style_block }).update(this.get_search_field_value().escapeHTML()) document.body.appendChild(div) w = Element.measure(div, 'width') + 25 @@ -497,12 +497,12 @@ class @Chosen extends AbstractChosen f_width = @container.getWidth() - if( w > f_width-10 ) + if( w > f_width - 10 ) w = f_width - 10 - @search_field.setStyle({'width': w + 'px'}) + @search_field.setStyle({ width: w + 'px' }) - trigger_form_field_change: -> + trigger_form_field_change: -> triggerHtmlEvent @form_field, 'input' triggerHtmlEvent @form_field, 'change' diff --git a/coffee/lib/abstract-chosen.coffee b/coffee/lib/abstract-chosen.coffee index f2dc8bd7602..a7a918e1b00 100644 --- a/coffee/lib/abstract-chosen.coffee +++ b/coffee/lib/abstract-chosen.coffee @@ -1,6 +1,6 @@ class AbstractChosen - constructor: (@form_field, @options={}) -> + constructor: (@form_field, @options = {}) -> return unless AbstractChosen.browser_is_supported() @is_multiple = @form_field.multiple this.set_default_text() @@ -21,7 +21,7 @@ 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]?.text is "" + @allow_single_deselect = if @options.allow_single_deselect? and @form_field.options[0]?.text is '' @options.allow_single_deselect else false @@ -41,8 +41,8 @@ class AbstractChosen @hide_results_on_select = if @options.hide_results_on_select? then @options.hide_results_on_select else true set_default_text: -> - @default_text = if @form_field.getAttribute("data-placeholder") - @form_field.getAttribute("data-placeholder") + @default_text = if @form_field.getAttribute('data-placeholder') + @form_field.getAttribute('data-placeholder') else if @is_multiple @options.placeholder_text_multiple || @options.placeholder_text || AbstractChosen.default_multiple_text else @@ -50,7 +50,7 @@ class AbstractChosen @default_text = this.escape_html(@default_text) - @results_none_found = @form_field.getAttribute("data-no_results_text") || + @results_none_found = @form_field.getAttribute('data-no_results_text') || @options.no_results_text || AbstractChosen.default_no_result_text choice_label: (item) -> @@ -110,16 +110,16 @@ class AbstractChosen return '' unless this.include_option_in_results(option) classes = [] - classes.push "active-result" if !option.disabled and !(option.selected and @is_multiple) - classes.push "disabled-result" if option.disabled and !(option.selected and @is_multiple) - classes.push "result-selected" if option.selected - classes.push "group-option" if option.group_array_index? - classes.push option.classes if option.classes != "" - - option_el = document.createElement("li") - option_el.className = classes.join(" ") + classes.push 'active-result' if !option.disabled and !(option.selected and @is_multiple) + classes.push 'disabled-result' if option.disabled and !(option.selected and @is_multiple) + classes.push 'result-selected' if option.selected + classes.push 'group-option' if option.group_array_index? + classes.push option.classes if option.classes != '' + + option_el = document.createElement('li') + option_el.className = classes.join(' ') option_el.style.cssText = option.style - option_el.setAttribute("data-option-array-index", option.array_index) + option_el.setAttribute('data-option-array-index', option.array_index) option_el.innerHTML = option.search_text option_el.title = option.title if option.title @@ -130,11 +130,11 @@ class AbstractChosen return '' unless group.active_options > 0 classes = [] - classes.push "group-result" + classes.push 'group-result' classes.push group.classes if group.classes - group_el = document.createElement("li") - group_el.className = classes.join(" ") + group_el = document.createElement('li') + group_el.className = classes.join(' ') group_el.innerHTML = group.search_text group_el.title = group.title if group.title @@ -147,7 +147,7 @@ class AbstractChosen this.results_build() this.winnow_results() if @results_showing - reset_single_select_options: () -> + reset_single_select_options: -> for result in @results_data result.selected = false if result.selected @@ -169,7 +169,7 @@ class AbstractChosen results = 0 searchText = this.get_search_text() - escapedSearchText = searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") + escapedSearchText = searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&') regex = this.get_search_regex(escapedSearchText) highlightRegex = this.get_highlight_regex(escapedSearchText) @@ -210,28 +210,28 @@ class AbstractChosen this.result_clear_highlight() if results < 1 and searchText.length - this.update_results_content "" + this.update_results_content '' this.no_results searchText else this.update_results_content this.results_option_build() this.winnow_results_set_highlight() get_search_regex: (escaped_search_string) -> - regex_anchor = if @search_contains then "" else "^" - regex_flag = if @case_sensitive_search then "" else "i" + regex_anchor = if @search_contains then '' else '^' + regex_flag = if @case_sensitive_search then '' else 'i' new RegExp(regex_anchor + escaped_search_string, regex_flag) get_highlight_regex: (escaped_search_string) -> - regex_anchor = if @search_contains then "" else "\\b" - regex_flag = if @case_sensitive_search then "" else "i" + regex_anchor = if @search_contains then '' else '\\b' + regex_flag = if @case_sensitive_search then '' else 'i' new RegExp(regex_anchor + escaped_search_string, regex_flag) search_string_match: (search_string, regex) -> if regex.test search_string return true - else if @enable_split_word_search and (search_string.indexOf(" ") >= 0 or search_string.indexOf("[") == 0) + else if @enable_split_word_search and (search_string.indexOf(' ') >= 0 or search_string.indexOf('[') == 0) #TODO: replace this substitution of /\[\]/ with a list of characters to skip. - parts = search_string.replace(/\[|\]/g, "").split(" ") + parts = search_string.replace(/\[|\]/g, '').split(' ') if parts.length for part in parts if regex.test part @@ -334,14 +334,14 @@ class AbstractChosen outerHTML: (element) -> return element.outerHTML if element.outerHTML - tmp = document.createElement("div") + tmp = document.createElement('div') tmp.appendChild(element) tmp.innerHTML # class methods and variables ============================================================ @browser_is_supported: -> - if "Microsoft Internet Explorer" is window.navigator.appName + if 'Microsoft Internet Explorer' is window.navigator.appName return document.documentMode >= 8 if /iP(od|hone)/i.test(window.navigator.userAgent) or /IEMobile/i.test(window.navigator.userAgent) or @@ -352,7 +352,6 @@ class AbstractChosen return false return true - @default_multiple_text: "Select Some Options" - @default_single_text: "Select an Option" - @default_no_result_text: "No results match" - + @default_multiple_text: 'Select Some Options' + @default_single_text: 'Select an Option' + @default_no_result_text: 'No results match' diff --git a/coffee/lib/select-parser.coffee b/coffee/lib/select-parser.coffee index 3cd0637b2d0..47b9cb1dd01 100644 --- a/coffee/lib/select-parser.coffee +++ b/coffee/lib/select-parser.coffee @@ -5,7 +5,7 @@ class SelectParser @parsed = [] add_node: (child) -> - if child.nodeName.toUpperCase() is "OPTGROUP" + if child.nodeName.toUpperCase() is 'OPTGROUP' this.add_group child else this.add_option child @@ -23,8 +23,8 @@ class SelectParser this.add_option( option, group_position, group.disabled ) for option in group.childNodes add_option: (option, group_position, group_disabled) -> - if option.nodeName.toUpperCase() is "OPTION" - if option.text != "" + if option.nodeName.toUpperCase() is 'OPTION' + if option.text != '' if group_position? @parsed[group_position].children += 1 @parsed.push @@ -49,18 +49,18 @@ class SelectParser escapeExpression: (text) -> if not text? or text is false - return "" + return '' unless /[\&\<\>\"\'\`]/.test(text) return text map = - "<": "<" - ">": ">" - '"': """ - "'": "'" - "`": "`" + '<': '<' + '>': '>' + '"': '"' + "'": ''' + '`': '`' unsafe_chars = /&(?!\w+;)|[\<\>\"\'\`]/g text.replace unsafe_chars, (chr) -> - map[chr] || "&" + map[chr] || '&' SelectParser.select_to_array = (select) -> parser = new SelectParser() diff --git a/coffeelint.json b/coffeelint.json index f341fdab70f..0f5132a5e94 100644 --- a/coffeelint.json +++ b/coffeelint.json @@ -1,10 +1,10 @@ { "arrow_spacing": { - "level": "ignore" + "level": "error" }, "braces_spacing": { - "level": "ignore", - "spaces": 0, + "level": "error", + "spaces": 1, "empty_object_spaces": 0 }, "camel_case_classes": { @@ -14,10 +14,10 @@ "level": "error" }, "colon_assignment_spacing": { - "level": "ignore", + "level": "error", "spacing": { "left": 0, - "right": 0 + "right": 1 } }, "cyclomatic_complexity": { @@ -34,7 +34,7 @@ "level": "warn" }, "eol_last": { - "level": "ignore" + "level": "error" }, "indentation": { "value": 2, @@ -68,7 +68,7 @@ "level": "ignore" }, "no_empty_param_list": { - "level": "ignore" + "level": "warn" }, "no_implicit_braces": { "level": "ignore", @@ -79,7 +79,7 @@ "strict": true }, "no_interpolation_in_single_quotes": { - "level": "ignore" + "level": "warn" }, "no_nested_string_interpolation": { "level": "warn" @@ -91,7 +91,7 @@ "level": "warn" }, "no_stand_alone_at": { - "level": "ignore" + "level": "error" }, "no_tabs": { "level": "error" @@ -111,10 +111,10 @@ "allowed_in_empty_lines": true }, "no_unnecessary_double_quotes": { - "level": "ignore" + "level": "error" }, "no_unnecessary_fat_arrows": { - "level": "warn" + "level": "error" }, "non_empty_constructor_needs_parens": { "level": "ignore" @@ -124,10 +124,10 @@ "doubleNotLevel": "ignore" }, "space_operators": { - "level": "ignore" + "level": "error" }, "spacing_after_comma": { - "level": "ignore" + "level": "error" }, "transform_messes_up_line_numbers": { "level": "warn"