Permalink
Browse files

Updating chosen dependency

  • Loading branch information...
adrexia committed Nov 27, 2012
1 parent 6ce6f9a commit 715b62f790c39fff43561380d9af7c3ce2f488cc
@@ -56,8 +56,7 @@ write_chosen_javascript = (filename, body, trailing='') ->
// Copyright (c) 2011 Harvest http://getharvest.com
// MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md
-
-// based on version 0.9.8, applied a very simple patch that fix percentaage width support on select tag
+// based on version 0.9.8, applied a very simple patch that fixes percentage width support on select tag, and enables rise-up functionality
// This file is generated by `cake build`, do not edit it by hand.
#{body}#{trailing}
"""
@@ -175,4 +174,4 @@ task 'release', 'build, tag the current release, and push', ->
, untag_release
, untag_release
- , untag_release
+ , untag_release

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -9,7 +9,8 @@ $.fn.extend({
chosen: (options) ->
# Do no harm and return as soon as possible for unsupported browsers, namely IE6 and IE7
- return this if $.browser.msie and ($.browser.version is "6.0" or $.browser.version is "7.0")
+ # Continue on if running IE document type but in compatibility mode
+ return this if $.browser.msie and ($.browser.version is "6.0" or ($.browser.version is "7.0" and document.documentMode is 7 ))
this.each((input_field) ->
$this = $ this
$this.data('chosen', new Chosen(this, options)) unless $this.hasClass "chzn-done"
@@ -20,6 +21,7 @@ class Chosen extends AbstractChosen
setup: ->
@form_field_jq = $ @form_field
+ @current_value = @form_field_jq.val()
@is_rtl = @form_field_jq.hasClass "chzn-rtl"
finish_setup: ->
@@ -45,7 +47,7 @@ class Chosen extends AbstractChosen
if @is_multiple
container_div.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" style="left:-9000px;"><ul class="chzn-results"></ul></div>'
else
- container_div.html '<a href="javascript:void(0)" class="chzn-single chzn-default"><span>' + this.default_text + '</span><div><b></b></div></a><div class="chzn-drop" style="left:-9000px;"><div class="chzn-search"><input type="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>'
+ container_div.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" style="left:-9000px;"><div class="chzn-search"><input type="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>'
@form_field_jq.hide().after container_div
@container = ($ '#' + @container_id)
@@ -94,16 +96,19 @@ class Chosen extends AbstractChosen
@search_results.mouseout (evt) => this.search_results_mouseout(evt)
@form_field_jq.bind "liszt:updated", (evt) => this.results_update_field(evt)
+ @form_field_jq.bind "liszt:activate", (evt) => this.activate_field(evt)
+ @form_field_jq.bind "liszt:open", (evt) => this.container_mousedown(evt)
@search_field.blur (evt) => this.input_blur(evt)
@search_field.keyup (evt) => this.keyup_checker(evt)
@search_field.keydown (evt) => this.keydown_checker(evt)
+ @search_field.focus (evt) => this.input_focus(evt)
if @is_multiple
@search_choices.click (evt) => this.choices_click(evt)
- @search_field.focus (evt) => this.input_focus(evt)
else
@container.click (evt) => evt.preventDefault() # gobble click of anchor
+
search_field_disabled: ->
@is_disabled = @form_field_jq[0].disabled
@@ -136,7 +141,7 @@ class Chosen extends AbstractChosen
@pending_destroy_click = false
container_mouseup: (evt) ->
- this.results_reset(evt) if evt.target.nodeName is "ABBR"
+ this.results_reset(evt) if evt.target.nodeName is "ABBR" and not @is_disabled
blur_test: (evt) ->
this.close_field() if not @active_field and @container.hasClass "chzn-container-active"
@@ -159,10 +164,6 @@ class Chosen extends AbstractChosen
this.search_field_scale()
activate_field: ->
- if not @is_multiple and not @active_field
- @search_field.attr "tabindex", (@selected_item.attr "tabindex")
- @selected_item.attr "tabindex", -1
-
@container.addClass "chzn-container-active"
@active_field = true
@@ -185,8 +186,8 @@ class Chosen extends AbstractChosen
@search_choices.find("li.search-choice").remove()
@choices = 0
else if not @is_multiple
- @selected_item.find("span").text @default_text
- if @form_field.options.length <= @disable_search_threshold
+ @selected_item.addClass("chzn-default").find("span").text(@default_text)
+ if @disable_search or @form_field.options.length <= @disable_search_threshold
@container.addClass "chzn-container-single-nosearch"
else
@container.removeClass "chzn-container-single-nosearch"
@@ -246,15 +247,18 @@ class Chosen extends AbstractChosen
if @result_single_selected
this.result_do_highlight( @result_single_selected )
+ #patch applied: https://github.com/harvesthq/chosen/issues/300, add variable assignment dd_width
+ dd_width = this.container.width() - get_side_border_padding(@dropdown);
+
+
###
CALL CUSTOM FUNCTION: rise_up
# if rise-up true, reverse drop-up direction
###
rise = @rise_up(@container, @dropdown)
dd_top = if rise then -this.container.find('.chzn-drop').height() else if @is_multiple then @container.height() else (@container.height() - 1)
-
- #patch applied: https://github.com/harvesthq/chosen/issues/300, add variable assignment dd_width
- dd_width = this.container.width() - get_side_border_padding(@dropdown);
+
+ @form_field_jq.trigger("liszt:showing_dropdown", {chosen: this})
@dropdown.css {"top": dd_top + "px", "left":0}
@results_showing = true
@@ -270,6 +274,7 @@ class Chosen extends AbstractChosen
results_hide: ->
@selected_item.removeClass "chzn-single-with-drop" unless @is_multiple
this.result_clear_highlight()
+ @form_field_jq.trigger("liszt:hiding_dropdown", {chosen: this})
@dropdown.css {"left":"-9000px"}
@results_showing = false
@@ -278,12 +283,7 @@ class Chosen extends AbstractChosen
if @form_field_jq.attr "tabindex"
ti = @form_field_jq.attr "tabindex"
@form_field_jq.attr "tabindex", -1
-
- if @is_multiple
- @search_field.attr "tabindex", ti
- else
- @selected_item.attr "tabindex", ti
- @search_field.attr "tabindex", -1
+ @search_field.attr "tabindex", ti
show_search_field_default: ->
if @is_multiple and @choices < 1 and not @active_field
@@ -298,6 +298,7 @@ class Chosen extends AbstractChosen
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()
@@ -315,7 +316,11 @@ class Chosen extends AbstractChosen
choice_build: (item) ->
choice_id = @container_id + "_c_" + item.array_index
@choices += 1
- @search_container.before '<li class="search-choice" id="' + choice_id + '"><span>' + item.html + '</span><a href="javascript:void(0)" class="search-choice-close" rel="' + item.array_index + '"></a></li>'
+ if item.disabled
+ html = '<li class="search-choice search-choice-disabled" id="' + choice_id + '"><span>' + item.html + '</span></li>'
+ else
+ html = '<li class="search-choice" id="' + choice_id + '"><span>' + item.html + '</span><a href="javascript:void(0)" class="search-choice-close" rel="' + item.array_index + '"></a></li>'
+ @search_container.before html
link = $('#' + choice_id).find("a").first()
link.click (evt) => this.choice_destroy_link_click(evt)
@@ -328,22 +333,26 @@ class Chosen extends AbstractChosen
evt.stopPropagation
choice_destroy: (link) ->
- @choices -= 1
- this.show_search_field_default()
+ if this.result_deselect (link.attr "rel")
+ @choices -= 1
+ this.show_search_field_default()
- this.results_hide() if @is_multiple and @choices > 0 and @search_field.val().length < 1
+ this.results_hide() if @is_multiple and @choices > 0 and @search_field.val().length < 1
- this.result_deselect (link.attr "rel")
- link.parents('li').first().remove()
+ link.parents('li').first().remove()
- results_reset: (evt) ->
+ results_reset: ->
@form_field.options[0].selected = true
@selected_item.find("span").text @default_text
@selected_item.addClass("chzn-default") if not @is_multiple
this.show_search_field_default()
- $(evt.target).remove();
+ this.results_reset_cleanup()
@form_field_jq.trigger "change"
this.results_hide() if @active_field
+
+ results_reset_cleanup: ->
+ @current_value = @form_field_jq.val()
+ @selected_item.find("abbr").remove()
result_select: (evt) ->
if @result_highlight
@@ -377,7 +386,8 @@ class Chosen extends AbstractChosen
@search_field.val ""
- @form_field_jq.trigger "change"
+ @form_field_jq.trigger "change", {'selected': @form_field.options[item.options_index].value} if @is_multiple || @form_field_jq.val() != @current_value
+ @current_value = @form_field_jq.val()
this.search_field_scale()
result_activate: (el) ->
@@ -388,17 +398,23 @@ class Chosen extends AbstractChosen
result_deselect: (pos) ->
result_data = @results_data[pos]
- result_data.selected = false
- @form_field.options[result_data.options_index].selected = false
- result = $("#" + @container_id + "_o_" + pos)
- result.removeClass("result-selected").addClass("active-result").show()
+ if not @form_field.options[result_data.options_index].disabled
+ result_data.selected = false
+
+ @form_field.options[result_data.options_index].selected = false
+ result = $("#" + @container_id + "_o_" + pos)
+ result.removeClass("result-selected").addClass("active-result").show()
- this.result_clear_highlight()
- this.winnow_results()
+ this.result_clear_highlight()
+ this.winnow_results()
- @form_field_jq.trigger "change"
- this.search_field_scale()
+ @form_field_jq.trigger "change", {deselected: @form_field.options[result_data.options_index].value}
+ this.search_field_scale()
+
+ return true
+ else
+ return false
single_deselect_control_build: ->
@selected_item.find("span").first().after "<abbr class=\"search-choice-close\"></abbr>" if @allow_single_deselect and @selected_item.find("abbr").length < 1
@@ -509,8 +525,13 @@ class Chosen extends AbstractChosen
this.choice_destroy @pending_backstroke.find("a").first()
this.clear_backstroke()
else
- @pending_backstroke = @search_container.siblings("li.search-choice").last()
- @pending_backstroke.addClass "search-choice-focus"
+ 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"
clear_backstroke: ->
@pending_backstroke.removeClass "search-choice-focus" if @pending_backstroke
@@ -570,7 +591,7 @@ class Chosen extends AbstractChosen
###
rise = @rise_up(@container, @dropdown)
dd_top = if rise then -this.container.find('.chzn-drop').height() else @container.height()
-
+
@dropdown.css({"top": dd_top + "px"})
generate_random_id: ->
Oops, something went wrong.

0 comments on commit 715b62f

Please sign in to comment.