Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Prototype merge

  • Loading branch information...
commit 245c05ac3ec84a2c687c88456aa27836c6291bcc 1 parent 82de765
@koenpunt authored
Showing with 11 additions and 12 deletions.
  1. +1 −1  chosen/chosen.proto.min.js
  2. +10 −11 coffee/chosen.proto.coffee
View
2  chosen/chosen.proto.min.js
@@ -7,4 +7,4 @@
// MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md
// This file is generated by `cake build`, do not edit it by hand.
-(function(){var e;e=function(){function e(){this.options_index=0,this.parsed=[]}return e.prototype.add_node=function(e){return e.nodeName.toUpperCase()==="OPTGROUP"?this.add_group(e):this.add_option(e)},e.prototype.add_group=function(e){var t,n,r,i,s,o;t=this.parsed.length,this.parsed.push({array_index:t,group:!0,label:e.label,children:0,disabled:e.disabled}),s=e.childNodes,o=[];for(r=0,i=s.length;r<i;r++)n=s[r],o.push(this.add_option(n,t,e.disabled));return o},e.prototype.add_option=function(e,t,n){if(e.nodeName.toUpperCase()==="OPTION")return e.text!==""?(t!=null&&(this.parsed[t].children+=1),this.parsed.push({array_index:this.parsed.length,options_index:this.options_index,value:e.value,text:e.text,html:e.innerHTML,selected:e.selected,disabled:n===!0?n:e.disabled,group_array_index:t,classes:e.className,style:e.style.cssText})):this.parsed.push({array_index:this.parsed.length,options_index:this.options_index,empty:!0}),this.options_index+=1},e}(),e.select_to_array=function(t){var n,r,i,s,o;r=new e,o=t.childNodes;for(i=0,s=o.length;i<s;i++)n=o[i],r.add_node(n);return r.parsed},this.SelectParser=e}).call(this),function(){var e,t;t=this,e=function(){function e(t,n){this.form_field=t,this.options=n!=null?n:{};if(!e.browser_is_supported())return;this.is_multiple=this.form_field.multiple,this.set_default_text(),this.set_default_values(),this.setup(),this.set_up_html(),this.register_observers(),this.finish_setup()}return e.prototype.set_default_values=function(){var e=this;return this.click_test_action=function(t){return e.test_active_click(t)},this.activate_action=function(t){return e.activate_field(t)},this.active_field=!1,this.mouse_on_container=!1,this.results_showing=!1,this.result_highlighted=null,this.result_single_selected=null,this.allow_single_deselect=this.options.allow_single_deselect!=null&&this.form_field.options[0]!=null&&this.form_field.options[0].text===""?this.options.allow_single_deselect:!1,this.disable_search_threshold=this.options.disable_search_threshold||0,this.disable_search=this.options.disable_search||!1,this.enable_split_word_search=this.options.enable_split_word_search!=null?this.options.enable_split_word_search:!0,this.search_contains=this.options.search_contains||!1,this.single_backstroke_delete=this.options.single_backstroke_delete||!1,this.max_selected_options=this.options.max_selected_options||Infinity,this.inherit_select_classes=this.options.inherit_select_classes||!1},e.prototype.set_default_text=function(){return this.form_field.getAttribute("data-placeholder")?this.default_text=this.form_field.getAttribute("data-placeholder"):this.is_multiple?this.default_text=this.options.placeholder_text_multiple||this.options.placeholder_text||e.default_multiple_text:this.default_text=this.options.placeholder_text_single||this.options.placeholder_text||e.default_single_text,this.results_none_found=this.form_field.getAttribute("data-no_results_text")||this.options.no_results_text||e.default_no_result_text},e.prototype.mouse_enter=function(){return this.mouse_on_container=!0},e.prototype.mouse_leave=function(){return this.mouse_on_container=!1},e.prototype.input_focus=function(e){var t=this;if(this.is_multiple){if(!this.active_field)return setTimeout(function(){return t.container_mousedown()},50)}else if(!this.active_field)return this.activate_field()},e.prototype.input_blur=function(e){var t=this;if(!this.mouse_on_container)return this.active_field=!1,setTimeout(function(){return t.blur_test()},100)},e.prototype.result_add_option=function(e){var t,n;return e.disabled?"":(e.dom_id=this.container_id+"_o_"+e.array_index,t=e.selected&&this.is_multiple?[]:["active-result"],e.selected&&t.push("result-selected"),e.group_array_index!=null&&t.push("group-option"),e.classes!==""&&t.push(e.classes),n=e.style.cssText!==""?' style="'+e.style+'"':"",'<li id="'+e.dom_id+'" class="'+t.join(" ")+'"'+n+">"+e.html+"</li>")},e.prototype.results_update_field=function(){return this.set_default_text(),this.is_multiple||this.results_reset_cleanup(),this.result_clear_highlight(),this.result_single_selected=null,this.results_build()},e.prototype.results_toggle=function(){return this.results_showing?this.results_hide():this.results_show()},e.prototype.results_search=function(e){return this.results_showing?this.winnow_results():this.results_show()},e.prototype.choices_count=function(){var e,t,n,r;if(this.selected_option_count!=null)return this.selected_option_count;this.selected_option_count=0,r=this.form_field.options;for(t=0,n=r.length;t<n;t++)e=r[t],e.selected&&(this.selected_option_count+=1);return this.selected_option_count},e.prototype.choices_click=function(e){e.preventDefault();if(!this.results_showing)return this.results_show()},e.prototype.keyup_checker=function(e){var t,n;t=(n=e.which)!=null?n:e.keyCode,this.search_field_scale();switch(t){case 8:if(this.is_multiple&&this.backstroke_length<1&&this.choices_count()>0)return this.keydown_backstroke();if(!this.pending_backstroke)return this.result_clear_highlight(),this.results_search();break;case 13:e.preventDefault();if(this.results_showing)return this.result_select(e);break;case 27:return this.results_showing&&this.results_hide(),!0;case 9:case 38:case 40:case 16:case 91:case 17:break;default:return this.results_search()}},e.prototype.generate_field_id=function(){var e;return e=this.generate_random_id(),this.form_field.id=e,e},e.prototype.generate_random_char=function(){var e,t,n;return e="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",n=Math.floor(Math.random()*e.length),t=e.substring(n,n+1)},e.prototype.container_width=function(){return this.options.width!=null?this.options.width:""+this.form_field.offsetWidth+"px"},e.browser_is_supported=function(){var e;return window.navigator.appName==="Microsoft Internet Explorer"?null!==(e=document.documentMode)&&e>=8:!0},e.default_multiple_text="Select Some Options",e.default_single_text="Select an Option",e.default_no_result_text="No results match",e}(),t.AbstractChosen=e}.call(this),function(){var e,t,n={}.hasOwnProperty,r=function(e,t){function i(){this.constructor=e}for(var r in t)n.call(t,r)&&(e[r]=t[r]);return i.prototype=t.prototype,e.prototype=new i,e.__super__=t.prototype,e};t=this,e=function(e){function n(){return n.__super__.constructor.apply(this,arguments)}return r(n,e),n.prototype.setup=function(){return this.current_selectedIndex=this.form_field.selectedIndex,this.is_rtl=this.form_field.hasClassName("chzn-rtl")},n.prototype.finish_setup=function(){return this.form_field.addClassName("chzn-done")},n.prototype.set_default_values=function(){return n.__super__.set_default_values.call(this),this.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>'),this.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>'),this.choice_temp=new Template('<li class="search-choice" id="#{id}"><span>#{choice}</span><a href="javascript:void(0)" class="search-choice-close" rel="#{position}"></a></li>'),this.choice_noclose_temp=new Template('<li class="search-choice search-choice-disabled" id="#{id}"><span>#{choice}</span></li>'),this.no_results_temp=new Template('<li class="no-results">'+this.results_none_found+' "<span>#{terms}</span>".#{add_item_link}</li>'),this.new_option_html=new Template('<option value="#{terms}">#{terms}</option>'),this.new_option_temp=new Template('<option value="#{value}">#{text}</option>'),this.add_link_temp=new Template(' <a href="javascript:void(0);" class="option-add">#{text}</a>')},n.prototype.set_up_html=function(){var e,t;return this.container_id=this.form_field.identify().replace(/[^\w]/g,"_")+"_chzn",e=["chzn-container"],e.push("chzn-container-"+(this.is_multiple?"multi":"single")),this.inherit_select_classes&&this.form_field.className&&e.push(this.form_field.className),this.is_rtl&&e.push("chzn-rtl"),t={id:this.container_id,"class":e.join(" "),style:"width: "+this.container_width()+";",title:this.form_field.title},this.container=this.is_multiple?(new Element("div",t)).update(this.multi_temp.evaluate({"default":this.default_text})):(new Element("div",t)).update(this.single_temp.evaluate({"default":this.default_text})),this.form_field.hide().insert({after:this.container}),this.dropdown=this.container.down("div.chzn-drop"),this.search_field=this.container.down("input"),this.search_results=this.container.down("ul.chzn-results"),this.search_field_scale(),this.search_no_results=this.container.down("li.no-results"),this.is_multiple?(this.search_choices=this.container.down("ul.chzn-choices"),this.search_container=this.container.down("li.search-field")):(this.search_container=this.container.down("div.chzn-search"),this.selected_item=this.container.down(".chzn-single")),this.results_build(),this.set_tab_index(),this.set_label_behavior(),this.form_field.fire("liszt:ready",{chosen:this})},n.prototype.register_observers=function(){var e=this;return this.container.observe("mousedown",function(t){return e.container_mousedown(t)}),this.container.observe("mouseup",function(t){return e.container_mouseup(t)}),this.container.observe("mouseenter",function(t){return e.mouse_enter(t)}),this.container.observe("mouseleave",function(t){return e.mouse_leave(t)}),this.search_results.observe("mouseup",function(t){return e.search_results_mouseup(t)}),this.search_results.observe("mouseover",function(t){return e.search_results_mouseover(t)}),this.search_results.observe("mouseout",function(t){return e.search_results_mouseout(t)}),this.search_results.observe("mousewheel",function(t){return e.search_results_mousewheel(t)}),this.search_results.observe("DOMMouseScroll",function(t){return e.search_results_mousewheel(t)}),this.form_field.observe("liszt:updated",function(t){return e.results_update_field(t)}),this.form_field.observe("liszt:activate",function(t){return e.activate_field(t)}),this.form_field.observe("liszt:open",function(t){return e.container_mousedown(t)}),this.search_field.observe("blur",function(t){return e.input_blur(t)}),this.search_field.observe("keyup",function(t){return e.keyup_checker(t)}),this.search_field.observe("keydown",function(t){return e.keydown_checker(t)}),this.search_field.observe("focus",function(t){return e.input_focus(t)}),this.is_multiple?this.search_choices.observe("click",function(t){return e.choices_click(t)}):this.container.observe("click",function(e){return e.preventDefault()})},n.prototype.search_field_disabled=function(){this.is_disabled=this.form_field.disabled;if(this.is_disabled)return this.container.addClassName("chzn-disabled"),this.search_field.disabled=!0,this.is_multiple||this.selected_item.stopObserving("focus",this.activate_action),this.close_field();this.container.removeClassName("chzn-disabled"),this.search_field.disabled=!1;if(!this.is_multiple)return this.selected_item.observe("focus",this.activate_action)},n.prototype.container_mousedown=function(e){if(!this.is_disabled){e&&e.type==="mousedown"&&!this.results_showing&&e.stop();if(e==null||!e.target.hasClassName("search-choice-close"))return this.active_field?!this.is_multiple&&e&&(e.target===this.selected_item||e.target.up("a.chzn-single"))&&this.results_toggle():(this.is_multiple&&this.search_field.clear(),document.observe("click",this.click_test_action),this.results_show()),this.activate_field()}},n.prototype.container_mouseup=function(e){if(e.target.nodeName==="ABBR"&&!this.is_disabled)return this.results_reset(e)},n.prototype.search_results_mousewheel=function(e){var t;t=-e.wheelDelta||e.detail;if(t!=null)return e.preventDefault(),e.type==="DOMMouseScroll"&&(t*=40),this.search_results.scrollTop=t+this.search_results.scrollTop},n.prototype.blur_test=function(e){if(!this.active_field&&this.container.hasClassName("chzn-container-active"))return this.close_field()},n.prototype.close_field=function(){return document.stopObserving("click",this.click_test_action),this.active_field=!1,this.results_hide(),this.container.removeClassName("chzn-container-active"),this.winnow_results_clear(),this.clear_backstroke(),this.show_search_field_default(),this.search_field_scale()},n.prototype.activate_field=function(){return this.container.addClassName("chzn-container-active"),this.active_field=!0,this.search_field.value=this.search_field.value,this.search_field.focus()},n.prototype.test_active_click=function(e){return e.target.up("#"+this.container_id)?this.active_field=!0:this.close_field()},n.prototype.results_build=function(){var e,n,r,i,s;this.parsing=!0,this.selected_option_count=null,this.results_data=t.SelectParser.select_to_array(this.form_field),this.is_multiple&&this.choices_count()>0?this.search_choices.select("li.search-choice").invoke("remove"):this.is_multiple||(this.selected_item.addClassName("chzn-default").down("span").update(this.default_text),this.disable_search||this.form_field.options.length<=this.disable_search_threshold?this.container.addClassName("chzn-container-single-nosearch"):this.container.removeClassName("chzn-container-single-nosearch")),e="",s=this.results_data;for(r=0,i=s.length;r<i;r++)n=s[r],n.group?e+=this.result_add_group(n):n.empty||(e+=this.result_add_option(n),n.selected&&this.is_multiple?this.choice_build(n):n.selected&&!this.is_multiple&&(this.selected_item.removeClassName("chzn-default").down("span").update(n.html),this.allow_single_deselect&&this.single_deselect_control_build()));return this.search_field_disabled(),this.show_search_field_default(),this.search_field_scale(),this.search_results.update(e),this.parsing=!1},n.prototype.result_add_group=function(e){return e.disabled?"":(e.dom_id=this.container_id+"_g_"+e.array_index,'<li id="'+e.dom_id+'" class="group-result">'+e.label.escapeHTML()+"</li>")},n.prototype.result_do_highlight=function(e){var t,n,r,i,s;this.result_clear_highlight(),this.result_highlight=e,this.result_highlight.addClassName("highlighted"),r=parseInt(this.search_results.getStyle("maxHeight"),10),s=this.search_results.scrollTop,i=r+s,n=this.result_highlight.positionedOffset().top+this.search_results.scrollTop,t=n+this.result_highlight.getHeight();if(t>=i)return this.search_results.scrollTop=t-r>0?t-r:0;if(n<s)return this.search_results.scrollTop=n},n.prototype.result_clear_highlight=function(){return this.result_highlight&&this.result_highlight.removeClassName("highlighted"),this.result_highlight=null},n.prototype.results_show=function(){if(this.result_single_selected!=null)this.result_do_highlight(this.result_single_selected);else if(this.is_multiple&&this.max_selected_options<=this.choices_count())return this.form_field.fire("liszt:maxselected",{chosen:this}),!1;return this.container.addClassName("chzn-with-drop"),this.form_field.fire("liszt:showing_dropdown",{chosen:this}),this.results_showing=!0,this.search_field.focus(),this.search_field.value=this.search_field.value,this.winnow_results()},n.prototype.results_hide=function(){return this.result_clear_highlight(),this.container.removeClassName("chzn-with-drop"),this.form_field.fire("liszt:hiding_dropdown",{chosen:this}),this.results_showing=!1},n.prototype.set_tab_index=function(e){var t;if(this.form_field.tabIndex)return t=this.form_field.tabIndex,this.form_field.tabIndex=-1,this.search_field.tabIndex=t},n.prototype.set_label_behavior=function(){var e=this;this.form_field_label=this.form_field.up("label"),this.form_field_label==null&&(this.form_field_label=$$("label[for='"+this.form_field.id+"']").first());if(this.form_field_label!=null)return this.form_field_label.observe("click",function(t){return e.is_multiple?e.container_mousedown(t):e.activate_field()})},n.prototype.show_search_field_default=function(){return this.is_multiple&&this.choices_count()<1&&!this.active_field?(this.search_field.value=this.default_text,this.search_field.addClassName("default")):(this.search_field.value="",this.search_field.removeClassName("default"))},n.prototype.search_results_mouseup=function(e){var t;t=e.target.hasClassName("active-result")?e.target:e.target.up(".active-result");if(t)return this.result_highlight=t,this.result_select(e),this.search_field.focus()},n.prototype.search_results_mouseover=function(e){var t;t=e.target.hasClassName("active-result")?e.target:e.target.up(".active-result");if(t)return this.result_do_highlight(t)},n.prototype.search_results_mouseout=function(e){if(e.target.hasClassName("active-result")||e.target.up(".active-result"))return this.result_clear_highlight()},n.prototype.choice_build=function(e){var t,n,r=this;return t=(new Element("li",{"class":"search-choice"})).update("<span>"+e.html+"</span>"),e.disabled?t.addClassName("search-choice-disabled"):(n=new Element("a",{href:"#","class":"search-choice-close",rel:e.array_index}),n.observe("click",function(e){return r.choice_destroy_link_click(e)}),t.insert(n)),this.search_container.insert({before:t})},n.prototype.choice_destroy_link_click=function(e){e.preventDefault(),e.stopPropagation();if(!this.is_disabled)return this.choice_destroy(e.target)},n.prototype.choice_destroy=function(e){if(this.result_deselect(e.readAttribute("rel")))return this.show_search_field_default(),this.is_multiple&&this.choices_count()>0&&this.search_field.value.length<1&&this.results_hide(),e.up("li").remove(),this.search_field_scale()},n.prototype.results_reset=function(){this.form_field.options[0].selected=!0,this.selected_option_count=null,this.selected_item.down("span").update(this.default_text),this.is_multiple||this.selected_item.addClassName("chzn-default"),this.show_search_field_default(),this.results_reset_cleanup(),typeof Event.simulate=="function"&&this.form_field.simulate("change");if(this.active_field)return this.results_hide()},n.prototype.results_reset_cleanup=function(){var e;this.current_selectedIndex=this.form_field.selectedIndex,e=this.selected_item.down("abbr");if(e)return e.remove()},n.prototype.result_select=function(e){var t,n,r;if(this.result_highlight)return t=this.result_highlight,this.result_clear_highlight(),this.is_multiple&&this.max_selected_options<=this.choices_count()?(this.form_field.fire("liszt:maxselected",{chosen:this}),!1):(this.is_multiple?this.result_deactivate(t):(this.search_results.descendants(".result-selected").invoke("removeClassName","result-selected"),this.selected_item.removeClassName("chzn-default"),this.result_single_selected=t),t.addClassName("result-selected"),r=t.id.substr(t.id.lastIndexOf("_")+1),n=this.results_data[r],n.selected=!0,this.form_field.options[n.options_index].selected=!0,this.selected_option_count=null,this.is_multiple?this.choice_build(n):(this.selected_item.down("span").update(n.html),this.allow_single_deselect&&this.single_deselect_control_build()),(!e.metaKey&&!e.ctrlKey||!this.is_multiple)&&this.results_hide(),this.search_field.value="",typeof Event.simulate=="function"&&(this.is_multiple||this.form_field.selectedIndex!==this.current_selectedIndex)&&this.form_field.simulate("change"),this.current_selectedIndex=this.form_field.selectedIndex,this.search_field_scale())},n.prototype.result_activate=function(e){return e.addClassName("active-result")},n.prototype.result_deactivate=function(e){return e.removeClassName("active-result")},n.prototype.result_deselect=function(e){var t,n;return n=this.results_data[e],this.form_field.options[n.options_index].disabled?!1:(n.selected=!1,this.form_field.options[n.options_index].selected=!1,this.selected_option_count=null,t=$(this.container_id+"_o_"+e),t.removeClassName("result-selected").addClassName("active-result").show(),this.result_clear_highlight(),this.winnow_results(),typeof Event.simulate=="function"&&this.form_field.simulate("change"),this.search_field_scale(),!0)},n.prototype.single_deselect_control_build=function(){if(!this.allow_single_deselect)return;return this.selected_item.down("abbr")||this.selected_item.down("span").insert({after:'<abbr class="search-choice-close"></abbr>'}),this.selected_item.addClassName("chzn-single-with-deselect")},n.prototype.winnow_results=function(){var e,t,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y;this.no_results_clear(),a=0,l=!1,f=this.search_field.value===this.default_text?"":this.search_field.value.strip().escapeHTML(),o=this.search_contains?"":"^",s=new RegExp(o+f.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),"i"),p=new RegExp(f.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),"i"),e=new RegExp("^"+f+"$","i"),y=this.results_data;for(d=0,m=y.length;d<m;d++){n=y[d];if(!n.disabled&&!n.empty)if(n.group)$(n.dom_id).hide();else if(!this.is_multiple||!n.selected){t=!1,u=n.dom_id;if(s.test(n.html))t=!0,a+=1;else if(this.enable_split_word_search&&(n.html.indexOf(" ")>=0||n.html.indexOf("[")===0)){i=n.html.replace(/\[|\]/g,"").split(" ");if(i.length)for(v=0,g=i.length;v<g;v++)r=i[v],s.test(r)&&(t=!0,a+=1)}t?(f.length?(c=n.html.search(p),h=n.html.substr(0,c+f.length)+"</em>"+n.html.substr(c+f.length),h=h.substr(0,c)+"<em>"+h.substr(c)):h=n.html,$(u).innerHTML!==h&&$(u).update(h),this.result_activate($(u)),n.group_array_index!=null&&$(this.results_data[n.group_array_index].dom_id).setStyle({display:"list-item"})):($(u)===this.result_highlight&&this.result_clear_highlight(),this.result_deactivate($(u)))}else this.is_multiple&&n.selected&&e.test(n.html)&&(l=!0)}return a<1&&f.length?this.no_results(f,l):this.winnow_results_set_highlight()},n.prototype.winnow_results_clear=function(){var e,t,n,r,i;this.search_field.clear(),t=this.search_results.select("li"),i=[];for(n=0,r=t.length;n<r;n++)e=t[n],e.hasClassName("group-result")?i.push(e.show()):!this.is_multiple||!e.hasClassName("result-selected")?i.push(this.result_activate(e)):i.push(void 0);return i},n.prototype.winnow_results_set_highlight=function(){var e;if(!this.result_highlight){this.is_multiple||(e=this.search_results.down(".result-selected.active-result")),e==null&&(e=this.search_results.down(".active-result"));if(e!=null)return this.result_do_highlight(e)}},n.prototype.no_results=function(e,t){var n,r=this;n="",this.options.addOption&&!t&&(n=this.add_link_temp.evaluate({text:"Add this item"})),this.search_results.insert(this.no_results_temp.evaluate({terms:e,add_item_link:n}));if(this.options.addOption&&!t)return this.search_results.down("a.option-add").observe("click",function(n){if(!t)return r.select_add_option(e)})},n.prototype.select_add_option=function(e){return Object.isFunction(this.options.addOption)?this.options.addOption.call(this,e,this.select_append_option):this.select_append_option({value:e,text:e})},n.prototype.select_append_option=function(e){var t;return t=this.new_option_temp.evaluate({value:e.value,text:e.text}),this.form_field.insert(t),Event.fire(this.form_field,"liszt:updated"),this.result_select()},n.prototype.no_results_clear=function(){var e,t;e=null,t=[];while(e=this.search_results.down(".no-results"))t.push(e.remove());return t},n.prototype.keydown_arrow=function(){var e,t,n;e=this.search_results.select("li.active-result");if(e.length){this.result_highlight?this.results_showing&&(n=this.result_highlight.nextSiblings(),t=n.intersect(e),t.length&&this.result_do_highlight(t.first())):this.result_do_highlight(e.first());if(!this.results_showing)return this.results_show()}},n.prototype.keyup_arrow=function(){var e,t,n;if(!this.results_showing&&!this.is_multiple)return this.results_show();if(this.result_highlight)return n=this.result_highlight.previousSiblings(),e=this.search_results.select("li.active-result"),t=n.intersect(e),t.length?this.result_do_highlight(t.first()):(this.choices_count()>0&&this.results_hide(),this.result_clear_highlight())},n.prototype.keydown_backstroke=function(){var e;if(this.pending_backstroke)return this.choice_destroy(this.pending_backstroke.down("a")),this.clear_backstroke();e=this.search_container.siblings().last();if(e&&e.hasClassName("search-choice")&&!e.hasClassName("search-choice-disabled"))return this.pending_backstroke=e,this.pending_backstroke&&this.pending_backstroke.addClassName("search-choice-focus"),this.single_backstroke_delete?this.keydown_backstroke():this.pending_backstroke.addClassName("search-choice-focus")},n.prototype.clear_backstroke=function(){return this.pending_backstroke&&this.pending_backstroke.removeClassName("search-choice-focus"),this.pending_backstroke=null},n.prototype.keydown_checker=function(e){var t,n;t=(n=e.which)!=null?n:e.keyCode,this.search_field_scale(),t!==8&&this.pending_backstroke&&this.clear_backstroke();switch(t){case 8:this.backstroke_length=this.search_field.value.length;break;case 9:this.results_showing&&!this.is_multiple&&this.result_select(e),this.mouse_on_container=!1;break;case 13:e.preventDefault();break;case 38:e.preventDefault(),this.keyup_arrow();break;case 40:this.keydown_arrow()}},n.prototype.search_field_scale=function(){var e,t,n,r,i,s,o,u;if(this.is_multiple){t=0,s=0,r="position:absolute; left: -1000px; top: -1000px; display:none;",i=["font-size","font-style","font-weight","font-family","line-height","text-transform","letter-spacing"];for(o=0,u=i.length;o<u;o++)n=i[o],r+=n+":"+this.search_field.getStyle(n)+";";return e=(new Element("div",{style:r})).update(this.search_field.value.escapeHTML()),document.body.appendChild(e),s=Element.measure(e,"width")+25,e.remove(),this.f_width||(this.f_width=this.container.getWidth()),s>this.f_width-10&&(s=this.f_width-10),this.search_field.setStyle({width:s+"px"})}},n}(AbstractChosen),t.Chosen=e}.call(this);
+(function(){var e;e=function(){function e(){this.options_index=0,this.parsed=[]}return e.prototype.add_node=function(e){return e.nodeName.toUpperCase()==="OPTGROUP"?this.add_group(e):this.add_option(e)},e.prototype.add_group=function(e){var t,n,r,i,s,o;t=this.parsed.length,this.parsed.push({array_index:t,group:!0,label:e.label,children:0,disabled:e.disabled}),s=e.childNodes,o=[];for(r=0,i=s.length;r<i;r++)n=s[r],o.push(this.add_option(n,t,e.disabled));return o},e.prototype.add_option=function(e,t,n){if(e.nodeName.toUpperCase()==="OPTION")return e.text!==""?(t!=null&&(this.parsed[t].children+=1),this.parsed.push({array_index:this.parsed.length,options_index:this.options_index,value:e.value,text:e.text,html:e.innerHTML,selected:e.selected,disabled:n===!0?n:e.disabled,group_array_index:t,classes:e.className,style:e.style.cssText})):this.parsed.push({array_index:this.parsed.length,options_index:this.options_index,empty:!0}),this.options_index+=1},e}(),e.select_to_array=function(t){var n,r,i,s,o;r=new e,o=t.childNodes;for(i=0,s=o.length;i<s;i++)n=o[i],r.add_node(n);return r.parsed},this.SelectParser=e}).call(this),function(){var e,t;t=this,e=function(){function e(t,n){this.form_field=t,this.options=n!=null?n:{};if(!e.browser_is_supported())return;this.is_multiple=this.form_field.multiple,this.set_default_text(),this.set_default_values(),this.setup(),this.set_up_html(),this.register_observers(),this.finish_setup()}return e.prototype.set_default_values=function(){var e=this;return this.click_test_action=function(t){return e.test_active_click(t)},this.activate_action=function(t){return e.activate_field(t)},this.active_field=!1,this.mouse_on_container=!1,this.results_showing=!1,this.result_highlighted=null,this.result_single_selected=null,this.allow_single_deselect=this.options.allow_single_deselect!=null&&this.form_field.options[0]!=null&&this.form_field.options[0].text===""?this.options.allow_single_deselect:!1,this.disable_search_threshold=this.options.disable_search_threshold||0,this.disable_search=this.options.disable_search||!1,this.enable_split_word_search=this.options.enable_split_word_search!=null?this.options.enable_split_word_search:!0,this.search_contains=this.options.search_contains||!1,this.single_backstroke_delete=this.options.single_backstroke_delete||!1,this.max_selected_options=this.options.max_selected_options||Infinity,this.inherit_select_classes=this.options.inherit_select_classes||!1},e.prototype.set_default_text=function(){return this.form_field.getAttribute("data-placeholder")?this.default_text=this.form_field.getAttribute("data-placeholder"):this.is_multiple?this.default_text=this.options.placeholder_text_multiple||this.options.placeholder_text||e.default_multiple_text:this.default_text=this.options.placeholder_text_single||this.options.placeholder_text||e.default_single_text,this.results_none_found=this.form_field.getAttribute("data-no_results_text")||this.options.no_results_text||e.default_no_result_text},e.prototype.mouse_enter=function(){return this.mouse_on_container=!0},e.prototype.mouse_leave=function(){return this.mouse_on_container=!1},e.prototype.input_focus=function(e){var t=this;if(this.is_multiple){if(!this.active_field)return setTimeout(function(){return t.container_mousedown()},50)}else if(!this.active_field)return this.activate_field()},e.prototype.input_blur=function(e){var t=this;if(!this.mouse_on_container)return this.active_field=!1,setTimeout(function(){return t.blur_test()},100)},e.prototype.result_add_option=function(e){var t,n;return e.disabled?"":(e.dom_id=this.container_id+"_o_"+e.array_index,t=e.selected&&this.is_multiple?[]:["active-result"],e.selected&&t.push("result-selected"),e.group_array_index!=null&&t.push("group-option"),e.classes!==""&&t.push(e.classes),n=e.style.cssText!==""?' style="'+e.style+'"':"",'<li id="'+e.dom_id+'" class="'+t.join(" ")+'"'+n+">"+e.html+"</li>")},e.prototype.results_update_field=function(){return this.set_default_text(),this.is_multiple||this.results_reset_cleanup(),this.result_clear_highlight(),this.result_single_selected=null,this.results_build()},e.prototype.results_toggle=function(){return this.results_showing?this.results_hide():this.results_show()},e.prototype.results_search=function(e){return this.results_showing?this.winnow_results():this.results_show()},e.prototype.choices_count=function(){var e,t,n,r;if(this.selected_option_count!=null)return this.selected_option_count;this.selected_option_count=0,r=this.form_field.options;for(t=0,n=r.length;t<n;t++)e=r[t],e.selected&&(this.selected_option_count+=1);return this.selected_option_count},e.prototype.choices_click=function(e){e.preventDefault();if(!this.results_showing)return this.results_show()},e.prototype.keyup_checker=function(e){var t,n;t=(n=e.which)!=null?n:e.keyCode,this.search_field_scale();switch(t){case 8:if(this.is_multiple&&this.backstroke_length<1&&this.choices_count()>0)return this.keydown_backstroke();if(!this.pending_backstroke)return this.result_clear_highlight(),this.results_search();break;case 13:e.preventDefault();if(this.results_showing)return this.result_select(e);break;case 27:return this.results_showing&&this.results_hide(),!0;case 9:case 38:case 40:case 16:case 91:case 17:break;default:return this.results_search()}},e.prototype.generate_field_id=function(){var e;return e=this.generate_random_id(),this.form_field.id=e,e},e.prototype.generate_random_char=function(){var e,t,n;return e="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",n=Math.floor(Math.random()*e.length),t=e.substring(n,n+1)},e.prototype.container_width=function(){return this.options.width!=null?this.options.width:""+this.form_field.offsetWidth+"px"},e.browser_is_supported=function(){var e;return window.navigator.appName==="Microsoft Internet Explorer"?null!==(e=document.documentMode)&&e>=8:!0},e.default_multiple_text="Select Some Options",e.default_single_text="Select an Option",e.default_no_result_text="No results match",e}(),t.AbstractChosen=e}.call(this),function(){var e,t,n={}.hasOwnProperty,r=function(e,t){function i(){this.constructor=e}for(var r in t)n.call(t,r)&&(e[r]=t[r]);return i.prototype=t.prototype,e.prototype=new i,e.__super__=t.prototype,e};t=this,e=function(e){function n(){return n.__super__.constructor.apply(this,arguments)}return r(n,e),n.prototype.setup=function(){return this.current_selectedIndex=this.form_field.selectedIndex,this.is_rtl=this.form_field.hasClassName("chzn-rtl")},n.prototype.finish_setup=function(){return this.form_field.addClassName("chzn-done")},n.prototype.set_default_values=function(){return n.__super__.set_default_values.call(this),this.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>'),this.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>'),this.choice_temp=new Template('<li class="search-choice" id="#{id}"><span>#{choice}</span><a href="javascript:void(0)" class="search-choice-close" rel="#{position}"></a></li>'),this.choice_noclose_temp=new Template('<li class="search-choice search-choice-disabled" id="#{id}"><span>#{choice}</span></li>'),this.no_results_temp=new Template('<li class="no-results">'+this.results_none_found+' "<span>#{terms}</span>".#{add_item_link}</li>'),this.new_option_html=new Template('<option value="#{terms}">#{terms}</option>'),this.new_option_temp=new Template('<option value="#{value}">#{text}</option>'),this.add_link_temp=new Template(' <a href="javascript:void(0);" class="option-add">'+this.add_option_text+"</a>")},n.prototype.set_up_html=function(){var e,t;return this.container_id=this.form_field.identify().replace(/[^\w]/g,"_")+"_chzn",e=["chzn-container"],e.push("chzn-container-"+(this.is_multiple?"multi":"single")),this.inherit_select_classes&&this.form_field.className&&e.push(this.form_field.className),this.is_rtl&&e.push("chzn-rtl"),t={id:this.container_id,"class":e.join(" "),style:"width: "+this.container_width()+";",title:this.form_field.title},this.container=this.is_multiple?(new Element("div",t)).update(this.multi_temp.evaluate({"default":this.default_text})):(new Element("div",t)).update(this.single_temp.evaluate({"default":this.default_text})),this.form_field.hide().insert({after:this.container}),this.dropdown=this.container.down("div.chzn-drop"),this.search_field=this.container.down("input"),this.search_results=this.container.down("ul.chzn-results"),this.search_field_scale(),this.search_no_results=this.container.down("li.no-results"),this.is_multiple?(this.search_choices=this.container.down("ul.chzn-choices"),this.search_container=this.container.down("li.search-field")):(this.search_container=this.container.down("div.chzn-search"),this.selected_item=this.container.down(".chzn-single")),this.results_build(),this.set_tab_index(),this.set_label_behavior(),this.form_field.fire("liszt:ready",{chosen:this})},n.prototype.register_observers=function(){var e=this;return this.container.observe("mousedown",function(t){return e.container_mousedown(t)}),this.container.observe("mouseup",function(t){return e.container_mouseup(t)}),this.container.observe("mouseenter",function(t){return e.mouse_enter(t)}),this.container.observe("mouseleave",function(t){return e.mouse_leave(t)}),this.search_results.observe("mouseup",function(t){return e.search_results_mouseup(t)}),this.search_results.observe("mouseover",function(t){return e.search_results_mouseover(t)}),this.search_results.observe("mouseout",function(t){return e.search_results_mouseout(t)}),this.search_results.observe("mousewheel",function(t){return e.search_results_mousewheel(t)}),this.search_results.observe("DOMMouseScroll",function(t){return e.search_results_mousewheel(t)}),this.form_field.observe("liszt:updated",function(t){return e.results_update_field(t)}),this.form_field.observe("liszt:activate",function(t){return e.activate_field(t)}),this.form_field.observe("liszt:open",function(t){return e.container_mousedown(t)}),this.search_field.observe("blur",function(t){return e.input_blur(t)}),this.search_field.observe("keyup",function(t){return e.keyup_checker(t)}),this.search_field.observe("keydown",function(t){return e.keydown_checker(t)}),this.search_field.observe("focus",function(t){return e.input_focus(t)}),this.is_multiple?this.search_choices.observe("click",function(t){return e.choices_click(t)}):this.container.observe("click",function(e){return e.preventDefault()})},n.prototype.search_field_disabled=function(){this.is_disabled=this.form_field.disabled;if(this.is_disabled)return this.container.addClassName("chzn-disabled"),this.search_field.disabled=!0,this.is_multiple||this.selected_item.stopObserving("focus",this.activate_action),this.close_field();this.container.removeClassName("chzn-disabled"),this.search_field.disabled=!1;if(!this.is_multiple)return this.selected_item.observe("focus",this.activate_action)},n.prototype.container_mousedown=function(e){if(!this.is_disabled){e&&e.type==="mousedown"&&!this.results_showing&&e.stop();if(e==null||!e.target.hasClassName("search-choice-close"))return this.active_field?!this.is_multiple&&e&&(e.target===this.selected_item||e.target.up("a.chzn-single"))&&this.results_toggle():(this.is_multiple&&this.search_field.clear(),document.observe("click",this.click_test_action),this.results_show()),this.activate_field()}},n.prototype.container_mouseup=function(e){if(e.target.nodeName==="ABBR"&&!this.is_disabled)return this.results_reset(e)},n.prototype.search_results_mousewheel=function(e){var t;t=-e.wheelDelta||e.detail;if(t!=null)return e.preventDefault(),e.type==="DOMMouseScroll"&&(t*=40),this.search_results.scrollTop=t+this.search_results.scrollTop},n.prototype.blur_test=function(e){if(!this.active_field&&this.container.hasClassName("chzn-container-active"))return this.close_field()},n.prototype.close_field=function(){return document.stopObserving("click",this.click_test_action),this.active_field=!1,this.results_hide(),this.container.removeClassName("chzn-container-active"),this.winnow_results_clear(),this.clear_backstroke(),this.show_search_field_default(),this.search_field_scale()},n.prototype.activate_field=function(){return this.container.addClassName("chzn-container-active"),this.active_field=!0,this.search_field.value=this.search_field.value,this.search_field.focus()},n.prototype.test_active_click=function(e){return e.target.up("#"+this.container_id)?this.active_field=!0:this.close_field()},n.prototype.results_build=function(){var e,n,r,i,s;this.parsing=!0,this.selected_option_count=null,this.results_data=t.SelectParser.select_to_array(this.form_field),this.is_multiple&&this.choices_count()>0?this.search_choices.select("li.search-choice").invoke("remove"):this.is_multiple||(this.selected_item.addClassName("chzn-default").down("span").update(this.default_text),this.disable_search||this.form_field.options.length<=this.disable_search_threshold?this.container.addClassName("chzn-container-single-nosearch"):this.container.removeClassName("chzn-container-single-nosearch")),e="",s=this.results_data;for(r=0,i=s.length;r<i;r++)n=s[r],n.group?e+=this.result_add_group(n):n.empty||(e+=this.result_add_option(n),n.selected&&this.is_multiple?this.choice_build(n):n.selected&&!this.is_multiple&&(this.selected_item.removeClassName("chzn-default").down("span").update(n.html),this.allow_single_deselect&&this.single_deselect_control_build()));return this.search_field_disabled(),this.show_search_field_default(),this.search_field_scale(),this.search_results.update(e),this.parsing=!1},n.prototype.result_add_group=function(e){return e.disabled?"":(e.dom_id=this.container_id+"_g_"+e.array_index,'<li id="'+e.dom_id+'" class="group-result">'+e.label.escapeHTML()+"</li>")},n.prototype.result_do_highlight=function(e){var t,n,r,i,s;this.result_clear_highlight(),this.result_highlight=e,this.result_highlight.addClassName("highlighted"),r=parseInt(this.search_results.getStyle("maxHeight"),10),s=this.search_results.scrollTop,i=r+s,n=this.result_highlight.positionedOffset().top+this.search_results.scrollTop,t=n+this.result_highlight.getHeight();if(t>=i)return this.search_results.scrollTop=t-r>0?t-r:0;if(n<s)return this.search_results.scrollTop=n},n.prototype.result_clear_highlight=function(){return this.result_highlight&&this.result_highlight.removeClassName("highlighted"),this.result_highlight=null},n.prototype.results_show=function(){if(this.result_single_selected!=null)this.result_do_highlight(this.result_single_selected);else if(this.is_multiple&&this.max_selected_options<=this.choices_count())return this.form_field.fire("liszt:maxselected",{chosen:this}),!1;return this.container.addClassName("chzn-with-drop"),this.form_field.fire("liszt:showing_dropdown",{chosen:this}),this.results_showing=!0,this.search_field.focus(),this.search_field.value=this.search_field.value,this.winnow_results()},n.prototype.results_hide=function(){return this.result_clear_highlight(),this.container.removeClassName("chzn-with-drop"),this.form_field.fire("liszt:hiding_dropdown",{chosen:this}),this.results_showing=!1},n.prototype.set_tab_index=function(e){var t;if(this.form_field.tabIndex)return t=this.form_field.tabIndex,this.form_field.tabIndex=-1,this.search_field.tabIndex=t},n.prototype.set_label_behavior=function(){var e=this;this.form_field_label=this.form_field.up("label"),this.form_field_label==null&&(this.form_field_label=$$("label[for='"+this.form_field.id+"']").first());if(this.form_field_label!=null)return this.form_field_label.observe("click",function(t){return e.is_multiple?e.container_mousedown(t):e.activate_field()})},n.prototype.show_search_field_default=function(){return this.is_multiple&&this.choices_count()<1&&!this.active_field?(this.search_field.value=this.default_text,this.search_field.addClassName("default")):(this.search_field.value="",this.search_field.removeClassName("default"))},n.prototype.search_results_mouseup=function(e){var t;t=e.target.hasClassName("active-result")?e.target:e.target.up(".active-result");if(t)return this.result_highlight=t,this.result_select(e),this.search_field.focus()},n.prototype.search_results_mouseover=function(e){var t;t=e.target.hasClassName("active-result")?e.target:e.target.up(".active-result");if(t)return this.result_do_highlight(t)},n.prototype.search_results_mouseout=function(e){if(e.target.hasClassName("active-result")||e.target.up(".active-result"))return this.result_clear_highlight()},n.prototype.choice_build=function(e){var t,n,r=this;return t=(new Element("li",{"class":"search-choice"})).update("<span>"+e.html+"</span>"),e.disabled?t.addClassName("search-choice-disabled"):(n=new Element("a",{href:"#","class":"search-choice-close",rel:e.array_index}),n.observe("click",function(e){return r.choice_destroy_link_click(e)}),t.insert(n)),this.search_container.insert({before:t})},n.prototype.choice_destroy_link_click=function(e){e.preventDefault(),e.stopPropagation();if(!this.is_disabled)return this.choice_destroy(e.target)},n.prototype.choice_destroy=function(e){if(this.result_deselect(e.readAttribute("rel")))return this.show_search_field_default(),this.is_multiple&&this.choices_count()>0&&this.search_field.value.length<1&&this.results_hide(),e.up("li").remove(),this.search_field_scale()},n.prototype.results_reset=function(){this.form_field.options[0].selected=!0,this.selected_option_count=null,this.selected_item.down("span").update(this.default_text),this.is_multiple||this.selected_item.addClassName("chzn-default"),this.show_search_field_default(),this.results_reset_cleanup(),typeof Event.simulate=="function"&&this.form_field.simulate("change");if(this.active_field)return this.results_hide()},n.prototype.results_reset_cleanup=function(){var e;this.current_selectedIndex=this.form_field.selectedIndex,e=this.selected_item.down("abbr");if(e)return e.remove()},n.prototype.result_select=function(e){var t,n,r;if(this.result_highlight)return t=this.result_highlight,this.result_clear_highlight(),this.is_multiple&&this.max_selected_options<=this.choices_count()?(this.form_field.fire("liszt:maxselected",{chosen:this}),!1):(this.is_multiple?this.result_deactivate(t):(this.search_results.descendants(".result-selected").invoke("removeClassName","result-selected"),this.selected_item.removeClassName("chzn-default"),this.result_single_selected=t),t.addClassName("result-selected"),r=t.id.substr(t.id.lastIndexOf("_")+1),n=this.results_data[r],n.selected=!0,this.form_field.options[n.options_index].selected=!0,this.selected_option_count=null,this.is_multiple?this.choice_build(n):(this.selected_item.down("span").update(n.html),this.allow_single_deselect&&this.single_deselect_control_build()),(!e.metaKey&&!e.ctrlKey||!this.is_multiple)&&this.results_hide(),this.search_field.value="",typeof Event.simulate=="function"&&(this.is_multiple||this.form_field.selectedIndex!==this.current_selectedIndex)&&this.form_field.simulate("change"),this.current_selectedIndex=this.form_field.selectedIndex,this.search_field_scale())},n.prototype.result_activate=function(e){return e.addClassName("active-result")},n.prototype.result_deactivate=function(e){return e.removeClassName("active-result")},n.prototype.result_deselect=function(e){var t,n;return n=this.results_data[e],this.form_field.options[n.options_index].disabled?!1:(n.selected=!1,this.form_field.options[n.options_index].selected=!1,this.selected_option_count=null,t=$(this.container_id+"_o_"+e),t.removeClassName("result-selected").addClassName("active-result").show(),this.result_clear_highlight(),this.winnow_results(),typeof Event.simulate=="function"&&this.form_field.simulate("change"),this.search_field_scale(),!0)},n.prototype.single_deselect_control_build=function(){if(!this.allow_single_deselect)return;return this.selected_item.down("abbr")||this.selected_item.down("span").insert({after:'<abbr class="search-choice-close"></abbr>'}),this.selected_item.addClassName("chzn-single-with-deselect")},n.prototype.winnow_results=function(){var e,t,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y;this.no_results_clear(),a=0,l=!1,f=this.search_field.value===this.default_text?"":this.search_field.value.strip().escapeHTML(),o=this.search_contains?"":"^",s=new RegExp(o+f.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),"i"),p=new RegExp(f.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),"i"),e=new RegExp("^"+f+"$","i"),y=this.results_data;for(d=0,m=y.length;d<m;d++){n=y[d];if(!n.disabled&&!n.empty)if(n.group)$(n.dom_id).hide();else if(!this.is_multiple||!n.selected){t=!1,u=n.dom_id;if(s.test(n.html))t=!0,a+=1;else if(this.enable_split_word_search&&(n.html.indexOf(" ")>=0||n.html.indexOf("[")===0)){i=n.html.replace(/\[|\]/g,"").split(" ");if(i.length)for(v=0,g=i.length;v<g;v++)r=i[v],s.test(r)&&(t=!0,a+=1)}t?(f.length?(c=n.html.search(p),h=n.html.substr(0,c+f.length)+"</em>"+n.html.substr(c+f.length),h=h.substr(0,c)+"<em>"+h.substr(c)):h=n.html,$(u).innerHTML!==h&&$(u).update(h),this.result_activate($(u)),n.group_array_index!=null&&$(this.results_data[n.group_array_index].dom_id).setStyle({display:"list-item"})):($(u)===this.result_highlight&&this.result_clear_highlight(),this.result_deactivate($(u)))}else this.is_multiple&&n.selected&&e.test(n.html)&&(l=!0)}return a<1&&f.length?this.no_results(f,l):this.winnow_results_set_highlight()},n.prototype.winnow_results_clear=function(){var e,t,n,r,i;this.search_field.clear(),t=this.search_results.select("li"),i=[];for(n=0,r=t.length;n<r;n++)e=t[n],e.hasClassName("group-result")?i.push(e.show()):!this.is_multiple||!e.hasClassName("result-selected")?i.push(this.result_activate(e)):i.push(void 0);return i},n.prototype.winnow_results_set_highlight=function(){var e;if(!this.result_highlight){this.is_multiple||(e=this.search_results.down(".result-selected.active-result")),e==null&&(e=this.search_results.down(".active-result"));if(e!=null)return this.result_do_highlight(e)}},n.prototype.no_results=function(e,t){var n,r=this;n="",this.add_option&&!t&&(n=this.add_link_temp.evaluate()),this.search_results.insert(this.no_results_temp.evaluate({terms:e,add_item_link:n}));if(this.options.addOption&&!t)return this.search_results.down("a.option-add").observe("click",function(n){if(!t)return r.select_add_option(e)})},n.prototype.select_add_option=function(e){return Object.isFunction(this.add_option)?this.add_option.call(this,e,this.select_append_option):this.select_append_option({value:e,text:e})},n.prototype.select_append_option=function(e){var t;return t=this.new_option_temp.evaluate({value:e.value,text:e.text}),this.form_field.insert(t),Event.fire(this.form_field,"liszt:updated"),this.result_select()},n.prototype.no_results_clear=function(){var e,t;e=null,t=[];while(e=this.search_results.down(".no-results"))t.push(e.remove());return t},n.prototype.keydown_arrow=function(){var e,t,n;e=this.search_results.select("li.active-result");if(e.length){this.result_highlight?this.results_showing&&(n=this.result_highlight.nextSiblings(),t=n.intersect(e),t.length&&this.result_do_highlight(t.first())):this.result_do_highlight(e.first());if(!this.results_showing)return this.results_show()}},n.prototype.keyup_arrow=function(){var e,t,n;if(!this.results_showing&&!this.is_multiple)return this.results_show();if(this.result_highlight)return n=this.result_highlight.previousSiblings(),e=this.search_results.select("li.active-result"),t=n.intersect(e),t.length?this.result_do_highlight(t.first()):(this.choices_count()>0&&this.results_hide(),this.result_clear_highlight())},n.prototype.keydown_backstroke=function(){var e;if(this.pending_backstroke)return this.choice_destroy(this.pending_backstroke.down("a")),this.clear_backstroke();e=this.search_container.siblings().last();if(e&&e.hasClassName("search-choice")&&!e.hasClassName("search-choice-disabled"))return this.pending_backstroke=e,this.pending_backstroke&&this.pending_backstroke.addClassName("search-choice-focus"),this.single_backstroke_delete?this.keydown_backstroke():this.pending_backstroke.addClassName("search-choice-focus")},n.prototype.clear_backstroke=function(){return this.pending_backstroke&&this.pending_backstroke.removeClassName("search-choice-focus"),this.pending_backstroke=null},n.prototype.keydown_checker=function(e){var t,n;t=(n=e.which)!=null?n:e.keyCode,this.search_field_scale(),t!==8&&this.pending_backstroke&&this.clear_backstroke();switch(t){case 8:this.backstroke_length=this.search_field.value.length;break;case 9:this.results_showing&&!this.is_multiple&&this.result_select(e),this.mouse_on_container=!1;break;case 13:e.preventDefault();break;case 38:e.preventDefault(),this.keyup_arrow();break;case 40:this.keydown_arrow()}},n.prototype.search_field_scale=function(){var e,t,n,r,i,s,o,u;if(this.is_multiple){t=0,s=0,r="position:absolute; left: -1000px; top: -1000px; display:none;",i=["font-size","font-style","font-weight","font-family","line-height","text-transform","letter-spacing"];for(o=0,u=i.length;o<u;o++)n=i[o],r+=n+":"+this.search_field.getStyle(n)+";";return e=(new Element("div",{style:r})).update(this.search_field.value.escapeHTML()),document.body.appendChild(e),s=Element.measure(e,"width")+25,e.remove(),this.f_width||(this.f_width=this.container.getWidth()),s>this.f_width-10&&(s=this.f_width-10),this.search_field.setStyle({width:s+"px"})}},n}(AbstractChosen),t.Chosen=e}.call(this);
View
21 coffee/chosen.proto.coffee
@@ -12,7 +12,7 @@ class @Chosen extends AbstractChosen
@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>".#{add_item_link}</li>')
@new_option_temp = new Template('<option value="#{value}">#{text}</option>')
- @add_link_temp = new Template(' <a href="javascript:void(0);" class="option-add">#{text}</a>')
+ @add_link_temp = new Template(' <a href="javascript:void(0);" class="option-add">' + @add_option_text + '</a>')
set_up_html: ->
container_classes = ["chosen-container"]
@@ -402,27 +402,26 @@ class @Chosen extends AbstractChosen
no_results: (terms, selected) ->
add_item_link = ''
-
- if @options.addOption and not selected
- add_item_link = @add_link_temp.evaluate( text: 'Add this item' )
-
+
+ if @add_option and not selected
+ add_item_link = @add_link_temp.evaluate( )
+
@search_results.insert @no_results_temp.evaluate( terms: terms, add_item_link: add_item_link )
-
+
if @options.addOption and not selected
@search_results.down("a.option-add").observe "click", (evt) => this.select_add_option(terms) unless selected
select_add_option: ( terms ) ->
- if Object.isFunction(@options.addOption)
- @options.addOption.call this, terms, this.select_append_option
+ if Object.isFunction(@add_option)
+ @add_option.call this, terms, this.select_append_option
else
- this.select_append_option( {value: terms, text: terms} )
-
+ this.select_append_option {value: terms, text: terms}
select_append_option: ( options ) ->
###
TODO Close options after adding
###
-
+
option = @new_option_temp.evaluate( value: options.value, text: options.text )
@form_field.insert option
Event.fire @form_field, "liszt:updated"
Please sign in to comment.
Something went wrong with that request. Please try again.