diff --git a/chosen/chosen.jquery.js b/chosen/chosen.jquery.js
index 40ea37861da..36e479b39de 100644
--- a/chosen/chosen.jquery.js
+++ b/chosen/chosen.jquery.js
@@ -726,7 +726,7 @@ Copyright (c) 2011 by Harvest
};
Chosen.prototype.choice_build = function(item) {
- var choice_id, html, link,
+ var choice, close_link,
_this = this;
if (this.is_multiple && this.max_selected_options <= this.choices) {
this.form_field_jq.trigger("liszt:maxselected", {
@@ -734,18 +734,24 @@ Copyright (c) 2011 by Harvest
});
return false;
}
- choice_id = this.container_id + "_c_" + item.array_index;
this.choices += 1;
+ choice = $('
', {
+ "class": "search-choice"
+ }).html("" + item.html + "");
if (item.disabled) {
- html = '' + item.html + '';
+ choice.addClass("search-choice-disabled");
} else {
- html = '' + item.html + '';
+ close_link = $('', {
+ href: '#',
+ "class": 'search-choice-close',
+ rel: item.array_index
+ });
+ close_link.click(function(evt) {
+ return _this.choice_destroy_link_click(evt);
+ });
+ choice.append(close_link);
}
- this.search_container.before(html);
- link = $('#' + choice_id).find("a").first();
- return link.click(function(evt) {
- return _this.choice_destroy_link_click(evt);
- });
+ return this.search_container.before(choice);
};
Chosen.prototype.choice_destroy_link_click = function(evt) {
diff --git a/chosen/chosen.jquery.min.js b/chosen/chosen.jquery.min.js
index 3a41e8a8f7b..a962c92246b 100644
--- a/chosen/chosen.jquery.min.js
+++ b/chosen/chosen.jquery.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"+e.html+"")},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_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>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,r={}.hasOwnProperty,i=function(e,t){function i(){this.constructor=e}for(var n in t)r.call(t,n)&&(e[n]=t[n]);return i.prototype=t.prototype,e.prototype=new i,e.__super__=t.prototype,e};n=this,e=jQuery,e.fn.extend({chosen:function(n){return AbstractChosen.browser_is_supported()?this.each(function(r){var i;i=e(this);if(!i.hasClass("chzn-done"))return i.data("chosen",new t(this,n))}):this}}),t=function(t){function r(){return r.__super__.constructor.apply(this,arguments)}return i(r,t),r.prototype.setup=function(){return this.form_field_jq=e(this.form_field),this.current_selectedIndex=this.form_field.selectedIndex,this.is_rtl=this.form_field_jq.hasClass("chzn-rtl")},r.prototype.finish_setup=function(){return this.form_field_jq.addClass("chzn-done")},r.prototype.set_up_html=function(){var t,n;return this.container_id=this.form_field.id.length?this.form_field.id.replace(/[^\w]/g,"_"):this.generate_field_id(),this.container_id+="_chzn",t=["chzn-container"],t.push("chzn-container-"+(this.is_multiple?"multi":"single")),this.inherit_select_classes&&this.form_field.className&&t.push(this.form_field.className),this.is_rtl&&t.push("chzn-rtl"),n={id:this.container_id,"class":t.join(" "),style:"width: "+this.container_width()+";",title:this.form_field.title},this.container=e("",n),this.is_multiple?this.container.html(''):this.container.html(''+this.default_text+'
'),this.form_field_jq.hide().after(this.container),this.dropdown=this.container.find("div.chzn-drop").first(),this.search_field=this.container.find("input").first(),this.search_results=this.container.find("ul.chzn-results").first(),this.search_field_scale(),this.search_no_results=this.container.find("li.no-results").first(),this.is_multiple?(this.search_choices=this.container.find("ul.chzn-choices").first(),this.search_container=this.container.find("li.search-field").first()):(this.search_container=this.container.find("div.chzn-search").first(),this.selected_item=this.container.find(".chzn-single").first()),this.results_build(),this.set_tab_index(),this.set_label_behavior(),this.form_field_jq.trigger("liszt:ready",{chosen:this})},r.prototype.register_observers=function(){var e=this;return this.container.mousedown(function(t){e.container_mousedown(t)}),this.container.mouseup(function(t){e.container_mouseup(t)}),this.container.mouseenter(function(t){e.mouse_enter(t)}),this.container.mouseleave(function(t){e.mouse_leave(t)}),this.search_results.mouseup(function(t){e.search_results_mouseup(t)}),this.search_results.mouseover(function(t){e.search_results_mouseover(t)}),this.search_results.mouseout(function(t){e.search_results_mouseout(t)}),this.search_results.bind("mousewheel DOMMouseScroll",function(t){e.search_results_mousewheel(t)}),this.form_field_jq.bind("liszt:updated",function(t){e.results_update_field(t)}),this.form_field_jq.bind("liszt:activate",function(t){e.activate_field(t)}),this.form_field_jq.bind("liszt:open",function(t){e.container_mousedown(t)}),this.search_field.blur(function(t){e.input_blur(t)}),this.search_field.keyup(function(t){e.keyup_checker(t)}),this.search_field.keydown(function(t){e.keydown_checker(t)}),this.search_field.focus(function(t){e.input_focus(t)}),this.is_multiple?this.search_choices.click(function(t){e.choices_click(t)}):this.container.click(function(e){e.preventDefault()})},r.prototype.search_field_disabled=function(){this.is_disabled=this.form_field_jq[0].disabled;if(this.is_disabled)return this.container.addClass("chzn-disabled"),this.search_field[0].disabled=!0,this.is_multiple||this.selected_item.unbind("focus",this.activate_action),this.close_field();this.container.removeClass("chzn-disabled"),this.search_field[0].disabled=!1;if(!this.is_multiple)return this.selected_item.bind("focus",this.activate_action)},r.prototype.container_mousedown=function(t){if(!this.is_disabled){t&&t.type==="mousedown"&&!this.results_showing&&t.preventDefault();if(t==null||!e(t.target).hasClass("search-choice-close"))return this.active_field?!this.is_multiple&&t&&(e(t.target)[0]===this.selected_item[0]||e(t.target).parents("a.chzn-single").length)&&(t.preventDefault(),this.results_toggle()):(this.is_multiple&&this.search_field.val(""),e(document).click(this.click_test_action),this.results_show()),this.activate_field()}},r.prototype.container_mouseup=function(e){if(e.target.nodeName==="ABBR"&&!this.is_disabled)return this.results_reset(e)},r.prototype.search_results_mousewheel=function(e){var t,n,r;t=-((n=e.originalEvent)!=null?n.wheelDelta:void 0)||((r=e.originialEvent)!=null?r.detail:void 0);if(t!=null)return e.preventDefault(),e.type==="DOMMouseScroll"&&(t*=40),this.search_results.scrollTop(t+this.search_results.scrollTop())},r.prototype.blur_test=function(e){if(!this.active_field&&this.container.hasClass("chzn-container-active"))return this.close_field()},r.prototype.close_field=function(){return e(document).unbind("click",this.click_test_action),this.active_field=!1,this.results_hide(),this.container.removeClass("chzn-container-active"),this.winnow_results_clear(),this.clear_backstroke(),this.show_search_field_default(),this.search_field_scale()},r.prototype.activate_field=function(){return this.container.addClass("chzn-container-active"),this.active_field=!0,this.search_field.val(this.search_field.val()),this.search_field.focus()},r.prototype.test_active_click=function(t){return e(t.target).parents("#"+this.container_id).length?this.active_field=!0:this.close_field()},r.prototype.results_build=function(){var e,t,r,i,s;this.parsing=!0,this.results_data=n.SelectParser.select_to_array(this.form_field),this.is_multiple&&this.choices>0?(this.search_choices.find("li.search-choice").remove(),this.choices=0):this.is_multiple||(this.selected_item.addClass("chzn-default").find("span").text(this.default_text),this.disable_search||this.form_field.options.length<=this.disable_search_threshold?this.container.addClass("chzn-container-single-nosearch"):this.container.removeClass("chzn-container-single-nosearch")),e="",s=this.results_data;for(r=0,i=s.length;r'+e("").text(t.label).html()+"")},r.prototype.result_do_highlight=function(e){var t,n,r,i,s;if(e.length){this.result_clear_highlight(),this.result_highlight=e,this.result_highlight.addClass("highlighted"),r=parseInt(this.search_results.css("maxHeight"),10),s=this.search_results.scrollTop(),i=r+s,n=this.result_highlight.position().top+this.search_results.scrollTop(),t=n+this.result_highlight.outerHeight();if(t>=i)return this.search_results.scrollTop(t-r>0?t-r:0);if(n0)return this.form_field_label.click(function(e){return t.is_multiple?t.container_mousedown(e):t.activate_field()})},r.prototype.show_search_field_default=function(){return this.is_multiple&&this.choices<1&&!this.active_field?(this.search_field.val(this.default_text),this.search_field.addClass("default")):(this.search_field.val(""),this.search_field.removeClass("default"))},r.prototype.search_results_mouseup=function(t){var n;n=e(t.target).hasClass("active-result")?e(t.target):e(t.target).parents(".active-result").first();if(n.length)return this.result_highlight=n,this.result_select(t),this.search_field.focus()},r.prototype.search_results_mouseover=function(t){var n;n=e(t.target).hasClass("active-result")?e(t.target):e(t.target).parents(".active-result").first();if(n)return this.result_do_highlight(n)},r.prototype.search_results_mouseout=function(t){if(e(t.target).hasClass("active-result"))return this.result_clear_highlight()},r.prototype.choice_build=function(t){var n,r,i,s=this;return this.is_multiple&&this.max_selected_options<=this.choices?(this.form_field_jq.trigger("liszt:maxselected",{chosen:this}),!1):(n=this.container_id+"_c_"+t.array_index,this.choices+=1,t.disabled?r=''+t.html+"":r=''+t.html+'',this.search_container.before(r),i=e("#"+n).find("a").first(),i.click(function(e){return s.choice_destroy_link_click(e)}))},r.prototype.choice_destroy_link_click=function(t){t.preventDefault(),t.stopPropagation();if(!this.is_disabled)return this.choice_destroy(e(t.target))},r.prototype.choice_destroy=function(e){if(this.result_deselect(e.attr("rel")))return this.choices-=1,this.show_search_field_default(),this.is_multiple&&this.choices>0&&this.search_field.val().length<1&&this.results_hide(),e.parents("li").first().remove(),this.search_field_scale()},r.prototype.results_reset=function(){this.form_field.options[0].selected=!0,this.selected_item.find("span").text(this.default_text),this.is_multiple||this.selected_item.addClass("chzn-default"),this.show_search_field_default(),this.results_reset_cleanup(),this.form_field_jq.trigger("change");if(this.active_field)return this.results_hide()},r.prototype.results_reset_cleanup=function(){return this.current_selectedIndex=this.form_field.selectedIndex,this.selected_item.find("abbr").remove()},r.prototype.result_select=function(e){var t,n,r,i;if(this.result_highlight)return t=this.result_highlight,n=t.attr("id"),this.result_clear_highlight(),this.is_multiple?this.result_deactivate(t):(this.search_results.find(".result-selected").removeClass("result-selected"),this.result_single_selected=t,this.selected_item.removeClass("chzn-default")),t.addClass("result-selected"),i=n.substr(n.lastIndexOf("_")+1),r=this.results_data[i],r.selected=!0,this.form_field.options[r.options_index].selected=!0,this.is_multiple?this.choice_build(r):(this.selected_item.find("span").first().text(r.text),this.allow_single_deselect&&this.single_deselect_control_build()),(!e.metaKey&&!e.ctrlKey||!this.is_multiple)&&this.results_hide(),this.search_field.val(""),(this.is_multiple||this.form_field.selectedIndex!==this.current_selectedIndex)&&this.form_field_jq.trigger("change",{selected:this.form_field.options[r.options_index].value}),this.current_selectedIndex=this.form_field.selectedIndex,this.search_field_scale()},r.prototype.result_activate=function(e){return e.addClass("active-result")},r.prototype.result_deactivate=function(e){return e.removeClass("active-result")},r.prototype.result_deselect=function(t){var n,r;return r=this.results_data[t],this.form_field.options[r.options_index].disabled?!1:(r.selected=!1,this.form_field.options[r.options_index].selected=!1,n=e("#"+this.container_id+"_o_"+t),n.removeClass("result-selected").addClass("active-result").show(),this.result_clear_highlight(),this.winnow_results(),this.form_field_jq.trigger("change",{deselected:this.form_field.options[r.options_index].value}),this.search_field_scale(),!0)},r.prototype.single_deselect_control_build=function(){if(this.allow_single_deselect&&this.selected_item.find("abbr").length<1)return this.selected_item.find("span").first().after('')},r.prototype.winnow_results=function(){var t,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y;this.no_results_clear(),f=0,l=this.search_field.val()===this.default_text?"":e("").text(e.trim(this.search_field.val())).html(),o=this.search_contains?"":"^",s=new RegExp(o+l.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),"i"),p=new RegExp(l.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),"i"),y=this.results_data;for(d=0,m=y.length;d=0||n.html.indexOf("[")===0)){i=n.html.replace(/\[|\]/g,"").split(" ");if(i.length)for(v=0,g=i.length;v"+n.html.substr(c+l.length),h=h.substr(0,c)+""+h.substr(c)):h=n.html,u.html(h),this.result_activate(u),n.group_array_index!=null&&e("#"+this.results_data[n.group_array_index].dom_id).css("display","list-item")):(this.result_highlight&&a===this.result_highlight.attr("id")&&this.result_clear_highlight(),this.result_deactivate(u))}}return f<1&&l.length?this.no_results(l):this.winnow_results_set_highlight()},r.prototype.winnow_results_clear=function(){var t,n,r,i,s;this.search_field.val(""),n=this.search_results.find("li"),s=[];for(r=0,i=n.length;r'+this.results_none_found+' ""'),n.find("span").first().html(t),this.search_results.append(n)},r.prototype.no_results_clear=function(){return this.search_results.find(".no-results").remove()},r.prototype.keydown_arrow=function(){var t,n;this.result_highlight?this.results_showing&&(n=this.result_highlight.nextAll("li.active-result").first(),n&&this.result_do_highlight(n)):(t=this.search_results.find("li.active-result").first(),t&&this.result_do_highlight(e(t)));if(!this.results_showing)return this.results_show()},r.prototype.keyup_arrow=function(){var e;if(!this.results_showing&&!this.is_multiple)return this.results_show();if(this.result_highlight)return e=this.result_highlight.prevAll("li.active-result"),e.length?this.result_do_highlight(e.first()):(this.choices>0&&this.results_hide(),this.result_clear_highlight())},r.prototype.keydown_backstroke=function(){var e;if(this.pending_backstroke)return this.choice_destroy(this.pending_backstroke.find("a").first()),this.clear_backstroke();e=this.search_container.siblings("li.search-choice").last();if(e.length&&!e.hasClass("search-choice-disabled"))return this.pending_backstroke=e,this.single_backstroke_delete?this.keydown_backstroke():this.pending_backstroke.addClass("search-choice-focus")},r.prototype.clear_backstroke=function(){return this.pending_backstroke&&this.pending_backstroke.removeClass("search-choice-focus"),this.pending_backstroke=null},r.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.val().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()}},r.prototype.search_field_scale=function(){var t,n,r,i,s,o,u,a;if(this.is_multiple){n=0,o=0,i="position:absolute; left: -1000px; top: -1000px; display:none;",s=["font-size","font-style","font-weight","font-family","line-height","text-transform","letter-spacing"];for(u=0,a=s.length;u",{style:i}),t.text(this.search_field.val()),e("body").append(t),o=t.width()+25,t.remove(),this.f_width||(this.f_width=this.container.outerWidth()),o>this.f_width-10&&(o=this.f_width-10),this.search_field.css({width:o+"px"})}},r.prototype.generate_random_id=function(){var t;t="sel"+this.generate_random_char()+this.generate_random_char()+this.generate_random_char();while(e("#"+t).length>0)t+=this.generate_random_char();return t},r}(AbstractChosen),n.Chosen=t}.call(this);
\ No newline at end of file
+(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"+e.html+"")},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_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>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,r={}.hasOwnProperty,i=function(e,t){function i(){this.constructor=e}for(var n in t)r.call(t,n)&&(e[n]=t[n]);return i.prototype=t.prototype,e.prototype=new i,e.__super__=t.prototype,e};n=this,e=jQuery,e.fn.extend({chosen:function(n){return AbstractChosen.browser_is_supported()?this.each(function(r){var i;i=e(this);if(!i.hasClass("chzn-done"))return i.data("chosen",new t(this,n))}):this}}),t=function(t){function r(){return r.__super__.constructor.apply(this,arguments)}return i(r,t),r.prototype.setup=function(){return this.form_field_jq=e(this.form_field),this.current_selectedIndex=this.form_field.selectedIndex,this.is_rtl=this.form_field_jq.hasClass("chzn-rtl")},r.prototype.finish_setup=function(){return this.form_field_jq.addClass("chzn-done")},r.prototype.set_up_html=function(){var t,n;return this.container_id=this.form_field.id.length?this.form_field.id.replace(/[^\w]/g,"_"):this.generate_field_id(),this.container_id+="_chzn",t=["chzn-container"],t.push("chzn-container-"+(this.is_multiple?"multi":"single")),this.inherit_select_classes&&this.form_field.className&&t.push(this.form_field.className),this.is_rtl&&t.push("chzn-rtl"),n={id:this.container_id,"class":t.join(" "),style:"width: "+this.container_width()+";",title:this.form_field.title},this.container=e("",n),this.is_multiple?this.container.html(''):this.container.html(''+this.default_text+'
'),this.form_field_jq.hide().after(this.container),this.dropdown=this.container.find("div.chzn-drop").first(),this.search_field=this.container.find("input").first(),this.search_results=this.container.find("ul.chzn-results").first(),this.search_field_scale(),this.search_no_results=this.container.find("li.no-results").first(),this.is_multiple?(this.search_choices=this.container.find("ul.chzn-choices").first(),this.search_container=this.container.find("li.search-field").first()):(this.search_container=this.container.find("div.chzn-search").first(),this.selected_item=this.container.find(".chzn-single").first()),this.results_build(),this.set_tab_index(),this.set_label_behavior(),this.form_field_jq.trigger("liszt:ready",{chosen:this})},r.prototype.register_observers=function(){var e=this;return this.container.mousedown(function(t){e.container_mousedown(t)}),this.container.mouseup(function(t){e.container_mouseup(t)}),this.container.mouseenter(function(t){e.mouse_enter(t)}),this.container.mouseleave(function(t){e.mouse_leave(t)}),this.search_results.mouseup(function(t){e.search_results_mouseup(t)}),this.search_results.mouseover(function(t){e.search_results_mouseover(t)}),this.search_results.mouseout(function(t){e.search_results_mouseout(t)}),this.search_results.bind("mousewheel DOMMouseScroll",function(t){e.search_results_mousewheel(t)}),this.form_field_jq.bind("liszt:updated",function(t){e.results_update_field(t)}),this.form_field_jq.bind("liszt:activate",function(t){e.activate_field(t)}),this.form_field_jq.bind("liszt:open",function(t){e.container_mousedown(t)}),this.search_field.blur(function(t){e.input_blur(t)}),this.search_field.keyup(function(t){e.keyup_checker(t)}),this.search_field.keydown(function(t){e.keydown_checker(t)}),this.search_field.focus(function(t){e.input_focus(t)}),this.is_multiple?this.search_choices.click(function(t){e.choices_click(t)}):this.container.click(function(e){e.preventDefault()})},r.prototype.search_field_disabled=function(){this.is_disabled=this.form_field_jq[0].disabled;if(this.is_disabled)return this.container.addClass("chzn-disabled"),this.search_field[0].disabled=!0,this.is_multiple||this.selected_item.unbind("focus",this.activate_action),this.close_field();this.container.removeClass("chzn-disabled"),this.search_field[0].disabled=!1;if(!this.is_multiple)return this.selected_item.bind("focus",this.activate_action)},r.prototype.container_mousedown=function(t){if(!this.is_disabled){t&&t.type==="mousedown"&&!this.results_showing&&t.preventDefault();if(t==null||!e(t.target).hasClass("search-choice-close"))return this.active_field?!this.is_multiple&&t&&(e(t.target)[0]===this.selected_item[0]||e(t.target).parents("a.chzn-single").length)&&(t.preventDefault(),this.results_toggle()):(this.is_multiple&&this.search_field.val(""),e(document).click(this.click_test_action),this.results_show()),this.activate_field()}},r.prototype.container_mouseup=function(e){if(e.target.nodeName==="ABBR"&&!this.is_disabled)return this.results_reset(e)},r.prototype.search_results_mousewheel=function(e){var t,n,r;t=-((n=e.originalEvent)!=null?n.wheelDelta:void 0)||((r=e.originialEvent)!=null?r.detail:void 0);if(t!=null)return e.preventDefault(),e.type==="DOMMouseScroll"&&(t*=40),this.search_results.scrollTop(t+this.search_results.scrollTop())},r.prototype.blur_test=function(e){if(!this.active_field&&this.container.hasClass("chzn-container-active"))return this.close_field()},r.prototype.close_field=function(){return e(document).unbind("click",this.click_test_action),this.active_field=!1,this.results_hide(),this.container.removeClass("chzn-container-active"),this.winnow_results_clear(),this.clear_backstroke(),this.show_search_field_default(),this.search_field_scale()},r.prototype.activate_field=function(){return this.container.addClass("chzn-container-active"),this.active_field=!0,this.search_field.val(this.search_field.val()),this.search_field.focus()},r.prototype.test_active_click=function(t){return e(t.target).parents("#"+this.container_id).length?this.active_field=!0:this.close_field()},r.prototype.results_build=function(){var e,t,r,i,s;this.parsing=!0,this.results_data=n.SelectParser.select_to_array(this.form_field),this.is_multiple&&this.choices>0?(this.search_choices.find("li.search-choice").remove(),this.choices=0):this.is_multiple||(this.selected_item.addClass("chzn-default").find("span").text(this.default_text),this.disable_search||this.form_field.options.length<=this.disable_search_threshold?this.container.addClass("chzn-container-single-nosearch"):this.container.removeClass("chzn-container-single-nosearch")),e="",s=this.results_data;for(r=0,i=s.length;r'+e("").text(t.label).html()+"")},r.prototype.result_do_highlight=function(e){var t,n,r,i,s;if(e.length){this.result_clear_highlight(),this.result_highlight=e,this.result_highlight.addClass("highlighted"),r=parseInt(this.search_results.css("maxHeight"),10),s=this.search_results.scrollTop(),i=r+s,n=this.result_highlight.position().top+this.search_results.scrollTop(),t=n+this.result_highlight.outerHeight();if(t>=i)return this.search_results.scrollTop(t-r>0?t-r:0);if(n0)return this.form_field_label.click(function(e){return t.is_multiple?t.container_mousedown(e):t.activate_field()})},r.prototype.show_search_field_default=function(){return this.is_multiple&&this.choices<1&&!this.active_field?(this.search_field.val(this.default_text),this.search_field.addClass("default")):(this.search_field.val(""),this.search_field.removeClass("default"))},r.prototype.search_results_mouseup=function(t){var n;n=e(t.target).hasClass("active-result")?e(t.target):e(t.target).parents(".active-result").first();if(n.length)return this.result_highlight=n,this.result_select(t),this.search_field.focus()},r.prototype.search_results_mouseover=function(t){var n;n=e(t.target).hasClass("active-result")?e(t.target):e(t.target).parents(".active-result").first();if(n)return this.result_do_highlight(n)},r.prototype.search_results_mouseout=function(t){if(e(t.target).hasClass("active-result"))return this.result_clear_highlight()},r.prototype.choice_build=function(t){var n,r,i=this;return this.is_multiple&&this.max_selected_options<=this.choices?(this.form_field_jq.trigger("liszt:maxselected",{chosen:this}),!1):(this.choices+=1,n=e("",{"class":"search-choice"}).html(""+t.html+""),t.disabled?n.addClass("search-choice-disabled"):(r=e("",{href:"#","class":"search-choice-close",rel:t.array_index}),r.click(function(e){return i.choice_destroy_link_click(e)}),n.append(r)),this.search_container.before(n))},r.prototype.choice_destroy_link_click=function(t){t.preventDefault(),t.stopPropagation();if(!this.is_disabled)return this.choice_destroy(e(t.target))},r.prototype.choice_destroy=function(e){if(this.result_deselect(e.attr("rel")))return this.choices-=1,this.show_search_field_default(),this.is_multiple&&this.choices>0&&this.search_field.val().length<1&&this.results_hide(),e.parents("li").first().remove(),this.search_field_scale()},r.prototype.results_reset=function(){this.form_field.options[0].selected=!0,this.selected_item.find("span").text(this.default_text),this.is_multiple||this.selected_item.addClass("chzn-default"),this.show_search_field_default(),this.results_reset_cleanup(),this.form_field_jq.trigger("change");if(this.active_field)return this.results_hide()},r.prototype.results_reset_cleanup=function(){return this.current_selectedIndex=this.form_field.selectedIndex,this.selected_item.find("abbr").remove()},r.prototype.result_select=function(e){var t,n,r,i;if(this.result_highlight)return t=this.result_highlight,n=t.attr("id"),this.result_clear_highlight(),this.is_multiple?this.result_deactivate(t):(this.search_results.find(".result-selected").removeClass("result-selected"),this.result_single_selected=t,this.selected_item.removeClass("chzn-default")),t.addClass("result-selected"),i=n.substr(n.lastIndexOf("_")+1),r=this.results_data[i],r.selected=!0,this.form_field.options[r.options_index].selected=!0,this.is_multiple?this.choice_build(r):(this.selected_item.find("span").first().text(r.text),this.allow_single_deselect&&this.single_deselect_control_build()),(!e.metaKey&&!e.ctrlKey||!this.is_multiple)&&this.results_hide(),this.search_field.val(""),(this.is_multiple||this.form_field.selectedIndex!==this.current_selectedIndex)&&this.form_field_jq.trigger("change",{selected:this.form_field.options[r.options_index].value}),this.current_selectedIndex=this.form_field.selectedIndex,this.search_field_scale()},r.prototype.result_activate=function(e){return e.addClass("active-result")},r.prototype.result_deactivate=function(e){return e.removeClass("active-result")},r.prototype.result_deselect=function(t){var n,r;return r=this.results_data[t],this.form_field.options[r.options_index].disabled?!1:(r.selected=!1,this.form_field.options[r.options_index].selected=!1,n=e("#"+this.container_id+"_o_"+t),n.removeClass("result-selected").addClass("active-result").show(),this.result_clear_highlight(),this.winnow_results(),this.form_field_jq.trigger("change",{deselected:this.form_field.options[r.options_index].value}),this.search_field_scale(),!0)},r.prototype.single_deselect_control_build=function(){if(this.allow_single_deselect&&this.selected_item.find("abbr").length<1)return this.selected_item.find("span").first().after('')},r.prototype.winnow_results=function(){var t,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y;this.no_results_clear(),f=0,l=this.search_field.val()===this.default_text?"":e("").text(e.trim(this.search_field.val())).html(),o=this.search_contains?"":"^",s=new RegExp(o+l.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),"i"),p=new RegExp(l.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),"i"),y=this.results_data;for(d=0,m=y.length;d=0||n.html.indexOf("[")===0)){i=n.html.replace(/\[|\]/g,"").split(" ");if(i.length)for(v=0,g=i.length;v"+n.html.substr(c+l.length),h=h.substr(0,c)+""+h.substr(c)):h=n.html,u.html(h),this.result_activate(u),n.group_array_index!=null&&e("#"+this.results_data[n.group_array_index].dom_id).css("display","list-item")):(this.result_highlight&&a===this.result_highlight.attr("id")&&this.result_clear_highlight(),this.result_deactivate(u))}}return f<1&&l.length?this.no_results(l):this.winnow_results_set_highlight()},r.prototype.winnow_results_clear=function(){var t,n,r,i,s;this.search_field.val(""),n=this.search_results.find("li"),s=[];for(r=0,i=n.length;r'+this.results_none_found+' ""'),n.find("span").first().html(t),this.search_results.append(n)},r.prototype.no_results_clear=function(){return this.search_results.find(".no-results").remove()},r.prototype.keydown_arrow=function(){var t,n;this.result_highlight?this.results_showing&&(n=this.result_highlight.nextAll("li.active-result").first(),n&&this.result_do_highlight(n)):(t=this.search_results.find("li.active-result").first(),t&&this.result_do_highlight(e(t)));if(!this.results_showing)return this.results_show()},r.prototype.keyup_arrow=function(){var e;if(!this.results_showing&&!this.is_multiple)return this.results_show();if(this.result_highlight)return e=this.result_highlight.prevAll("li.active-result"),e.length?this.result_do_highlight(e.first()):(this.choices>0&&this.results_hide(),this.result_clear_highlight())},r.prototype.keydown_backstroke=function(){var e;if(this.pending_backstroke)return this.choice_destroy(this.pending_backstroke.find("a").first()),this.clear_backstroke();e=this.search_container.siblings("li.search-choice").last();if(e.length&&!e.hasClass("search-choice-disabled"))return this.pending_backstroke=e,this.single_backstroke_delete?this.keydown_backstroke():this.pending_backstroke.addClass("search-choice-focus")},r.prototype.clear_backstroke=function(){return this.pending_backstroke&&this.pending_backstroke.removeClass("search-choice-focus"),this.pending_backstroke=null},r.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.val().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()}},r.prototype.search_field_scale=function(){var t,n,r,i,s,o,u,a;if(this.is_multiple){n=0,o=0,i="position:absolute; left: -1000px; top: -1000px; display:none;",s=["font-size","font-style","font-weight","font-family","line-height","text-transform","letter-spacing"];for(u=0,a=s.length;u",{style:i}),t.text(this.search_field.val()),e("body").append(t),o=t.width()+25,t.remove(),this.f_width||(this.f_width=this.container.outerWidth()),o>this.f_width-10&&(o=this.f_width-10),this.search_field.css({width:o+"px"})}},r.prototype.generate_random_id=function(){var t;t="sel"+this.generate_random_char()+this.generate_random_char()+this.generate_random_char();while(e("#"+t).length>0)t+=this.generate_random_char();return t},r}(AbstractChosen),n.Chosen=t}.call(this);
\ No newline at end of file
diff --git a/chosen/chosen.proto.js b/chosen/chosen.proto.js
index 88da0caa751..f1bd4edd5ce 100644
--- a/chosen/chosen.proto.js
+++ b/chosen/chosen.proto.js
@@ -356,8 +356,6 @@ Copyright (c) 2011 by Harvest
Chosen.__super__.set_default_values.call(this);
this.single_temp = new Template('#{default}
');
this.multi_temp = new Template('');
- this.choice_temp = new Template('#{choice}');
- this.choice_noclose_temp = new Template('#{choice}');
return this.no_results_temp = new Template('' + this.results_none_found + ' "#{terms}"');
};
@@ -717,7 +715,7 @@ Copyright (c) 2011 by Harvest
};
Chosen.prototype.choice_build = function(item) {
- var choice_id, link,
+ var choice, close_link,
_this = this;
if (this.is_multiple && this.max_selected_options <= this.choices) {
this.form_field.fire("liszt:maxselected", {
@@ -725,21 +723,26 @@ Copyright (c) 2011 by Harvest
});
return false;
}
- choice_id = this.container_id + "_c_" + item.array_index;
this.choices += 1;
- this.search_container.insert({
- before: (item.disabled ? this.choice_noclose_temp : this.choice_temp).evaluate({
- id: choice_id,
- choice: item.html,
- position: item.array_index
- })
- });
- if (!item.disabled) {
- link = $(choice_id).down('a');
- return link.observe("click", function(evt) {
+ choice = new Element('li', {
+ "class": "search-choice"
+ }).update("" + item.html + "");
+ 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", function(evt) {
return _this.choice_destroy_link_click(evt);
});
+ choice.insert(close_link);
}
+ return this.search_container.insert({
+ before: choice
+ });
};
Chosen.prototype.choice_destroy_link_click = function(evt) {
diff --git a/chosen/chosen.proto.min.js b/chosen/chosen.proto.min.js
index 888bec57865..d29e7d6a9b3 100644
--- a/chosen/chosen.proto.min.js
+++ b/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"+e.html+"")},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_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>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('#{default}
'),this.multi_temp=new Template(''),this.choice_temp=new Template('#{choice}'),this.choice_noclose_temp=new Template('#{choice}'),this.no_results_temp=new Template(''+this.results_none_found+' "#{terms}"')},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.results_data=t.SelectParser.select_to_array(this.form_field),this.is_multiple&&this.choices>0?(this.search_choices.select("li.search-choice").invoke("remove"),this.choices=0):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'+e.label.escapeHTML()+"")},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(n0&&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_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.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.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,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&&!this.selected_item.down("abbr"))return this.selected_item.down("span").insert({after:''})},n.prototype.winnow_results=function(){var e,t,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m;this.no_results_clear(),u=0,a=this.search_field.value===this.default_text?"":this.search_field.value.strip().escapeHTML(),s=this.search_contains?"":"^",i=new RegExp(s+a.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),"i"),c=new RegExp(a.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),"i"),m=this.results_data;for(h=0,d=m.length;h=0||t.html.indexOf("[")===0)){r=t.html.replace(/\[|\]/g,"").split(" ");if(r.length)for(p=0,v=r.length;p"+t.html.substr(f+a.length),l=l.substr(0,f)+""+l.substr(f)):l=t.html,$(o).innerHTML!==l&&$(o).update(l),this.result_activate($(o)),t.group_array_index!=null&&$(this.results_data[t.group_array_index].dom_id).setStyle({display:"list-item"})):($(o)===this.result_highlight&&this.result_clear_highlight(),this.result_deactivate($(o)))}}return u<1&&a.length?this.no_results(a):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;n0&&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;othis.f_width-10&&(s=this.f_width-10),this.search_field.setStyle({width:s+"px"})}},n}(AbstractChosen),t.Chosen=e}.call(this);
\ No newline at end of file
+(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"+e.html+"")},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_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>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('#{default}
'),this.multi_temp=new Template(''),this.no_results_temp=new Template(''+this.results_none_found+' "#{terms}"')},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.results_data=t.SelectParser.select_to_array(this.form_field),this.is_multiple&&this.choices>0?(this.search_choices.select("li.search-choice").invoke("remove"),this.choices=0):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'+e.label.escapeHTML()+"")},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"+e.html+""),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.choices-=1,this.show_search_field_default(),this.is_multiple&&this.choices>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_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.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.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,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&&!this.selected_item.down("abbr"))return this.selected_item.down("span").insert({after:''})},n.prototype.winnow_results=function(){var e,t,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m;this.no_results_clear(),u=0,a=this.search_field.value===this.default_text?"":this.search_field.value.strip().escapeHTML(),s=this.search_contains?"":"^",i=new RegExp(s+a.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),"i"),c=new RegExp(a.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),"i"),m=this.results_data;for(h=0,d=m.length;h=0||t.html.indexOf("[")===0)){r=t.html.replace(/\[|\]/g,"").split(" ");if(r.length)for(p=0,v=r.length;p"+t.html.substr(f+a.length),l=l.substr(0,f)+""+l.substr(f)):l=t.html,$(o).innerHTML!==l&&$(o).update(l),this.result_activate($(o)),t.group_array_index!=null&&$(this.results_data[t.group_array_index].dom_id).setStyle({display:"list-item"})):($(o)===this.result_highlight&&this.result_clear_highlight(),this.result_deactivate($(o)))}}return u<1&&a.length?this.no_results(a):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;n0&&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;othis.f_width-10&&(s=this.f_width-10),this.search_field.setStyle({width:s+"px"})}},n}(AbstractChosen),t.Chosen=e}.call(this);
\ No newline at end of file
diff --git a/coffee/chosen.jquery.coffee b/coffee/chosen.jquery.coffee
index 0df0f2d35ca..32decefa4ef 100644
--- a/coffee/chosen.jquery.coffee
+++ b/coffee/chosen.jquery.coffee
@@ -291,16 +291,20 @@ class Chosen extends AbstractChosen
choice_build: (item) ->
if @is_multiple and @max_selected_options <= @choices
@form_field_jq.trigger("liszt:maxselected", {chosen: this})
- return false # fire event
- choice_id = @container_id + "_c_" + item.array_index
+ return false
+
@choices += 1
+
+ choice = $('', { class: "search-choice" }).html("#{item.html}")
+
if item.disabled
- html = '' + item.html + ''
+ choice.addClass 'search-choice-disabled'
else
- html = '' + item.html + ''
- @search_container.before html
- link = $('#' + choice_id).find("a").first()
- link.click (evt) => this.choice_destroy_link_click(evt)
+ close_link = $('', { href: '#', class: 'search-choice-close', rel: item.array_index })
+ close_link.click (evt) => this.choice_destroy_link_click(evt)
+ choice.append close_link
+
+ @search_container.before choice
choice_destroy_link_click: (evt) ->
evt.preventDefault()
diff --git a/coffee/chosen.proto.coffee b/coffee/chosen.proto.coffee
index 5d1adb46b4e..1f77a310982 100644
--- a/coffee/chosen.proto.coffee
+++ b/coffee/chosen.proto.coffee
@@ -19,8 +19,6 @@ class Chosen extends AbstractChosen
# HTML Templates
@single_temp = new Template('#{default}
')
@multi_temp = new Template('')
- @choice_temp = new Template('#{choice}')
- @choice_noclose_temp = new Template('#{choice}')
@no_results_temp = new Template('' + @results_none_found + ' "#{terms}"')
set_up_html: ->
@@ -281,16 +279,19 @@ class Chosen extends AbstractChosen
if @is_multiple and @max_selected_options <= @choices
@form_field.fire("liszt:maxselected", {chosen: this})
return false
- choice_id = @container_id + "_c_" + item.array_index
+
@choices += 1
- @search_container.insert
- before: (if item.disabled then @choice_noclose_temp else @choice_temp).evaluate
- id: choice_id
- choice: item.html
- position: item.array_index
- if not item.disabled
- link = $(choice_id).down('a')
- link.observe "click", (evt) => this.choice_destroy_link_click(evt)
+
+ choice = new Element('li', { class: "search-choice" }).update("#{item.html}")
+
+ 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)
+ choice.insert close_link
+
+ @search_container.insert { before: choice }
choice_destroy_link_click: (evt) ->
evt.preventDefault()