| 10 | | (function(){var a,b,c,d,e=function(a,b){return function(){return a.apply(b,arguments)}};d=this,a=jQuery,a.fn.extend({chosen:function(c){return a.browser!=="msie"||a.browser.version!=="6.0"&&a.browser.version!=="7.0"?a(this).each(function(d){if(!a(this).hasClass("chzn-done"))return new b(this,c)}):this}}),b=function(){function b(b,c){this.options=c||{},this.set_default_values(),this.form_field=b,this.form_field_jq=a(this.form_field),this.is_multiple=this.form_field.multiple,this.is_rtl=this.form_field_jq.hasClass("chzn-rtl"),this.default_text_default=this.form_field.multiple?"Select Some Options":"Select an Option",this.set_up_html(),this.register_observers(),this.form_field_jq.addClass("chzn-done")}b.prototype.set_default_values=function(){this.click_test_action=e(function(a){return this.test_active_click(a)},this),this.active_field=!1,this.mouse_on_container=!1,this.results_showing=!1,this.result_highlighted=null,this.result_single_selected=null,this.choices=0;return this.results_none_found=this.options.no_results_text||"No results match"},b.prototype.set_up_html=function(){var b,d,e,f;this.container_id=this.form_field.id.length?this.form_field.id.replace(/(:|\.)/g,"_"):this.generate_field_id(),this.container_id+="_chzn",this.f_width=this.form_field_jq.outerWidth(),this.default_text=this.form_field_jq.data("placeholder")?this.form_field_jq.data("placeholder"):this.default_text_default,b=a("<div />",{id:this.container_id,"class":"chzn-container "+(this.is_rtl?"chzn-rtl":""),style:"width: "+this.f_width+"px;"}),this.is_multiple?b.html('<ul class="chzn-choices"><li class="search-field"><input type="text" value="'+this.default_text+'" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chzn-drop" style="left:-9000px;"><ul class="chzn-results"></ul></div>'):b.html('<a href="javascript:void(0)" class="chzn-single"><span>'+this.default_text+'</span><div><b></b></div></a><div class="chzn-drop" style="left:-9000px;"><div class="chzn-search"><input type="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>'),this.form_field_jq.hide().after(b),this.container=a("#"+this.container_id),this.container.addClass("chzn-container-"+(this.is_multiple?"multi":"single")),this.dropdown=this.container.find("div.chzn-drop").first(),d=this.container.height(),e=this.f_width-c(this.dropdown),this.dropdown.css({width:e+"px",top:d+"px"}),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(),f=e-c(this.search_container)-c(this.search_field),this.search_field.css({width:f+"px"})),this.results_build();return this.set_tab_index()},b.prototype.register_observers=function(){this.container.mousedown(e(function(a){return this.container_mousedown(a)},this)),this.container.mouseenter(e(function(a){return this.mouse_enter(a)},this)),this.container.mouseleave(e(function(a){return this.mouse_leave(a)},this)),this.search_results.mouseup(e(function(a){return this.search_results_mouseup(a)},this)),this.search_results.mouseover(e(function(a){return this.search_results_mouseover(a)},this)),this.search_results.mouseout(e(function(a){return this.search_results_mouseout(a)},this)),this.form_field_jq.bind("liszt:updated",e(function(a){return this.results_update_field(a)},this)),this.search_field.blur(e(function(a){return this.input_blur(a)},this)),this.search_field.keyup(e(function(a){return this.keyup_checker(a)},this)),this.search_field.keydown(e(function(a){return this.keydown_checker(a)},this));if(this.is_multiple){this.search_choices.click(e(function(a){return this.choices_click(a)},this));return this.search_field.focus(e(function(a){return this.input_focus(a)},this))}return this.selected_item.focus(e(function(a){return this.activate_field(a)},this))},b.prototype.container_mousedown=function(b){b&&b.type==="mousedown"&&b.stopPropagation();if(!this.pending_destroy_click){this.active_field?!this.is_multiple&&b&&(a(b.target)===this.selected_item||a(b.target).parents("a.chzn-single").length)&&(b.preventDefault(),this.results_toggle()):(this.is_multiple&&this.search_field.val(""),a(document).click(this.click_test_action),this.results_show());return this.activate_field()}return this.pending_destroy_click=!1},b.prototype.mouse_enter=function(){return this.mouse_on_container=!0},b.prototype.mouse_leave=function(){return this.mouse_on_container=!1},b.prototype.input_focus=function(a){if(!this.active_field)return setTimeout(e(function(){return this.container_mousedown()},this),50)},b.prototype.input_blur=function(a){if(!this.mouse_on_container){this.active_field=!1;return setTimeout(e(function(){return this.blur_test()},this),100)}},b.prototype.blur_test=function(a){if(!this.active_field&&this.container.hasClass("chzn-container-active"))return this.close_field()},b.prototype.close_field=function(){a(document).unbind("click",this.click_test_action),this.is_multiple||(this.selected_item.attr("tabindex",this.search_field.attr("tabindex")),this.search_field.attr("tabindex",-1)),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();return this.search_field_scale()},b.prototype.activate_field=function(){!this.is_multiple&&!this.active_field&&(this.search_field.attr("tabindex",this.selected_item.attr("tabindex")),this.selected_item.attr("tabindex",-1)),this.container.addClass("chzn-container-active"),this.active_field=!0,this.search_field.val(this.search_field.val());return this.search_field.focus()},b.prototype.test_active_click=function(b){return a(b.target).parents("#"+this.container_id).length?this.active_field=!0:this.close_field()},b.prototype.results_build=function(){var a,b,c,e,f,g;c=new Date,this.parsing=!0,this.results_data=d.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.find("span").text(this.default_text),a="",g=this.results_data;for(e=0,f=g.length;e<f;e++)b=g[e],b.group?a+=this.result_add_group(b):b.empty||(a+=this.result_add_option(b),b.selected&&this.is_multiple?this.choice_build(b):b.selected&&!this.is_multiple&&this.selected_item.find("span").text(b.text));this.show_search_field_default(),this.search_field_scale(),this.search_results.html(a);return this.parsing=!1},b.prototype.result_add_group=function(b){if(!b.disabled){b.dom_id=this.container_id+"_g_"+b.array_index;return'<li id="'+b.dom_id+'" class="group-result">'+a("<div />").text(b.label).html()+"</li>"}return""},b.prototype.result_add_option=function(a){var b;if(!a.disabled){a.dom_id=this.container_id+"_o_"+a.array_index,b=a.selected&&this.is_multiple?[]:["active-result"],a.selected&&b.push("result-selected"),a.group_array_index!=null&&b.push("group-option");return'<li id="'+a.dom_id+'" class="'+b.join(" ")+'">'+a.html+"</li>"}return""},b.prototype.results_update_field=function(){this.result_clear_highlight(),this.result_single_selected=null;return this.results_build()},b.prototype.result_do_highlight=function(a){var b,c,d,e,f;if(a.length){this.result_clear_highlight(),this.result_highlight=a,this.result_highlight.addClass("highlighted"),d=parseInt(this.search_results.css("maxHeight"),10),f=this.search_results.scrollTop(),e=d+f,c=this.result_highlight.position().top+this.search_results.scrollTop(),b=c+this.result_highlight.outerHeight();if(b>=e)return this.search_results.scrollTop(b-d>0?b-d:0);if(c<f)return this.search_results.scrollTop(c)}},b.prototype.result_clear_highlight=function(){this.result_highlight&&this.result_highlight.removeClass("highlighted");return this.result_highlight=null},b.prototype.results_toggle=function(){return this.results_showing?this.results_hide():this.results_show()},b.prototype.results_show=function(){var a;this.is_multiple||(this.selected_item.addClass("chzn-single-with-drop"),this.result_single_selected&&this.result_do_highlight(this.result_single_selected)),a=this.is_multiple?this.container.height():this.container.height()-1,this.dropdown.css({top:a+"px",left:0}),this.results_showing=!0,this.search_field.focus(),this.search_field.val(this.search_field.val());return this.winnow_results()},b.prototype.results_hide=function(){this.is_multiple||this.selected_item.removeClass("chzn-single-with-drop"),this.result_clear_highlight(),this.dropdown.css({left:"-9000px"});return this.results_showing=!1},b.prototype.set_tab_index=function(a){var b;if(this.form_field_jq.attr("tabindex")){b=this.form_field_jq.attr("tabindex"),this.form_field_jq.attr("tabindex",-1);if(this.is_multiple)return this.search_field.attr("tabindex",b);this.selected_item.attr("tabindex",b);return this.search_field.attr("tabindex",-1)}},b.prototype.show_search_field_default=function(){if(this.is_multiple&&this.choices<1&&!this.active_field){this.search_field.val(this.default_text);return this.search_field.addClass("default")}this.search_field.val("");return this.search_field.removeClass("default")},b.prototype.search_results_mouseup=function(b){var c;c=a(b.target).hasClass("active-result")?a(b.target):a(b.target).parents(".active-result").first();if(c.length){this.result_highlight=c;return this.result_select(b)}},b.prototype.search_results_mouseover=function(b){var c;c=a(b.target).hasClass("active-result")?a(b.target):a(b.target).parents(".active-result").first();if(c)return this.result_do_highlight(c)},b.prototype.search_results_mouseout=function(b){if(a(b.target).hasClass("active-result"))return this.result_clear_highlight()},b.prototype.choices_click=function(b){b.preventDefault();if(this.active_field&&!a(b.target).hasClass("search-choice")&&!this.results_showing)return this.results_show()},b.prototype.choice_build=function(b){var c,d;c=this.container_id+"_c_"+b.array_index,this.choices+=1,this.search_container.before('<li class="search-choice" id="'+c+'"><span>'+b.html+'</span><a href="javascript:void(0)" class="search-choice-close" rel="'+b.array_index+'"></a></li>'),d=a("#"+c).find("a").first();return d.click(e(function(a){return this.choice_destroy_link_click(a)},this))},b.prototype.choice_destroy_link_click=function(b){b.preventDefault(),this.pending_destroy_click=!0;return this.choice_destroy(a(b.target))},b.prototype.choice_destroy=function(a){this.choices-=1,this.show_search_field_default(),this.is_multiple&&this.choices>0&&this.search_field.val().length<1&&this.results_hide(),this.result_deselect(a.attr("rel"));return a.parents("li").first().remove()},b.prototype.result_select=function(a){var b,c,d,e;if(this.result_highlight){b=this.result_highlight,c=b.attr("id"),this.result_clear_highlight(),b.addClass("result-selected"),this.is_multiple?this.result_deactivate(b):this.result_single_selected=b,e=c.substr(c.lastIndexOf("_")+1),d=this.results_data[e],d.selected=!0,this.form_field.options[d.options_index].selected=!0,this.is_multiple?this.choice_build(d):this.selected_item.find("span").first().text(d.text),(!a.metaKey||!this.is_multiple)&&this.results_hide(),this.search_field.val(""),this.form_field_jq.trigger("change");return this.search_field_scale()}},b.prototype.result_activate=function(a){return a.addClass("active-result").show()},b.prototype.result_deactivate=function(a){return a.removeClass("active-result").hide()},b.prototype.result_deselect=function(b){var c,d;d=this.results_data[b],d.selected=!1,this.form_field.options[d.options_index].selected=!1,c=a("#"+this.container_id+"_o_"+b),c.removeClass("result-selected").addClass("active-result").show(),this.result_clear_highlight(),this.winnow_results(),this.form_field_jq.trigger("change");return this.search_field_scale()},b.prototype.results_search=function(a){return this.results_showing?this.winnow_results():this.results_show()},b.prototype.winnow_results=function(){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r;j=new Date,this.no_results_clear(),h=0,i=this.search_field.val()===this.default_text?"":a("<div/>").text(a.trim(this.search_field.val())).html(),f=new RegExp("^"+i.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),"i"),m=new RegExp(i.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),"i"),r=this.results_data;for(n=0,p=r.length;n<p;n++){c=r[n];if(!c.disabled&&!c.empty)if(c.group)a("#"+c.dom_id).hide();else if(!this.is_multiple||!c.selected){b=!1,g=c.dom_id;if(f.test(c.html))b=!0,h+=1;else if(c.html.indexOf(" ")>=0||c.html.indexOf("[")===0){e=c.html.replace(/\[|\]/g,"").split(" ");if(e.length)for(o=0,q=e.length;o<q;o++)d=e[o],f.test(d)&&(b=!0,h+=1)}b?(i.length?(k=c.html.search(m),l=c.html.substr(0,k+i.length)+"</em>"+c.html.substr(k+i.length),l=l.substr(0,k)+"<em>"+l.substr(k)):l=c.html,a("#"+g).html!==l&&a("#"+g).html(l),this.result_activate(a("#"+g)),c.group_array_index!=null&&a("#"+this.results_data[c.group_array_index].dom_id).show()):(this.result_highlight&&g===this.result_highlight.attr("id")&&this.result_clear_highlight(),this.result_deactivate(a("#"+g)))}}return h<1&&i.length?this.no_results(i):this.winnow_results_set_highlight()},b.prototype.winnow_results_clear=function(){var b,c,d,e,f;this.search_field.val(""),c=this.search_results.find("li"),f=[];for(d=0,e=c.length;d<e;d++)b=c[d],b=a(b),f.push(b.hasClass("group-result")?b.show():!this.is_multiple||!b.hasClass("result-selected")?this.result_activate(b):void 0);return f},b.prototype.winnow_results_set_highlight=function(){var a,b;if(!this.result_highlight){b=this.is_multiple?[]:this.search_results.find(".result-selected"),a=b.length?b.first():this.search_results.find(".active-result").first();if(a!=null)return this.result_do_highlight(a)}},b.prototype.no_results=function(b){var c;c=a('<li class="no-results">'+this.results_none_found+' "<span></span>"</li>'),c.find("span").first().html(b);return this.search_results.append(c)},b.prototype.no_results_clear=function(){return this.search_results.find(".no-results").remove()},b.prototype.keydown_arrow=function(){var b,c;this.result_highlight?this.results_showing&&(c=this.result_highlight.nextAll("li.active-result").first(),c&&this.result_do_highlight(c)):(b=this.search_results.find("li.active-result").first(),b&&this.result_do_highlight(a(b)));if(!this.results_showing)return this.results_show()},b.prototype.keyup_arrow=function(){var a;if(!this.results_showing&&!this.is_multiple)return this.results_show();if(this.result_highlight){a=this.result_highlight.prevAll("li.active-result");if(a.length)return this.result_do_highlight(a.first());this.choices>0&&this.results_hide();return this.result_clear_highlight()}},b.prototype.keydown_backstroke=function(){if(this.pending_backstroke){this.choice_destroy(this.pending_backstroke.find("a").first());return this.clear_backstroke()}this.pending_backstroke=this.search_container.siblings("li.search-choice").last();return this.pending_backstroke.addClass("search-choice-focus")},b.prototype.clear_backstroke=function(){this.pending_backstroke&&this.pending_backstroke.removeClass("search-choice-focus");return this.pending_backstroke=null},b.prototype.keyup_checker=function(a){var b,c;b=(c=a.which)!=null?c:a.keyCode,this.search_field_scale();switch(b){case 8:if(this.is_multiple&&this.backstroke_length<1&&this.choices>0)return this.keydown_backstroke();if(!this.pending_backstroke){this.result_clear_highlight();return this.results_search()}break;case 13:a.preventDefault();if(this.results_showing)return this.result_select(a);break;case 27:if(this.results_showing)return this.results_hide();break;case 9:case 38:case 40:case 16:case 91:case 17:break;default:return this.results_search()}},b.prototype.keydown_checker=function(a){var b,c;b=(c=a.which)!=null?c:a.keyCode,this.search_field_scale(),b!==8&&this.pending_backstroke&&this.clear_backstroke();switch(b){case 8:this.backstroke_length=this.search_field.val().length;break;case 9:this.mouse_on_container=!1;break;case 13:a.preventDefault();break;case 38:a.preventDefault(),this.keyup_arrow();break;case 40:this.keydown_arrow()}},b.prototype.search_field_scale=function(){var b,c,d,e,f,g,h,i,j;if(this.is_multiple){d=0,h=0,f="position:absolute; left: -1000px; top: -1000px; display:none;",g=["font-size","font-style","font-weight","font-family","line-height","text-transform","letter-spacing"];for(i=0,j=g.length;i<j;i++)e=g[i],f+=e+":"+this.search_field.css(e)+";";c=a("<div />",{style:f}),c.text(this.search_field.val()),a("body").append(c),h=c.width()+25,c.remove(),h>this.f_width-10&&(h=this.f_width-10),this.search_field.css({width:h+"px"}),b=this.container.height();return this.dropdown.css({top:b+"px"})}},b.prototype.generate_field_id=function(){var a;a=this.generate_random_id(),this.form_field.id=a;return a},b.prototype.generate_random_id=function(){var b;b="sel"+this.generate_random_char()+this.generate_random_char()+this.generate_random_char();while(a("#"+b).length>0)b+=this.generate_random_char();return b},b.prototype.generate_random_char=function(){var a,b,c;a="0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ",c=Math.floor(Math.random()*a.length);return b=a.substring(c,c+1)};return b}(),c=function(a){var b;return b=a.outerWidth()-a.width()},d.get_side_border_padding=c}).call(this),function(){var a;a=function(){function a(){this.options_index=0,this.parsed=[]}a.prototype.add_node=function(a){return a.nodeName==="OPTGROUP"?this.add_group(a):this.add_option(a)},a.prototype.add_group=function(a){var b,c,d,e,f,g;b=this.parsed.length,this.parsed.push({array_index:b,group:!0,label:a.label,children:0,disabled:a.disabled}),f=a.childNodes,g=[];for(d=0,e=f.length;d<e;d++)c=f[d],g.push(this.add_option(c,b,a.disabled));return g},a.prototype.add_option=function(a,b,c){if(a.nodeName==="OPTION"){a.text!==""?(b!=null&&(this.parsed[b].children+=1),this.parsed.push({array_index:this.parsed.length,options_index:this.options_index,value:a.value,text:a.text,html:a.innerHTML,selected:a.selected,disabled:c===!0?c:a.disabled,group_array_index:b})):this.parsed.push({array_index:this.parsed.length,options_index:this.options_index,empty:!0});return this.options_index+=1}};return a}(),a.select_to_array=function(b){var c,d,e,f,g;d=new a,g=b.childNodes;for(e=0,f=g.length;e<f;e++)c=g[e],d.add_node(c);return d.parsed},this.SelectParser=a}.call(this) |
|---|
| | 10 | (function() { |
|---|
| | 11 | /* |
|---|
| | 12 | Chosen source: generate output using 'cake build' |
|---|
| | 13 | Copyright (c) 2011 by Harvest |
|---|
| | 14 | */ var $, Chosen, get_side_border_padding, root; |
|---|
| | 15 | var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; |
|---|
| | 16 | root = this; |
|---|
| | 17 | $ = jQuery; |
|---|
| | 18 | $.fn.extend({ |
|---|
| | 19 | chosen: function(options) { |
|---|
| | 20 | if ($.browser === "msie" && ($.browser.version === "6.0" || $.browser.version === "7.0")) { |
|---|
| | 21 | return this; |
|---|
| | 22 | } |
|---|
| | 23 | return $(this).each(function(input_field) { |
|---|
| | 24 | if (!($(this)).hasClass("chzn-done")) { |
|---|
| | 25 | return new Chosen(this, options); |
|---|
| | 26 | } |
|---|
| | 27 | }); |
|---|
| | 28 | } |
|---|
| | 29 | }); |
|---|
| | 30 | Chosen = (function() { |
|---|
| | 31 | function Chosen(elmn, options) { |
|---|
| | 32 | this.options = options || {}; |
|---|
| | 33 | this.set_default_values(); |
|---|
| | 34 | this.form_field = elmn; |
|---|
| | 35 | this.form_field_jq = $(this.form_field); |
|---|
| | 36 | this.is_multiple = this.form_field.multiple; |
|---|
| | 37 | this.is_rtl = this.form_field_jq.hasClass("chzn-rtl"); |
|---|
| | 38 | this.default_text_default = this.options.default_text || (this.form_field.multiple ? "Select Some Options" : "Select an Option"); |
|---|
| | 39 | this.real_default_text = this.default_text_default; |
|---|
| | 40 | this.set_up_html(); |
|---|
| | 41 | this.register_observers(); |
|---|
| | 42 | this.form_field_jq.addClass("chzn-done"); |
|---|
| | 43 | } |
|---|
| | 44 | Chosen.prototype.set_default_values = function() { |
|---|
| | 45 | this.click_test_action = __bind(function(evt) { |
|---|
| | 46 | return this.test_active_click(evt); |
|---|
| | 47 | }, this); |
|---|
| | 48 | this.active_field = false; |
|---|
| | 49 | this.mouse_on_container = false; |
|---|
| | 50 | this.results_showing = false; |
|---|
| | 51 | this.result_highlighted = null; |
|---|
| | 52 | this.result_single_selected = null; |
|---|
| | 53 | this.choices = 0; |
|---|
| | 54 | return this.results_none_found = this.options.no_results_text || "No results match"; |
|---|
| | 55 | }; |
|---|
| | 56 | Chosen.prototype.set_up_html = function() { |
|---|
| | 57 | var container_div, dd_top, dd_width, sf_width; |
|---|
| | 58 | this.container_id = this.form_field.id.length ? this.form_field.id.replace(/(:|\.)/g, '_') : this.generate_field_id(); |
|---|
| | 59 | this.container_id += "_chzn"; |
|---|
| | 60 | this.f_width = (this.form_field_jq.width() == 0)?300:this.form_field_jq.outerWidth(); |
|---|
| | 61 | this.default_text = this.form_field_jq.data('placeholder') ? this.form_field_jq.data('placeholder') : this.default_text_default; |
|---|
| | 62 | container_div = $("<div />", { |
|---|
| | 63 | id: this.container_id, |
|---|
| | 64 | "class": "chzn-container " + (this.is_rtl ? 'chzn-rtl' : ''), |
|---|
| | 65 | style: 'width: ' + this.f_width + 'px;' |
|---|
| | 66 | }); |
|---|
| | 67 | if (this.is_multiple) { |
|---|
| | 68 | container_div.html('<ul class="chzn-choices"><li class="search-field"><input type="text" value="' + this.default_text + '" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chzn-drop" style="left:-9000px;"><ul class="chzn-results"></ul></div>'); |
|---|
| | 69 | } else { |
|---|
| | 70 | container_div.html('<a href="javascript:void(0)" class="chzn-single"><span>' + this.default_text + '</span><div><b></b></div></a><div class="chzn-drop" style="left:-9000px;"><div class="chzn-search"><input type="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>'); |
|---|
| | 71 | } |
|---|
| | 72 | this.form_field_jq.hide().after(container_div); |
|---|
| | 73 | this.container = $('#' + this.container_id); |
|---|
| | 74 | this.container.addClass("chzn-container-" + (this.is_multiple ? "multi" : "single")); |
|---|
| | 75 | this.dropdown = this.container.find('div.chzn-drop').first(); |
|---|
| | 76 | dd_top = this.container.height(); |
|---|
| | 77 | dd_width = this.f_width - get_side_border_padding(this.dropdown); |
|---|
| | 78 | this.dropdown.css({ |
|---|
| | 79 | "width": dd_width + "px", |
|---|
| | 80 | "top": dd_top + "px" |
|---|
| | 81 | }); |
|---|
| | 82 | this.search_field = this.container.find('input').first(); |
|---|
| | 83 | this.search_results = this.container.find('ul.chzn-results').first(); |
|---|
| | 84 | this.search_field_scale(); |
|---|
| | 85 | this.search_no_results = this.container.find('li.no-results').first(); |
|---|
| | 86 | if (this.is_multiple) { |
|---|
| | 87 | this.search_choices = this.container.find('ul.chzn-choices').first(); |
|---|
| | 88 | this.search_container = this.container.find('li.search-field').first(); |
|---|
| | 89 | } else { |
|---|
| | 90 | this.search_container = this.container.find('div.chzn-search').first(); |
|---|
| | 91 | this.selected_item = this.container.find('.chzn-single').first(); |
|---|
| | 92 | sf_width = dd_width - get_side_border_padding(this.search_container) - get_side_border_padding(this.search_field); |
|---|
| | 93 | this.search_field.css({ |
|---|
| | 94 | "width": sf_width + "px" |
|---|
| | 95 | }); |
|---|
| | 96 | } |
|---|
| | 97 | this.results_build(); |
|---|
| | 98 | return this.set_tab_index(); |
|---|
| | 99 | }; |
|---|
| | 100 | Chosen.prototype.register_observers = function() { |
|---|
| | 101 | this.container.mousedown(__bind(function(evt) { |
|---|
| | 102 | return this.container_mousedown(evt); |
|---|
| | 103 | }, this)); |
|---|
| | 104 | this.container.mouseenter(__bind(function(evt) { |
|---|
| | 105 | return this.mouse_enter(evt); |
|---|
| | 106 | }, this)); |
|---|
| | 107 | this.container.mouseleave(__bind(function(evt) { |
|---|
| | 108 | return this.mouse_leave(evt); |
|---|
| | 109 | }, this)); |
|---|
| | 110 | this.search_results.mouseup(__bind(function(evt) { |
|---|
| | 111 | return this.search_results_mouseup(evt); |
|---|
| | 112 | }, this)); |
|---|
| | 113 | this.search_results.mouseover(__bind(function(evt) { |
|---|
| | 114 | return this.search_results_mouseover(evt); |
|---|
| | 115 | }, this)); |
|---|
| | 116 | this.search_results.mouseout(__bind(function(evt) { |
|---|
| | 117 | return this.search_results_mouseout(evt); |
|---|
| | 118 | }, this)); |
|---|
| | 119 | this.form_field_jq.bind("liszt:updated", __bind(function(evt) { |
|---|
| | 120 | return this.results_update_field(evt); |
|---|
| | 121 | }, this)); |
|---|
| | 122 | this.search_field.blur(__bind(function(evt) { |
|---|
| | 123 | return this.input_blur(evt); |
|---|
| | 124 | }, this)); |
|---|
| | 125 | this.search_field.keyup(__bind(function(evt) { |
|---|
| | 126 | return this.keyup_checker(evt); |
|---|
| | 127 | }, this)); |
|---|
| | 128 | this.search_field.keydown(__bind(function(evt) { |
|---|
| | 129 | return this.keydown_checker(evt); |
|---|
| | 130 | }, this)); |
|---|
| | 131 | if (this.is_multiple) { |
|---|
| | 132 | this.search_choices.click(__bind(function(evt) { |
|---|
| | 133 | return this.choices_click(evt); |
|---|
| | 134 | }, this)); |
|---|
| | 135 | return this.search_field.focus(__bind(function(evt) { |
|---|
| | 136 | return this.input_focus(evt); |
|---|
| | 137 | }, this)); |
|---|
| | 138 | } else { |
|---|
| | 139 | return this.selected_item.focus(__bind(function(evt) { |
|---|
| | 140 | return this.activate_field(evt); |
|---|
| | 141 | }, this)); |
|---|
| | 142 | } |
|---|
| | 143 | }; |
|---|
| | 144 | Chosen.prototype.container_mousedown = function(evt) { |
|---|
| | 145 | if (evt && evt.type === "mousedown") { |
|---|
| | 146 | evt.stopPropagation(); |
|---|
| | 147 | } |
|---|
| | 148 | if (!this.pending_destroy_click) { |
|---|
| | 149 | if (!this.active_field) { |
|---|
| | 150 | if (this.is_multiple) { |
|---|
| | 151 | this.search_field.val(""); |
|---|
| | 152 | } |
|---|
| | 153 | $(document).click(this.click_test_action); |
|---|
| | 154 | this.results_show(); |
|---|
| | 155 | } else if (!this.is_multiple && evt && ($(evt.target) === this.selected_item || $(evt.target).parents("a.chzn-single").length)) { |
|---|
| | 156 | evt.preventDefault(); |
|---|
| | 157 | this.results_toggle(); |
|---|
| | 158 | } |
|---|
| | 159 | return this.activate_field(); |
|---|
| | 160 | } else { |
|---|
| | 161 | return this.pending_destroy_click = false; |
|---|
| | 162 | } |
|---|
| | 163 | }; |
|---|
| | 164 | Chosen.prototype.mouse_enter = function() { |
|---|
| | 165 | return this.mouse_on_container = true; |
|---|
| | 166 | }; |
|---|
| | 167 | Chosen.prototype.mouse_leave = function() { |
|---|
| | 168 | return this.mouse_on_container = false; |
|---|
| | 169 | }; |
|---|
| | 170 | Chosen.prototype.input_focus = function(evt) { |
|---|
| | 171 | if (!this.active_field) { |
|---|
| | 172 | return setTimeout((__bind(function() { |
|---|
| | 173 | return this.container_mousedown(); |
|---|
| | 174 | }, this)), 50); |
|---|
| | 175 | } |
|---|
| | 176 | }; |
|---|
| | 177 | Chosen.prototype.input_blur = function(evt) { |
|---|
| | 178 | if (!this.mouse_on_container) { |
|---|
| | 179 | this.active_field = false; |
|---|
| | 180 | return setTimeout((__bind(function() { |
|---|
| | 181 | return this.blur_test(); |
|---|
| | 182 | }, this)), 100); |
|---|
| | 183 | } |
|---|
| | 184 | }; |
|---|
| | 185 | Chosen.prototype.blur_test = function(evt) { |
|---|
| | 186 | if (!this.active_field && this.container.hasClass("chzn-container-active")) { |
|---|
| | 187 | return this.close_field(); |
|---|
| | 188 | } |
|---|
| | 189 | }; |
|---|
| | 190 | Chosen.prototype.close_field = function() { |
|---|
| | 191 | $(document).unbind("click", this.click_test_action); |
|---|
| | 192 | if (!this.is_multiple) { |
|---|
| | 193 | this.selected_item.attr("tabindex", this.search_field.attr("tabindex")); |
|---|
| | 194 | this.search_field.attr("tabindex", -1); |
|---|
| | 195 | } |
|---|
| | 196 | this.active_field = false; |
|---|
| | 197 | this.results_hide(); |
|---|
| | 198 | this.container.removeClass("chzn-container-active"); |
|---|
| | 199 | this.winnow_results_clear(); |
|---|
| | 200 | this.clear_backstroke(); |
|---|
| | 201 | this.show_search_field_default(); |
|---|
| | 202 | return this.search_field_scale(); |
|---|
| | 203 | }; |
|---|
| | 204 | Chosen.prototype.activate_field = function() { |
|---|
| | 205 | if (!this.is_multiple && !this.active_field) { |
|---|
| | 206 | this.search_field.attr("tabindex", this.selected_item.attr("tabindex")); |
|---|
| | 207 | this.selected_item.attr("tabindex", -1); |
|---|
| | 208 | } |
|---|
| | 209 | this.container.addClass("chzn-container-active"); |
|---|
| | 210 | this.active_field = true; |
|---|
| | 211 | this.search_field.val(this.search_field.val()); |
|---|
| | 212 | return this.search_field.focus(); |
|---|
| | 213 | }; |
|---|
| | 214 | Chosen.prototype.test_active_click = function(evt) { |
|---|
| | 215 | if ($(evt.target).parents('#' + this.container_id).length) { |
|---|
| | 216 | return this.active_field = true; |
|---|
| | 217 | } else { |
|---|
| | 218 | return this.close_field(); |
|---|
| | 219 | } |
|---|
| | 220 | }; |
|---|
| | 221 | Chosen.prototype.results_build = function() { |
|---|
| | 222 | var content, data, startTime, _i, _len, _ref; |
|---|
| | 223 | startTime = new Date(); |
|---|
| | 224 | this.parsing = true; |
|---|
| | 225 | this.results_data = root.SelectParser.select_to_array(this.form_field); |
|---|
| | 226 | if (this.is_multiple && this.choices > 0) { |
|---|
| | 227 | this.search_choices.find("li.search-choice").remove(); |
|---|
| | 228 | this.choices = 0; |
|---|
| | 229 | } else if (!this.is_multiple) { |
|---|
| | 230 | this.selected_item.find("span").text(this.default_text); |
|---|
| | 231 | } |
|---|
| | 232 | content = ''; |
|---|
| | 233 | _ref = this.results_data; |
|---|
| | 234 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
|---|
| | 235 | data = _ref[_i]; |
|---|
| | 236 | if (data.group) { |
|---|
| | 237 | content += this.result_add_group(data); |
|---|
| | 238 | } else if (!data.empty) { |
|---|
| | 239 | content += this.result_add_option(data); |
|---|
| | 240 | if (data.selected && this.is_multiple) { |
|---|
| | 241 | this.choice_build(data); |
|---|
| | 242 | } else if (data.selected && !this.is_multiple) { |
|---|
| | 243 | this.selected_item.find("span").text(data.text); |
|---|
| | 244 | } |
|---|
| | 245 | } |
|---|
| | 246 | } |
|---|
| | 247 | this.show_search_field_default(); |
|---|
| | 248 | this.search_field_scale(); |
|---|
| | 249 | this.search_results.html(content); |
|---|
| | 250 | return this.parsing = false; |
|---|
| | 251 | }; |
|---|
| | 252 | Chosen.prototype.result_add_group = function(group) { |
|---|
| | 253 | if (!group.disabled) { |
|---|
| | 254 | group.dom_id = this.container_id + "_g_" + group.array_index; |
|---|
| | 255 | return '<li id="' + group.dom_id + '" class="group-result">' + $("<div />").text(group.label).html() + '</li>'; |
|---|
| | 256 | } else { |
|---|
| | 257 | return ""; |
|---|
| | 258 | } |
|---|
| | 259 | }; |
|---|
| | 260 | Chosen.prototype.result_add_option = function(option) { |
|---|
| | 261 | var classes; |
|---|
| | 262 | if (!option.disabled) { |
|---|
| | 263 | option.dom_id = this.container_id + "_o_" + option.array_index; |
|---|
| | 264 | classes = option.selected && this.is_multiple ? [] : ["active-result"]; |
|---|
| | 265 | if (option.selected) { |
|---|
| | 266 | classes.push("result-selected"); |
|---|
| | 267 | } |
|---|
| | 268 | if (option.group_array_index != null) { |
|---|
| | 269 | classes.push("group-option"); |
|---|
| | 270 | } |
|---|
| | 271 | return '<li id="' + option.dom_id + '" class="' + classes.join(' ') + '">' + option.html + '</li>'; |
|---|
| | 272 | } else { |
|---|
| | 273 | return ""; |
|---|
| | 274 | } |
|---|
| | 275 | }; |
|---|
| | 276 | Chosen.prototype.results_update_field = function() { |
|---|
| | 277 | this.result_clear_highlight(); |
|---|
| | 278 | this.result_single_selected = null; |
|---|
| | 279 | return this.results_build(); |
|---|
| | 280 | }; |
|---|
| | 281 | Chosen.prototype.result_do_highlight = function(el) { |
|---|
| | 282 | var high_bottom, high_top, maxHeight, visible_bottom, visible_top; |
|---|
| | 283 | if (el.length) { |
|---|
| | 284 | this.result_clear_highlight(); |
|---|
| | 285 | this.result_highlight = el; |
|---|
| | 286 | this.result_highlight.addClass("highlighted"); |
|---|
| | 287 | maxHeight = parseInt(this.search_results.css("maxHeight"), 10); |
|---|
| | 288 | visible_top = this.search_results.scrollTop(); |
|---|
| | 289 | visible_bottom = maxHeight + visible_top; |
|---|
| | 290 | high_top = this.result_highlight.position().top + this.search_results.scrollTop(); |
|---|
| | 291 | high_bottom = high_top + this.result_highlight.outerHeight(); |
|---|
| | 292 | if (high_bottom >= visible_bottom) { |
|---|
| | 293 | return this.search_results.scrollTop((high_bottom - maxHeight) > 0 ? high_bottom - maxHeight : 0); |
|---|
| | 294 | } else if (high_top < visible_top) { |
|---|
| | 295 | return this.search_results.scrollTop(high_top); |
|---|
| | 296 | } |
|---|
| | 297 | } |
|---|
| | 298 | }; |
|---|
| | 299 | Chosen.prototype.result_clear_highlight = function() { |
|---|
| | 300 | if (this.result_highlight) { |
|---|
| | 301 | this.result_highlight.removeClass("highlighted"); |
|---|
| | 302 | } |
|---|
| | 303 | return this.result_highlight = null; |
|---|
| | 304 | }; |
|---|
| | 305 | Chosen.prototype.results_toggle = function() { |
|---|
| | 306 | if (this.results_showing) { |
|---|
| | 307 | return this.results_hide(); |
|---|
| | 308 | } else { |
|---|
| | 309 | return this.results_show(); |
|---|
| | 310 | } |
|---|
| | 311 | }; |
|---|
| | 312 | Chosen.prototype.results_show = function() { |
|---|
| | 313 | var dd_top; |
|---|
| | 314 | if (!this.is_multiple) { |
|---|
| | 315 | this.selected_item.addClass("chzn-single-with-drop"); |
|---|
| | 316 | if (this.result_single_selected) { |
|---|
| | 317 | this.result_do_highlight(this.result_single_selected); |
|---|
| | 318 | } |
|---|
| | 319 | } |
|---|
| | 320 | dd_top = this.is_multiple ? this.container.height() : this.container.height() - 1; |
|---|
| | 321 | this.dropdown.css({ |
|---|
| | 322 | "top": dd_top + "px", |
|---|
| | 323 | "left": 0 |
|---|
| | 324 | }); |
|---|
| | 325 | this.results_showing = true; |
|---|
| | 326 | this.search_field.focus(); |
|---|
| | 327 | this.search_field.val(this.search_field.val()); |
|---|
| | 328 | return this.winnow_results(); |
|---|
| | 329 | }; |
|---|
| | 330 | Chosen.prototype.results_hide = function() { |
|---|
| | 331 | if (!this.is_multiple) { |
|---|
| | 332 | this.selected_item.removeClass("chzn-single-with-drop"); |
|---|
| | 333 | } |
|---|
| | 334 | this.result_clear_highlight(); |
|---|
| | 335 | this.dropdown.css({ |
|---|
| | 336 | "left": "-9000px" |
|---|
| | 337 | }); |
|---|
| | 338 | return this.results_showing = false; |
|---|
| | 339 | }; |
|---|
| | 340 | Chosen.prototype.set_tab_index = function(el) { |
|---|
| | 341 | var ti; |
|---|
| | 342 | if (this.form_field_jq.attr("tabindex")) { |
|---|
| | 343 | ti = this.form_field_jq.attr("tabindex"); |
|---|
| | 344 | this.form_field_jq.attr("tabindex", -1); |
|---|
| | 345 | if (this.is_multiple) { |
|---|
| | 346 | return this.search_field.attr("tabindex", ti); |
|---|
| | 347 | } else { |
|---|
| | 348 | this.selected_item.attr("tabindex", ti); |
|---|
| | 349 | return this.search_field.attr("tabindex", -1); |
|---|
| | 350 | } |
|---|
| | 351 | } |
|---|
| | 352 | }; |
|---|
| | 353 | Chosen.prototype.show_search_field_default = function() { |
|---|
| | 354 | if (this.is_multiple && this.choices < 1 && !this.active_field) { |
|---|
| | 355 | this.search_field.val(this.default_text); |
|---|
| | 356 | return this.search_field.addClass("default"); |
|---|
| | 357 | } else { |
|---|
| | 358 | this.search_field.val(""); |
|---|
| | 359 | return this.search_field.removeClass("default"); |
|---|
| | 360 | } |
|---|
| | 361 | }; |
|---|
| | 362 | Chosen.prototype.search_results_mouseup = function(evt) { |
|---|
| | 363 | var target; |
|---|
| | 364 | target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first(); |
|---|
| | 365 | if (target.length) { |
|---|
| | 366 | this.result_highlight = target; |
|---|
| | 367 | return this.result_select(evt); |
|---|
| | 368 | } |
|---|
| | 369 | }; |
|---|
| | 370 | Chosen.prototype.search_results_mouseover = function(evt) { |
|---|
| | 371 | var target; |
|---|
| | 372 | target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first(); |
|---|
| | 373 | if (target) { |
|---|
| | 374 | return this.result_do_highlight(target); |
|---|
| | 375 | } |
|---|
| | 376 | }; |
|---|
| | 377 | Chosen.prototype.search_results_mouseout = function(evt) { |
|---|
| | 378 | if ($(evt.target).hasClass("active-result" || $(evt.target).parents('.active-result').first())) { |
|---|
| | 379 | return this.result_clear_highlight(); |
|---|
| | 380 | } |
|---|
| | 381 | }; |
|---|
| | 382 | Chosen.prototype.choices_click = function(evt) { |
|---|
| | 383 | evt.preventDefault(); |
|---|
| | 384 | if (this.active_field && !($(evt.target).hasClass("search-choice" || $(evt.target).parents('.search-choice').first)) && !this.results_showing) { |
|---|
| | 385 | return this.results_show(); |
|---|
| | 386 | } |
|---|
| | 387 | }; |
|---|
| | 388 | Chosen.prototype.choice_build = function(item) { |
|---|
| | 389 | var choice_id, link; |
|---|
| | 390 | choice_id = this.container_id + "_c_" + item.array_index; |
|---|
| | 391 | this.choices += 1; |
|---|
| | 392 | this.search_container.before('<li class="search-choice" id="' + choice_id + '"><span>' + item.html + '</span><a href="javascript:void(0)" class="search-choice-close" rel="' + item.array_index + '"></a></li>'); |
|---|
| | 393 | link = $('#' + choice_id).find("a").first(); |
|---|
| | 394 | return link.click(__bind(function(evt) { |
|---|
| | 395 | return this.choice_destroy_link_click(evt); |
|---|
| | 396 | }, this)); |
|---|
| | 397 | }; |
|---|
| | 398 | Chosen.prototype.choice_destroy_link_click = function(evt) { |
|---|
| | 399 | evt.preventDefault(); |
|---|
| | 400 | this.pending_destroy_click = true; |
|---|
| | 401 | return this.choice_destroy($(evt.target)); |
|---|
| | 402 | }; |
|---|
| | 403 | Chosen.prototype.choice_destroy = function(link) { |
|---|
| | 404 | this.choices -= 1; |
|---|
| | 405 | this.show_search_field_default(); |
|---|
| | 406 | if (this.is_multiple && this.choices > 0 && this.search_field.val().length < 1) { |
|---|
| | 407 | this.results_hide(); |
|---|
| | 408 | } |
|---|
| | 409 | this.result_deselect(link.attr("rel")); |
|---|
| | 410 | return link.parents('li').first().remove(); |
|---|
| | 411 | }; |
|---|
| | 412 | Chosen.prototype.result_select = function(evt) { |
|---|
| | 413 | var high, high_id, item, position; |
|---|
| | 414 | if (this.result_highlight) { |
|---|
| | 415 | high = this.result_highlight; |
|---|
| | 416 | high_id = high.attr("id"); |
|---|
| | 417 | this.result_clear_highlight(); |
|---|
| | 418 | high.addClass("result-selected"); |
|---|
| | 419 | if (this.is_multiple) { |
|---|
| | 420 | this.result_deactivate(high); |
|---|
| | 421 | } else { |
|---|
| | 422 | this.result_single_selected = high; |
|---|
| | 423 | } |
|---|
| | 424 | position = high_id.substr(high_id.lastIndexOf("_") + 1); |
|---|
| | 425 | item = this.results_data[position]; |
|---|
| | 426 | item.selected = true; |
|---|
| | 427 | this.form_field.options[item.options_index].selected = true; |
|---|
| | 428 | if (this.is_multiple) { |
|---|
| | 429 | this.choice_build(item); |
|---|
| | 430 | } else { |
|---|
| | 431 | this.selected_item.find("span").first().text(item.text); |
|---|
| | 432 | } |
|---|
| | 433 | if (!(evt.metaKey && this.is_multiple)) { |
|---|
| | 434 | this.results_hide(); |
|---|
| | 435 | } |
|---|
| | 436 | this.search_field.val(""); |
|---|
| | 437 | this.form_field_jq.trigger("change"); |
|---|
| | 438 | return this.search_field_scale(); |
|---|
| | 439 | } |
|---|
| | 440 | }; |
|---|
| | 441 | Chosen.prototype.result_activate = function(el) { |
|---|
| | 442 | return el.addClass("active-result").show(); |
|---|
| | 443 | }; |
|---|
| | 444 | Chosen.prototype.result_deactivate = function(el) { |
|---|
| | 445 | return el.removeClass("active-result").hide(); |
|---|
| | 446 | }; |
|---|
| | 447 | Chosen.prototype.result_deselect = function(pos) { |
|---|
| | 448 | var result, result_data; |
|---|
| | 449 | result_data = this.results_data[pos]; |
|---|
| | 450 | result_data.selected = false; |
|---|
| | 451 | this.form_field.options[result_data.options_index].selected = false; |
|---|
| | 452 | result = $("#" + this.container_id + "_o_" + pos); |
|---|
| | 453 | result.removeClass("result-selected").addClass("active-result").show(); |
|---|
| | 454 | this.result_clear_highlight(); |
|---|
| | 455 | this.winnow_results(); |
|---|
| | 456 | this.form_field_jq.trigger("change"); |
|---|
| | 457 | return this.search_field_scale(); |
|---|
| | 458 | }; |
|---|
| | 459 | Chosen.prototype.results_search = function(evt) { |
|---|
| | 460 | if (this.results_showing) { |
|---|
| | 461 | return this.winnow_results(); |
|---|
| | 462 | } else { |
|---|
| | 463 | return this.results_show(); |
|---|
| | 464 | } |
|---|
| | 465 | }; |
|---|
| | 466 | Chosen.prototype.winnow_results = function() { |
|---|
| | 467 | var found, option, part, parts, regex, result_id, results, searchText, startTime, startpos, text, zregex, _i, _j, _len, _len2, _ref; |
|---|
| | 468 | startTime = new Date(); |
|---|
| | 469 | this.no_results_clear(); |
|---|
| | 470 | results = 0; |
|---|
| | 471 | searchText = this.search_field.val() === this.default_text ? "" : $('<div/>').text($.trim(this.search_field.val())).html(); |
|---|
| | 472 | regex = new RegExp('^' + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i'); |
|---|
| | 473 | zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i'); |
|---|
| | 474 | _ref = this.results_data; |
|---|
| | 475 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
|---|
| | 476 | option = _ref[_i]; |
|---|
| | 477 | if (!option.disabled && !option.empty) { |
|---|
| | 478 | if (option.group) { |
|---|
| | 479 | $('#' + option.dom_id).hide(); |
|---|
| | 480 | } else if (!(this.is_multiple && option.selected)) { |
|---|
| | 481 | found = false; |
|---|
| | 482 | result_id = option.dom_id; |
|---|
| | 483 | if (regex.test(option.html)) { |
|---|
| | 484 | found = true; |
|---|
| | 485 | results += 1; |
|---|
| | 486 | } else if (option.html.indexOf(" ") >= 0 || option.html.indexOf("[") === 0) { |
|---|
| | 487 | parts = option.html.replace(/\[|\]/g, "").split(" "); |
|---|
| | 488 | if (parts.length) { |
|---|
| | 489 | for (_j = 0, _len2 = parts.length; _j < _len2; _j++) { |
|---|
| | 490 | part = parts[_j]; |
|---|
| | 491 | if (regex.test(part)) { |
|---|
| | 492 | found = true; |
|---|
| | 493 | results += 1; |
|---|
| | 494 | } |
|---|
| | 495 | } |
|---|
| | 496 | } |
|---|
| | 497 | } |
|---|
| | 498 | if (found) { |
|---|
| | 499 | if (searchText.length) { |
|---|
| | 500 | startpos = option.html.search(zregex); |
|---|
| | 501 | text = option.html.substr(0, startpos + searchText.length) + '</em>' + option.html.substr(startpos + searchText.length); |
|---|
| | 502 | text = text.substr(0, startpos) + '<em>' + text.substr(startpos); |
|---|
| | 503 | } else { |
|---|
| | 504 | text = option.html; |
|---|
| | 505 | } |
|---|
| | 506 | if ($("#" + result_id).html !== text) { |
|---|
| | 507 | $("#" + result_id).html(text); |
|---|
| | 508 | } |
|---|
| | 509 | this.result_activate($("#" + result_id)); |
|---|
| | 510 | if (option.group_array_index != null) { |
|---|
| | 511 | $("#" + this.results_data[option.group_array_index].dom_id).show(); |
|---|
| | 512 | } |
|---|
| | 513 | } else { |
|---|
| | 514 | if (this.result_highlight && result_id === this.result_highlight.attr('id')) { |
|---|
| | 515 | this.result_clear_highlight(); |
|---|
| | 516 | } |
|---|
| | 517 | this.result_deactivate($("#" + result_id)); |
|---|
| | 518 | } |
|---|
| | 519 | } |
|---|
| | 520 | } |
|---|
| | 521 | } |
|---|
| | 522 | if (results < 1 && searchText.length) { |
|---|
| | 523 | return this.no_results(searchText); |
|---|
| | 524 | } else { |
|---|
| | 525 | return this.winnow_results_set_highlight(); |
|---|
| | 526 | } |
|---|
| | 527 | }; |
|---|
| | 528 | Chosen.prototype.winnow_results_clear = function() { |
|---|
| | 529 | var li, lis, _i, _len, _results; |
|---|
| | 530 | this.search_field.val(""); |
|---|
| | 531 | lis = this.search_results.find("li"); |
|---|
| | 532 | _results = []; |
|---|
| | 533 | for (_i = 0, _len = lis.length; _i < _len; _i++) { |
|---|
| | 534 | li = lis[_i]; |
|---|
| | 535 | li = $(li); |
|---|
| | 536 | _results.push(li.hasClass("group-result") ? li.show() : !this.is_multiple || !li.hasClass("result-selected") ? this.result_activate(li) : void 0); |
|---|
| | 537 | } |
|---|
| | 538 | return _results; |
|---|
| | 539 | }; |
|---|
| | 540 | Chosen.prototype.winnow_results_set_highlight = function() { |
|---|
| | 541 | var do_high, selected_results; |
|---|
| | 542 | if (!this.result_highlight) { |
|---|
| | 543 | selected_results = !this.is_multiple ? this.search_results.find(".result-selected") : []; |
|---|
| | 544 | do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first(); |
|---|
| | 545 | if (do_high != null) { |
|---|
| | 546 | return this.result_do_highlight(do_high); |
|---|
| | 547 | } |
|---|
| | 548 | } |
|---|
| | 549 | }; |
|---|
| | 550 | Chosen.prototype.no_results = function(terms) { |
|---|
| | 551 | var no_results_html; |
|---|
| | 552 | no_results_html = $('<li class="no-results">' + this.results_none_found + ' "<span></span>"</li>'); |
|---|
| | 553 | no_results_html.find("span").first().html(terms); |
|---|
| | 554 | return this.search_results.append(no_results_html); |
|---|
| | 555 | }; |
|---|
| | 556 | Chosen.prototype.no_results_clear = function() { |
|---|
| | 557 | return this.search_results.find(".no-results").remove(); |
|---|
| | 558 | }; |
|---|
| | 559 | Chosen.prototype.keydown_arrow = function() { |
|---|
| | 560 | var first_active, next_sib; |
|---|
| | 561 | if (!this.result_highlight) { |
|---|
| | 562 | first_active = this.search_results.find("li.active-result").first(); |
|---|
| | 563 | if (first_active) { |
|---|
| | 564 | this.result_do_highlight($(first_active)); |
|---|
| | 565 | } |
|---|
| | 566 | } else if (this.results_showing) { |
|---|
| | 567 | next_sib = this.result_highlight.nextAll("li.active-result").first(); |
|---|
| | 568 | if (next_sib) { |
|---|
| | 569 | this.result_do_highlight(next_sib); |
|---|
| | 570 | } |
|---|
| | 571 | } |
|---|
| | 572 | if (!this.results_showing) { |
|---|
| | 573 | return this.results_show(); |
|---|
| | 574 | } |
|---|
| | 575 | }; |
|---|
| | 576 | Chosen.prototype.keyup_arrow = function() { |
|---|
| | 577 | var prev_sibs; |
|---|
| | 578 | if (!this.results_showing && !this.is_multiple) { |
|---|
| | 579 | return this.results_show(); |
|---|
| | 580 | } else if (this.result_highlight) { |
|---|
| | 581 | prev_sibs = this.result_highlight.prevAll("li.active-result"); |
|---|
| | 582 | if (prev_sibs.length) { |
|---|
| | 583 | return this.result_do_highlight(prev_sibs.first()); |
|---|
| | 584 | } else { |
|---|
| | 585 | if (this.choices > 0) { |
|---|
| | 586 | this.results_hide(); |
|---|
| | 587 | } |
|---|
| | 588 | return this.result_clear_highlight(); |
|---|
| | 589 | } |
|---|
| | 590 | } |
|---|
| | 591 | }; |
|---|
| | 592 | Chosen.prototype.keydown_backstroke = function() { |
|---|
| | 593 | if (this.pending_backstroke) { |
|---|
| | 594 | this.choice_destroy(this.pending_backstroke.find("a").first()); |
|---|
| | 595 | return this.clear_backstroke(); |
|---|
| | 596 | } else { |
|---|
| | 597 | this.pending_backstroke = this.search_container.siblings("li.search-choice").last(); |
|---|
| | 598 | return this.pending_backstroke.addClass("search-choice-focus"); |
|---|
| | 599 | } |
|---|
| | 600 | }; |
|---|
| | 601 | Chosen.prototype.clear_backstroke = function() { |
|---|
| | 602 | if (this.pending_backstroke) { |
|---|
| | 603 | this.pending_backstroke.removeClass("search-choice-focus"); |
|---|
| | 604 | } |
|---|
| | 605 | return this.pending_backstroke = null; |
|---|
| | 606 | }; |
|---|
| | 607 | Chosen.prototype.keyup_checker = function(evt) { |
|---|
| | 608 | var stroke, _ref; |
|---|
| | 609 | stroke = (_ref = evt.which) != null ? _ref : evt.keyCode; |
|---|
| | 610 | this.search_field_scale(); |
|---|
| | 611 | switch (stroke) { |
|---|
| | 612 | case 8: |
|---|
| | 613 | if (this.is_multiple && this.backstroke_length < 1 && this.choices > 0) { |
|---|
| | 614 | return this.keydown_backstroke(); |
|---|
| | 615 | } else if (!this.pending_backstroke) { |
|---|
| | 616 | this.result_clear_highlight(); |
|---|
| | 617 | return this.results_search(); |
|---|
| | 618 | } |
|---|
| | 619 | break; |
|---|
| | 620 | case 13: |
|---|
| | 621 | evt.preventDefault(); |
|---|
| | 622 | if (this.results_showing) { |
|---|
| | 623 | return this.result_select(evt); |
|---|
| | 624 | } |
|---|
| | 625 | break; |
|---|
| | 626 | case 27: |
|---|
| | 627 | if (this.results_showing) { |
|---|
| | 628 | return this.results_hide(); |
|---|
| | 629 | } |
|---|
| | 630 | break; |
|---|
| | 631 | case 9: |
|---|
| | 632 | case 38: |
|---|
| | 633 | case 40: |
|---|
| | 634 | case 16: |
|---|
| | 635 | case 91: |
|---|
| | 636 | case 17: |
|---|
| | 637 | break; |
|---|
| | 638 | default: |
|---|
| | 639 | return this.results_search(); |
|---|
| | 640 | } |
|---|
| | 641 | }; |
|---|
| | 642 | Chosen.prototype.keydown_checker = function(evt) { |
|---|
| | 643 | var stroke, _ref; |
|---|
| | 644 | stroke = (_ref = evt.which) != null ? _ref : evt.keyCode; |
|---|
| | 645 | this.search_field_scale(); |
|---|
| | 646 | if (stroke !== 8 && this.pending_backstroke) { |
|---|
| | 647 | this.clear_backstroke(); |
|---|
| | 648 | } |
|---|
| | 649 | switch (stroke) { |
|---|
| | 650 | case 8: |
|---|
| | 651 | this.backstroke_length = this.search_field.val().length; |
|---|
| | 652 | break; |
|---|
| | 653 | case 9: |
|---|
| | 654 | this.mouse_on_container = false; |
|---|
| | 655 | break; |
|---|
| | 656 | case 13: |
|---|
| | 657 | evt.preventDefault(); |
|---|
| | 658 | break; |
|---|
| | 659 | case 38: |
|---|
| | 660 | evt.preventDefault(); |
|---|
| | 661 | this.keyup_arrow(); |
|---|
| | 662 | break; |
|---|
| | 663 | case 40: |
|---|
| | 664 | this.keydown_arrow(); |
|---|
| | 665 | break; |
|---|
| | 666 | } |
|---|
| | 667 | }; |
|---|
| | 668 | Chosen.prototype.search_field_scale = function() { |
|---|
| | 669 | var dd_top, div, h, style, style_block, styles, w, _i, _len; |
|---|
| | 670 | if (this.is_multiple) { |
|---|
| | 671 | h = 0; |
|---|
| | 672 | w = 0; |
|---|
| | 673 | style_block = "position:absolute; left: -1000px; top: -1000px; display:none;"; |
|---|
| | 674 | styles = ['font-size', 'font-style', 'font-weight', 'font-family', 'line-height', 'text-transform', 'letter-spacing']; |
|---|
| | 675 | for (_i = 0, _len = styles.length; _i < _len; _i++) { |
|---|
| | 676 | style = styles[_i]; |
|---|
| | 677 | style_block += style + ":" + this.search_field.css(style) + ";"; |
|---|
| | 678 | } |
|---|
| | 679 | div = $('<div />', { |
|---|
| | 680 | 'style': style_block |
|---|
| | 681 | }); |
|---|
| | 682 | div.text(this.search_field.val()); |
|---|
| | 683 | $('body').append(div); |
|---|
| | 684 | w = div.width() + 25; |
|---|
| | 685 | div.remove(); |
|---|
| | 686 | if (w > this.f_width - 10) { |
|---|
| | 687 | w = this.f_width - 10; |
|---|
| | 688 | } |
|---|
| | 689 | this.search_field.css({ |
|---|
| | 690 | 'width': w + 'px' |
|---|
| | 691 | }); |
|---|
| | 692 | dd_top = this.container.height(); |
|---|
| | 693 | return this.dropdown.css({ |
|---|
| | 694 | "top": dd_top + "px" |
|---|
| | 695 | }); |
|---|
| | 696 | } |
|---|
| | 697 | }; |
|---|
| | 698 | Chosen.prototype.generate_field_id = function() { |
|---|
| | 699 | var new_id; |
|---|
| | 700 | new_id = this.generate_random_id(); |
|---|
| | 701 | this.form_field.id = new_id; |
|---|
| | 702 | return new_id; |
|---|
| | 703 | }; |
|---|
| | 704 | Chosen.prototype.generate_random_id = function() { |
|---|
| | 705 | var string; |
|---|
| | 706 | string = "sel" + this.generate_random_char() + this.generate_random_char() + this.generate_random_char(); |
|---|
| | 707 | while ($("#" + string).length > 0) { |
|---|
| | 708 | string += this.generate_random_char(); |
|---|
| | 709 | } |
|---|
| | 710 | return string; |
|---|
| | 711 | }; |
|---|
| | 712 | Chosen.prototype.generate_random_char = function() { |
|---|
| | 713 | var chars, newchar, rand; |
|---|
| | 714 | chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ"; |
|---|
| | 715 | rand = Math.floor(Math.random() * chars.length); |
|---|
| | 716 | return newchar = chars.substring(rand, rand + 1); |
|---|
| | 717 | }; |
|---|
| | 718 | return Chosen; |
|---|
| | 719 | })(); |
|---|
| | 720 | get_side_border_padding = function(elmt) { |
|---|
| | 721 | var side_border_padding; |
|---|
| | 722 | return side_border_padding = elmt.outerWidth() - elmt.width(); |
|---|
| | 723 | }; |
|---|
| | 724 | root.get_side_border_padding = get_side_border_padding; |
|---|
| | 725 | }).call(this); |
|---|
| | 726 | (function() { |
|---|
| | 727 | var SelectParser; |
|---|
| | 728 | SelectParser = (function() { |
|---|
| | 729 | function SelectParser() { |
|---|
| | 730 | this.options_index = 0; |
|---|
| | 731 | this.parsed = []; |
|---|
| | 732 | } |
|---|
| | 733 | SelectParser.prototype.add_node = function(child) { |
|---|
| | 734 | if (child.nodeName === "OPTGROUP") { |
|---|
| | 735 | return this.add_group(child); |
|---|
| | 736 | } else { |
|---|
| | 737 | return this.add_option(child); |
|---|
| | 738 | } |
|---|
| | 739 | }; |
|---|
| | 740 | SelectParser.prototype.add_group = function(group) { |
|---|
| | 741 | var group_position, option, _i, _len, _ref, _results; |
|---|
| | 742 | group_position = this.parsed.length; |
|---|
| | 743 | this.parsed.push({ |
|---|
| | 744 | array_index: group_position, |
|---|
| | 745 | group: true, |
|---|
| | 746 | label: group.label, |
|---|
| | 747 | children: 0, |
|---|
| | 748 | disabled: group.disabled |
|---|
| | 749 | }); |
|---|
| | 750 | _ref = group.childNodes; |
|---|
| | 751 | _results = []; |
|---|
| | 752 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
|---|
| | 753 | option = _ref[_i]; |
|---|
| | 754 | _results.push(this.add_option(option, group_position, group.disabled)); |
|---|
| | 755 | } |
|---|
| | 756 | return _results; |
|---|
| | 757 | }; |
|---|
| | 758 | SelectParser.prototype.add_option = function(option, group_position, group_disabled) { |
|---|
| | 759 | if (option.nodeName === "OPTION") { |
|---|
| | 760 | if (option.text !== "") { |
|---|
| | 761 | if (group_position != null) { |
|---|
| | 762 | this.parsed[group_position].children += 1; |
|---|
| | 763 | } |
|---|
| | 764 | this.parsed.push({ |
|---|
| | 765 | array_index: this.parsed.length, |
|---|
| | 766 | options_index: this.options_index, |
|---|
| | 767 | value: option.value, |
|---|
| | 768 | text: option.text, |
|---|
| | 769 | html: option.innerHTML, |
|---|
| | 770 | selected: option.selected, |
|---|
| | 771 | disabled: group_disabled === true ? group_disabled : option.disabled, |
|---|
| | 772 | group_array_index: group_position |
|---|
| | 773 | }); |
|---|
| | 774 | } else { |
|---|
| | 775 | this.parsed.push({ |
|---|
| | 776 | array_index: this.parsed.length, |
|---|
| | 777 | options_index: this.options_index, |
|---|
| | 778 | empty: true |
|---|
| | 779 | }); |
|---|
| | 780 | } |
|---|
| | 781 | return this.options_index += 1; |
|---|
| | 782 | } |
|---|
| | 783 | }; |
|---|
| | 784 | return SelectParser; |
|---|
| | 785 | })(); |
|---|
| | 786 | SelectParser.select_to_array = function(select) { |
|---|
| | 787 | var child, parser, _i, _len, _ref; |
|---|
| | 788 | parser = new SelectParser(); |
|---|
| | 789 | _ref = select.childNodes; |
|---|
| | 790 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
|---|
| | 791 | child = _ref[_i]; |
|---|
| | 792 | parser.add_node(child); |
|---|
| | 793 | } |
|---|
| | 794 | return parser.parsed; |
|---|
| | 795 | }; |
|---|
| | 796 | this.SelectParser = SelectParser; |
|---|
| | 797 | }).call(this); |
|---|