Permalink
Browse files

rake update-chosen (0.9.10)

  • Loading branch information...
1 parent 5eb2bb8 commit f69cfbfa455715c690f911919a4dbbd918d171cb @tsechingho committed Dec 9, 2012
@@ -1,6 +1,6 @@
module Chosen
module Rails
- VERSION = "0.9.9"
- CHOSEN_VERSION = "0.9.9"
+ VERSION = "0.9.10"
+ CHOSEN_VERSION = "0.9.10"
end
end
@@ -32,11 +32,13 @@ class Chosen extends AbstractChosen
@f_width = @form_field_jq.outerWidth()
- container_div = ($ "<div />", {
+ container_props =
id: @container_id
class: "chzn-container#{ if @is_rtl then ' chzn-rtl' else '' }"
style: 'width: ' + (@f_width) + 'px;' #use parens around @f_width so coffeescript doesn't think + ' px' is a function parameter
- })
+ title: @form_field.title
+
+ container_div = ($ "<div />", container_props)
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>'
@@ -95,7 +97,7 @@ class Chosen extends AbstractChosen
@search_choices.click (evt) => this.choices_click(evt)
else
@container.click (evt) => evt.preventDefault() # gobble click of anchor
-
+
search_field_disabled: ->
@is_disabled = @form_field_jq[0].disabled
@@ -113,7 +115,7 @@ class Chosen extends AbstractChosen
if !@is_disabled
target_closelink = if evt? then ($ evt.target).hasClass "search-choice-close" else false
if evt and evt.type is "mousedown" and not @results_showing
- evt.stopPropagation()
+ evt.preventDefault()
if not @pending_destroy_click and not target_closelink
if not @active_field
@search_field.val "" if @is_multiple
@@ -316,6 +318,8 @@ class Chosen extends AbstractChosen
link.parents('li').first().remove()
+ this.search_field_scale()
+
results_reset: ->
@form_field.options[0].selected = true
@selected_item.find("span").text @default_text
@@ -324,7 +328,7 @@ class Chosen extends AbstractChosen
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()
@@ -357,7 +361,7 @@ class Chosen extends AbstractChosen
@selected_item.find("span").first().text item.text
this.single_deselect_control_build() if @allow_single_deselect
- this.results_hide() unless evt.metaKey and @is_multiple
+ this.results_hide() unless (evt.metaKey or evt.ctrlKey) and @is_multiple
@search_field.val ""
@@ -376,7 +380,7 @@ class Chosen extends AbstractChosen
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()
@@ -386,7 +390,7 @@ class Chosen extends AbstractChosen
@form_field_jq.trigger "change", {deselected: @form_field.options[result_data.options_index].value}
this.search_field_scale()
-
+
return true
else
return false
@@ -416,7 +420,7 @@ class Chosen extends AbstractChosen
if regex.test option.html
found = true
results += 1
- else if option.html.indexOf(" ") >= 0 or option.html.indexOf("[") == 0
+ else if @search_split_words and (option.html.indexOf(" ") >= 0 or option.html.indexOf("[") == 0)
#TODO: replace this substitution of /\[\]/ with a list of characters to skip.
parts = option.html.replace(/\[|\]/g, "").split(" ")
if parts.length
@@ -569,6 +573,8 @@ class Chosen extends AbstractChosen
string += this.generate_random_char()
string
+root.Chosen = Chosen
+
get_side_border_padding = (elmt) ->
side_border_padding = elmt.outerWidth() - elmt.width()
@@ -15,7 +15,7 @@ class Chosen extends AbstractChosen
set_default_values: ->
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" style="left:-9000px;"><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" style="left:-9000px;"><ul class="chzn-results"></ul></div>')
@@ -25,32 +25,33 @@ class Chosen extends AbstractChosen
set_up_html: ->
@container_id = @form_field.identify().replace(/[^\w]/g, '_') + "_chzn"
-
+
@f_width = if @form_field.getStyle("width") then parseInt @form_field.getStyle("width"), 10 else @form_field.getWidth()
-
+
container_props =
'id': @container_id
'class': "chzn-container#{ if @is_rtl then ' chzn-rtl' else '' }"
'style': 'width: ' + (@f_width) + 'px' #use parens around @f_width so coffeescript doesn't think + ' px' is a function parameter
+ 'title': @form_field.title
base_template = 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 }) )
@form_field.hide().insert({ after: base_template })
@container = $(@container_id)
@container.addClassName( "chzn-container-" + (if @is_multiple then "multi" else "single") )
@dropdown = @container.down('div.chzn-drop')
-
+
dd_top = @container.getHeight()
dd_width = (@f_width - get_side_border_padding(@dropdown))
-
+
@dropdown.setStyle({"width": dd_width + "px", "top": dd_top + "px"})
@search_field = @container.down('input')
@search_results = @container.down('ul.chzn-results')
this.search_field_scale()
@search_no_results = @container.down('li.no-results')
-
+
if @is_multiple
@search_choices = @container.down('ul.chzn-choices')
@search_container = @container.down('li.search-field')
@@ -59,7 +60,7 @@ class Chosen extends AbstractChosen
@selected_item = @container.down('.chzn-single')
sf_width = dd_width - get_side_border_padding(@search_container) - get_side_border_padding(@search_field)
@search_field.setStyle( {"width" : sf_width + "px"} )
-
+
this.results_build()
this.set_tab_index()
@form_field.fire("liszt:ready", {chosen: this})
@@ -69,11 +70,11 @@ class Chosen extends AbstractChosen
@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)
-
+
@form_field.observe "liszt:updated", (evt) => this.results_update_field(evt)
@form_field.observe "liszt:activate", (evt) => this.activate_field(evt)
@form_field.observe "liszt:open", (evt) => this.container_mousedown(evt)
@@ -116,7 +117,7 @@ class Chosen extends AbstractChosen
this.activate_field()
else
@pending_destroy_click = false
-
+
container_mouseup: (evt) ->
this.results_reset(evt) if evt.target.nodeName is "ABBR" and not @is_disabled
@@ -125,7 +126,7 @@ class Chosen extends AbstractChosen
close_field: ->
document.stopObserving "click", @click_test_action
-
+
@active_field = false
this.results_hide()
@@ -178,7 +179,7 @@ class Chosen extends AbstractChosen
this.search_field_disabled()
this.show_search_field_default()
this.search_field_scale()
-
+
@search_results.update content
@parsing = false
@@ -189,7 +190,7 @@ class Chosen extends AbstractChosen
'<li id="' + group.dom_id + '" class="group-result">' + group.label.escapeHTML() + '</li>'
else
""
-
+
result_do_highlight: (el) ->
this.result_clear_highlight()
@@ -207,7 +208,7 @@ class Chosen extends AbstractChosen
@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
@result_highlight = null
@@ -303,6 +304,8 @@ class Chosen extends AbstractChosen
link.up('li').remove()
+ this.search_field_scale()
+
results_reset: ->
@form_field.options[0].selected = true
@selected_item.down("span").update(@default_text)
@@ -316,7 +319,7 @@ class Chosen extends AbstractChosen
@current_value = @form_field.value
deselect_trigger = @selected_item.down("abbr")
deselect_trigger.remove() if(deselect_trigger)
-
+
result_select: (evt) ->
if @result_highlight
high = @result_highlight
@@ -328,9 +331,9 @@ class Chosen extends AbstractChosen
@search_results.descendants(".result-selected").invoke "removeClassName", "result-selected"
@selected_item.removeClassName("chzn-default")
@result_single_selected = high
-
+
high.addClassName("result-selected")
-
+
position = high.id.substr(high.id.lastIndexOf("_") + 1 )
item = @results_data[position]
item.selected = true
@@ -343,13 +346,13 @@ class Chosen extends AbstractChosen
@selected_item.down("span").update(item.html)
this.single_deselect_control_build() if @allow_single_deselect
- this.results_hide() unless evt.metaKey and @is_multiple
+ this.results_hide() unless (evt.metaKey or evt.ctrlKey) and @is_multiple
@search_field.value = ""
-
+
@form_field.simulate("change") if typeof Event.simulate is 'function' && (@is_multiple || @form_field.value != @current_value)
@current_value = @form_field.value
-
+
this.search_field_scale()
result_activate: (el) ->
@@ -360,7 +363,7 @@ class Chosen extends AbstractChosen
result_deselect: (pos) ->
result_data = @results_data[pos]
-
+
if not @form_field.options[result_data.options_index].disabled
result_data.selected = false
@@ -376,7 +379,7 @@ class Chosen extends AbstractChosen
return true
else
return false
-
+
single_deselect_control_build: ->
@selected_item.down("span").insert { after: "<abbr class=\"search-choice-close\"></abbr>" } if @allow_single_deselect and not @selected_item.down("abbr")
@@ -397,11 +400,11 @@ class Chosen extends AbstractChosen
else if not (@is_multiple and option.selected)
found = false
result_id = option.dom_id
-
+
if regex.test option.html
found = true
results += 1
- else if option.html.indexOf(" ") >= 0 or option.html.indexOf("[") == 0
+ else if @search_split_words and (option.html.indexOf(" ") >= 0 or option.html.indexOf("[") == 0)
#TODO: replace this substitution of /\[\]/ with a list of characters to skip.
parts = option.html.replace(/\[|\]/g, "").split(" ")
if parts.length
@@ -452,10 +455,10 @@ class Chosen extends AbstractChosen
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 )
-
+
no_results_clear: ->
nr = null
nr.remove() while nr = @search_results.down(".no-results")
@@ -509,7 +512,7 @@ class Chosen extends AbstractChosen
this.search_field_scale()
this.clear_backstroke() if stroke != 8 and this.pending_backstroke
-
+
switch stroke
when 8
@backstroke_length = this.search_field.value.length
@@ -536,10 +539,10 @@ class Chosen extends AbstractChosen
style_block = "position:absolute; left: -1000px; top: -1000px; display:none;"
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) + ";"
-
+
div = new Element('div', { 'style' : style_block }).update(@search_field.value.escapeHTML())
document.body.appendChild(div)
@@ -557,7 +560,7 @@ class Chosen extends AbstractChosen
root.Chosen = Chosen
# Prototype does not support version numbers so we add it ourselves
-if Prototype.Browser.IE
+if Prototype.Browser.IE
if /MSIE (\d+\.\d+);/.test(navigator.userAgent)
Prototype.BrowserFeatures['Version'] = new Number(RegExp.$1);
@@ -29,6 +29,7 @@ class AbstractChosen
@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
@disable_search_threshold = @options.disable_search_threshold || 0
@disable_search = @options.disable_search || false
+ @search_split_words = not (@options.disable_search_split_words || false)
@search_contains = @options.search_contains || false
@choices = 0
@single_backstroke_delete = @options.single_backstroke_delete || false

0 comments on commit f69cfbf

Please sign in to comment.