mirror of
https://github.com/Hopiu/django-select2.git
synced 2026-04-02 13:20:24 +00:00
1 line
No EOL
40 KiB
JavaScript
1 line
No EOL
40 KiB
JavaScript
(function(a){if(typeof a.fn.each2=="undefined"){a.fn.extend({each2:function(f){var d=a([0]),e=-1,b=this.length;while(++e<b&&(d.context=d[0]=this[e])&&f.call(d[0],e,d)!==false){}return this}})}})(jQuery);(function(j,l){if(window.Select2!==l){return}var c,e,w,G,u,a,C,D;c={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,isArrow:function(H){H=H.which?H.which:H;switch(H){case c.LEFT:case c.RIGHT:case c.UP:case c.DOWN:return true}return false},isControl:function(I){var H=I.which;switch(H){case c.SHIFT:case c.CTRL:case c.ALT:return true}if(I.metaKey){return true}return false},isFunctionKey:function(H){H=H.which?H.which:H;return H>=112&&H<=123}};D=j(document);u=(function(){var H=1;return function(){return H++}}());function b(J,K){var I=0,H=K.length;for(;I<H;I=I+1){if(q(J,K[I])){return I}}return -1}function q(I,H){if(I===H){return true}if(I===l||H===l){return false}if(I===null||H===null){return false}if(I.constructor===String){return I===H+""}if(H.constructor===String){return H===I+""}return false}function m(I,K){var L,J,H;if(I===null||I.length<1){return[]}L=I.split(K);for(J=0,H=L.length;J<H;J=J+1){L[J]=j.trim(L[J])}return L}function n(H){return H.outerWidth(false)-H.width()}function B(I){var H="keyup-change-value";I.bind("keydown",function(){if(j.data(I,H)===l){j.data(I,H,I.val())}});I.bind("keyup",function(){var J=j.data(I,H);if(J!==l&&I.val()!==J){j.removeData(I,H);I.trigger("keyup-change")}})}D.bind("mousemove",function(H){C={x:H.pageX,y:H.pageY}});function v(H){H.bind("mousemove",function(J){var I=C;if(I===l||I.x!==J.pageX||I.y!==J.pageY){j(J.target).trigger("mousemove-filtered",J)}})}function g(K,I,H){H=H||l;var J;return function(){var L=arguments;window.clearTimeout(J);J=window.setTimeout(function(){I.apply(H,L)},K)}}function E(J){var H=false,I;return function(){if(H===false){I=J();H=true}return I}}function f(H,J){var I=g(H,function(K){J.trigger("scroll-debounced",K)});J.bind("scroll",function(K){if(b(K.target,J.get())>=0){I(K)}})}function r(H){if(H[0]===document.activeElement){return}window.setTimeout(function(){var J=H[0],K=H.val().length,I;H.focus();if(J.setSelectionRange){J.setSelectionRange(K,K)}else{if(J.createTextRange){I=J.createTextRange();I.collapse(true);I.moveEnd("character",K);I.moveStart("character",K);I.select()}}},0)}function d(H){H.preventDefault();H.stopPropagation()}function F(H){H.preventDefault();H.stopImmediatePropagation()}function z(I){if(!a){var H=I[0].currentStyle||window.getComputedStyle(I[0],null);a=j(document.createElement("div")).css({position:"absolute",left:"-10000px",top:"-10000px",display:"none",fontSize:H.fontSize,fontFamily:H.fontFamily,fontStyle:H.fontStyle,fontWeight:H.fontWeight,letterSpacing:H.letterSpacing,textTransform:H.textTransform,whiteSpace:"nowrap"});a.attr("class","select2-sizer");j("body").append(a)}a.text(I.val());return a.width()}function y(I,M,H){var K,L=[],J;K=I.attr("class");if(typeof K==="string"){j(K.split(" ")).each2(function(){if(this.indexOf("select2-")===0){L.push(this)}})}K=M.attr("class");if(typeof K==="string"){j(K.split(" ")).each2(function(){if(this.indexOf("select2-")!==0){J=H(this);if(typeof J==="string"&&J.length>0){L.push(this)}}})}I.attr("class",L.join(" "))}function i(M,L,J,H){var K=M.toUpperCase().indexOf(L.toUpperCase()),I=L.length;if(K<0){J.push(H(M));return}J.push(H(M.substring(0,K)));J.push("<span class='select2-match'>");J.push(H(M.substring(K,K+I)));J.push("</span>");J.push(H(M.substring(K+I,M.length)))}function p(J){var M,I=0,K=null,N=J.quietMillis||100,L=J.url,H=this;return function(O){window.clearTimeout(M);M=window.setTimeout(function(){I+=1;var Q=I,S=J.data,P=L,U=J.transport||j.ajax,R=J.type||"GET",T={};S=S?S.call(H,O.term,O.page,O.context):null;P=(typeof P==="function")?P.call(H,O.term,O.page,O.context):P;if(null!==K){K.abort()}if(J.params){if(j.isFunction(J.params)){j.extend(T,J.params.call(H))}else{j.extend(T,J.params)}}j.extend(T,{url:P,dataType:J.dataType,data:S,type:R,cache:false,success:function(W){if(Q<I){return}var V=J.results(W,O.page);O.callback(V)}});K=U.call(H,T)},N)}}function s(I){var L=I,K,J,M=function(N){return""+N.text};if(j.isArray(L)){J=L;L={results:J}}if(j.isFunction(L)===false){J=L;L=function(){return J}}var H=L();if(H.text){M=H.text;if(!j.isFunction(M)){K=L.text;M=function(N){return N[K]}}}return function(P){var O=P.term,N={results:[]},Q;if(O===""){P.callback(L());return}Q=function(S,U){var T,R;S=S[0];if(S.children){T={};for(R in S){if(S.hasOwnProperty(R)){T[R]=S[R]}}T.children=[];j(S.children).each2(function(V,W){Q(W,T.children)});if(T.children.length||P.matcher(O,M(T),S)){U.push(T)}}else{if(P.matcher(O,M(S),S)){U.push(S)}}};j(L().results).each2(function(S,R){Q(R,N.results)});P.callback(N)}}function o(I){var H=j.isFunction(I);return function(L){var K=L.term,J={results:[]};j(H?I():I).each(function(){var M=this.text!==l,N=M?this.text:this;if(K===""||L.matcher(K,N)){J.results.push(M?this:{id:this,text:this})}});L.callback(J)}}function k(H,I){if(j.isFunction(H)){return true}if(!H){return false}throw new Error("formatterName must be a function or a falsy value")}function t(H){return j.isFunction(H)?H():H}function h(H){var I=0;j.each(H,function(J,K){if(K.children){I+=h(K.children)}else{I++}});return I}function A(P,Q,N,H){var I=P,R=false,K,O,L,J,M;if(!H.createSearchChoice||!H.tokenSeparators||H.tokenSeparators.length<1){return l}while(true){O=-1;for(L=0,J=H.tokenSeparators.length;L<J;L++){M=H.tokenSeparators[L];O=P.indexOf(M);if(O>=0){break}}if(O<0){break}K=P.substring(0,O);P=P.substring(O+M.length);if(K.length>0){K=H.createSearchChoice(K,Q);if(K!==l&&K!==null&&H.id(K)!==l&&H.id(K)!==null){R=false;for(L=0,J=Q.length;L<J;L++){if(q(H.id(K),H.id(Q[L]))){R=true;break}}if(!R){N(K)}}}}if(I!==P){return P}}function x(H,I){var J=function(){};J.prototype=new H;J.prototype.constructor=J;J.prototype.parent=H.prototype;J.prototype=j.extend(J.prototype,I);return J}e=x(Object,{bind:function(I){var H=this;return function(){I.apply(H,arguments)}},init:function(K){var J,I,L=".select2-results",H;this.opts=K=this.prepareOpts(K);this.id=K.id;if(K.element.data("select2")!==l&&K.element.data("select2")!==null){this.destroy()}this.enabled=true;this.container=this.createContainer();this.containerId="s2id_"+(K.element.attr("id")||"autogen"+u());this.containerSelector="#"+this.containerId.replace(/([;&,\.\+\*\~':"\!\^#$%@\[\]\(\)=>\|])/g,"\\$1");this.container.attr("id",this.containerId);this.body=E(function(){return K.element.closest("body")});y(this.container,this.opts.element,this.opts.adaptContainerCssClass);this.container.css(t(K.containerCss));this.container.addClass(t(K.containerCssClass));this.elementTabIndex=this.opts.element.attr("tabIndex");this.opts.element.data("select2",this).addClass("select2-offscreen").bind("focus.select2",function(){j(this).select2("focus")}).attr("tabIndex","-1").before(this.container);this.container.data("select2",this);this.dropdown=this.container.find(".select2-drop");this.dropdown.addClass(t(K.dropdownCssClass));this.dropdown.data("select2",this);this.results=J=this.container.find(L);this.search=I=this.container.find("input.select2-input");I.attr("tabIndex",this.elementTabIndex);this.resultsPage=0;this.context=null;this.initContainer();v(this.results);this.dropdown.delegate(L,"mousemove-filtered touchstart touchmove touchend",this.bind(this.highlightUnderEvent));f(80,this.results);this.dropdown.delegate(L,"scroll-debounced",this.bind(this.loadMoreIfNeeded));if(j.fn.mousewheel){J.mousewheel(function(Q,R,O,N){var P=J.scrollTop(),M;if(N>0&&P-N<=0){J.scrollTop(0);d(Q)}else{if(N<0&&J.get(0).scrollHeight-J.scrollTop()+N<=J.height()){J.scrollTop(J.get(0).scrollHeight-J.height());d(Q)}}})}B(I);I.bind("keyup-change input paste",this.bind(this.updateResults));I.bind("focus",function(){I.addClass("select2-focused")});I.bind("blur",function(){I.removeClass("select2-focused")});this.dropdown.delegate(L,"mouseup",this.bind(function(M){if(j(M.target).closest(".select2-result-selectable").length>0){this.highlightUnderEvent(M);this.selectHighlighted(M)}}));this.dropdown.bind("click mouseup mousedown",function(M){M.stopPropagation()});if(j.isFunction(this.opts.initSelection)){this.initSelection();this.monitorSource()}if(K.element.is(":disabled")||K.element.is("[readonly='readonly']")){this.disable()}},destroy:function(){var H=this.opts.element.data("select2");if(this.propertyObserver){delete this.propertyObserver;this.propertyObserver=null}if(H!==l){H.container.remove();H.dropdown.remove();H.opts.element.removeClass("select2-offscreen").removeData("select2").unbind(".select2").attr({tabIndex:this.elementTabIndex}).show()}},prepareOpts:function(L){var J,I,H,K;J=L.element;if(J.get(0).tagName.toLowerCase()==="select"){this.select=I=L.element}if(I){j.each(["id","multiple","ajax","query","createSearchChoice","initSelection","data","tags"],function(){if(this in L){throw new Error("Option '"+this+"' is not allowed for Select2 when attached to a <select> element.")}})}L=j.extend({},{populateResults:function(M,Q,S){var R,P,U,O,N=this.opts.id,T=this;R=function(ab,V,aa){var ac,X,ah,ae,Y,ag,W,af,ad,Z;ab=L.sortResults(ab,V,S);for(ac=0,X=ab.length;ac<X;ac=ac+1){ah=ab[ac];Y=(ah.disabled===true);ae=(!Y)&&(N(ah)!==l);ag=ah.children&&ah.children.length>0;W=j("<li></li>");W.addClass("select2-results-dept-"+aa);W.addClass("select2-result");W.addClass(ae?"select2-result-selectable":"select2-result-unselectable");if(Y){W.addClass("select2-disabled")}if(ag){W.addClass("select2-result-with-children")}W.addClass(T.opts.formatResultCssClass(ah));af=j(document.createElement("div"));af.addClass("select2-result-label");Z=L.formatResult(ah,af,S,T.opts.escapeMarkup);if(Z!==l){af.html(Z)}W.append(af);if(ag){ad=j("<ul></ul>");ad.addClass("select2-result-sub");R(ah.children,ad,aa+1);W.append(ad)}W.data("select2-data",ah);V.append(W)}};R(Q,M,0)}},j.fn.select2.defaults,L);if(typeof(L.id)!=="function"){H=L.id;L.id=function(M){return M[H]}}if(j.isArray(L.element.data("select2Tags"))){if("tags" in L){throw"tags specified as both an attribute 'data-select2-tags' and in options of Select2 "+L.element.attr("id")}L.tags=L.element.attr("data-select2-tags")}if(I){L.query=this.bind(function(P){var O={results:[],more:false},N=P.term,M,R,Q;Q=function(S,U){var T;if(S.is("option")){if(P.matcher(N,S.text(),S)){U.push({id:S.attr("value"),text:S.text(),element:S.get(),css:S.attr("class"),disabled:q(S.attr("disabled"),"disabled")})}}else{if(S.is("optgroup")){T={text:S.attr("label"),children:[],element:S.get(),css:S.attr("class")};S.children().each2(function(V,W){Q(W,T.children)});if(T.children.length>0){U.push(T)}}}};M=J.children();if(this.getPlaceholder()!==l&&M.length>0){R=M[0];if(j(R).text()===""){M=M.not(R)}}M.each2(function(S,T){Q(T,O.results)});P.callback(O)});L.id=function(M){return M.id};L.formatResultCssClass=function(M){return M.css}}else{if(!("query" in L)){if("ajax" in L){K=L.element.data("ajax-url");if(K&&K.length>0){L.ajax.url=K}L.query=p.call(L.element,L.ajax)}else{if("data" in L){L.query=s(L.data)}else{if("tags" in L){L.query=o(L.tags);if(L.createSearchChoice===l){L.createSearchChoice=function(M){return{id:M,text:M}}}if(L.initSelection===l){L.initSelection=function(M,O){var N=[];j(m(M.val(),L.separator)).each(function(){var R=this,Q=this,P=L.tags;if(j.isFunction(P)){P=P()}j(P).each(function(){if(q(this.id,R)){Q=this.text;return false}});N.push({id:R,text:Q})});O(N)}}}}}}}if(typeof(L.query)!=="function"){throw"query function not defined for Select2 "+L.element.attr("id")}return L},monitorSource:function(){var H=this.opts.element,I;H.bind("change.select2",this.bind(function(J){if(this.opts.element.data("select2-change-triggered")!==true){this.initSelection()}}));I=this.bind(function(){var L,K,J=this;L=this.opts.element.attr("disabled")!=="disabled";K=this.opts.element.attr("readonly")==="readonly";L=L&&!K;if(this.enabled!==L){if(L){this.enable()}else{this.disable()}}y(this.container,this.opts.element,this.opts.adaptContainerCssClass);this.container.addClass(t(this.opts.containerCssClass));y(this.dropdown,this.opts.element,this.opts.adaptDropdownCssClass);this.dropdown.addClass(t(this.opts.dropdownCssClass))});H.bind("propertychange.select2 DOMAttrModified.select2",I);if(typeof WebKitMutationObserver!=="undefined"){if(this.propertyObserver){delete this.propertyObserver;this.propertyObserver=null}this.propertyObserver=new WebKitMutationObserver(function(J){J.forEach(I)});this.propertyObserver.observe(H.get(0),{attributes:true,subtree:false})}},triggerChange:function(H){H=H||{};H=j.extend({},H,{type:"change",val:this.val()});this.opts.element.data("select2-change-triggered",true);this.opts.element.trigger(H);this.opts.element.data("select2-change-triggered",false);this.opts.element.click();if(this.opts.blurOnChange){this.opts.element.blur()}},enable:function(){if(this.enabled){return}this.enabled=true;this.container.removeClass("select2-container-disabled");this.opts.element.removeAttr("disabled")},disable:function(){if(!this.enabled){return}this.close();this.enabled=false;this.container.addClass("select2-container-disabled");this.opts.element.attr("disabled","disabled")},opened:function(){return this.container.hasClass("select2-dropdown-open")},positionDropdown:function(){var N=this.container.offset(),W=this.container.outerHeight(false),I=this.container.outerWidth(false),M=this.dropdown.outerHeight(false),P=j(window).scrollLeft()+j(window).width(),S=j(window).scrollTop()+j(window).height(),H=N.top+W,V=N.left,T=H+M<=S,R=(N.top-M)>=this.body().scrollTop(),J=this.dropdown.outerWidth(false),K=V+J<=P,L=this.dropdown.hasClass("select2-drop-above"),O,U,Q;if(this.body().css("position")!=="static"){O=this.body().offset();H-=O.top;V-=O.left}if(L){U=true;if(!R&&T){U=false}}else{U=false;if(!T&&R){U=true}}if(!K){V=N.left+I-J}if(U){H=N.top-M;this.container.addClass("select2-drop-above");this.dropdown.addClass("select2-drop-above")}else{this.container.removeClass("select2-drop-above");this.dropdown.removeClass("select2-drop-above")}Q=j.extend({top:H,left:V,width:I},t(this.opts.dropdownCss));this.dropdown.css(Q)},shouldOpen:function(){var H;if(this.opened()){return false}H=j.Event("opening");this.opts.element.trigger(H);return !H.isDefaultPrevented()},clearDropdownAlignmentPreference:function(){this.container.removeClass("select2-drop-above");this.dropdown.removeClass("select2-drop-above")},open:function(){if(!this.shouldOpen()){return false}window.setTimeout(this.bind(this.opening),1);return true},opening:function(){var M=this.containerId,H="scroll."+M,K="resize."+M,J="orientationchange."+M,I;this.clearDropdownAlignmentPreference();this.container.addClass("select2-dropdown-open").addClass("select2-container-active");if(this.dropdown[0]!==this.body().children().last()[0]){this.dropdown.detach().appendTo(this.body())}this.updateResults(true);I=j("#select2-drop-mask");if(I.length==0){I=j(document.createElement("div"));I.attr("id","select2-drop-mask").attr("class","select2-drop-mask");I.hide();I.appendTo(this.body());I.bind("mousedown touchstart",function(O){var P=j("#select2-drop"),N;if(P.length>0){N=P.data("select2");if(N.opts.selectOnBlur){N.selectHighlighted({noFocus:true})}N.close()}})}if(this.dropdown.prev()[0]!==I[0]){this.dropdown.before(I)}j("#select2-drop").removeAttr("id");this.dropdown.attr("id","select2-drop");I.css({width:document.documentElement.scrollWidth,height:document.documentElement.scrollHeight});I.show();this.dropdown.show();this.positionDropdown();this.dropdown.addClass("select2-drop-active");this.ensureHighlightVisible();var L=this;this.container.parents().add(window).each(function(){j(this).bind(K+" "+H+" "+J,function(N){j("#select2-drop-mask").css({width:document.documentElement.scrollWidth,height:document.documentElement.scrollHeight});L.positionDropdown()})});this.focusSearch()},close:function(){if(!this.opened()){return}var K=this.containerId,H="scroll."+K,J="resize."+K,I="orientationchange."+K;this.container.parents().add(window).each(function(){j(this).unbind(H).unbind(J).unbind(I)});this.clearDropdownAlignmentPreference();j("#select2-drop-mask").hide();this.dropdown.removeAttr("id");this.dropdown.hide();this.container.removeClass("select2-dropdown-open");this.results.empty();this.clearSearch();this.opts.element.trigger(j.Event("close"))},clearSearch:function(){},getMaximumSelectionSize:function(){return t(this.opts.maximumSelectionSize)},ensureHighlightVisible:function(){var K=this.results,J,H,O,N,L,M,I;H=this.highlight();if(H<0){return}if(H==0){K.scrollTop(0);return}J=this.findHighlightableChoices();O=j(J[H]);N=O.offset().top+O.outerHeight(true);if(H===J.length-1){I=K.find("li.select2-more-results");if(I.length>0){N=I.offset().top+I.outerHeight(true)}}L=K.offset().top+K.outerHeight(true);if(N>L){K.scrollTop(K.scrollTop()+(N-L))}M=O.offset().top-K.offset().top;if(M<0&&O.css("display")!="none"){K.scrollTop(K.scrollTop()+M)}},findHighlightableChoices:function(){var H=this.results.find(".select2-result-selectable:not(.select2-selected):not(.select2-disabled)");return this.results.find(".select2-result-selectable:not(.select2-selected):not(.select2-disabled)")},moveHighlight:function(K){var J=this.findHighlightableChoices(),I=this.highlight();while(I>-1&&I<J.length){I+=K;var H=j(J[I]);if(H.hasClass("select2-result-selectable")&&!H.hasClass("select2-disabled")&&!H.hasClass("select2-selected")){this.highlight(I);break}}},highlight:function(I){var K=this.findHighlightableChoices(),H,J;if(arguments.length===0){return b(K.filter(".select2-highlighted")[0],K.get())}if(I>=K.length){I=K.length-1}if(I<0){I=0}this.results.find(".select2-highlighted").removeClass("select2-highlighted");H=j(K[I]);H.addClass("select2-highlighted");this.ensureHighlightVisible();J=H.data("select2-data");if(J){this.opts.element.trigger({type:"highlight",val:this.id(J),choice:J})}},countSelectableResults:function(){return this.findHighlightableChoices().length},highlightUnderEvent:function(I){var H=j(I.target).closest(".select2-result-selectable");if(H.length>0&&!H.is(".select2-highlighted")){var J=this.findHighlightableChoices();this.highlight(J.index(H))}else{if(H.length==0){this.results.find(".select2-highlighted").removeClass("select2-highlighted")}}},loadMoreIfNeeded:function(){var L=this.results,K=L.find("li.select2-more-results"),O,N=-1,M=this.resultsPage+1,H=this,J=this.search.val(),I=this.context;if(K.length===0){return}O=K.offset().top-L.offset().top-L.height();if(O<=this.opts.loadMorePadding){K.addClass("select2-active");this.opts.query({element:this.opts.element,term:J,page:M,context:I,matcher:this.opts.matcher,callback:this.bind(function(P){if(!H.opened()){return}H.opts.populateResults.call(this,L,P.results,{term:J,page:M,context:I});if(P.more===true){K.detach().appendTo(L).text(H.opts.formatLoadMore(M+1));window.setTimeout(function(){H.loadMoreIfNeeded()},10)}else{K.remove()}H.positionDropdown();H.resultsPage=M;H.context=P.context})})}},tokenize:function(){},updateResults:function(N){var Q=this.search,L=this.results,H=this.opts,K,P=this,O;if(N!==true&&(this.showSearchInput===false||!this.opened())){return}Q.addClass("select2-active");function M(){L.scrollTop(0);Q.removeClass("select2-active");P.positionDropdown()}function I(R){L.html(R);M()}var J=this.getMaximumSelectionSize();if(J>=1){K=this.data();if(j.isArray(K)&&K.length>=J&&k(H.formatSelectionTooBig,"formatSelectionTooBig")){I("<li class='select2-selection-limit'>"+H.formatSelectionTooBig(J)+"</li>");return}}if(Q.val().length<H.minimumInputLength){if(k(H.formatInputTooShort,"formatInputTooShort")){I("<li class='select2-no-results'>"+H.formatInputTooShort(Q.val(),H.minimumInputLength)+"</li>")}else{I("")}return}else{if(H.formatSearching()&&N===true){I("<li class='select2-searching'>"+H.formatSearching()+"</li>")}}if(H.maximumInputLength&&Q.val().length>H.maximumInputLength){if(k(H.formatInputTooLong,"formatInputTooLong")){I("<li class='select2-no-results'>"+H.formatInputTooLong(Q.val(),H.maximumInputLength)+"</li>")}else{I("")}return}O=this.tokenize();if(O!=l&&O!=null){Q.val(O)}this.resultsPage=1;H.query({element:H.element,term:Q.val(),page:this.resultsPage,context:null,matcher:H.matcher,callback:this.bind(function(S){var R;if(!this.opened()){return}this.context=(S.context===l)?null:S.context;if(this.opts.createSearchChoice&&Q.val()!==""){R=this.opts.createSearchChoice.call(null,Q.val(),S.results);if(R!==l&&R!==null&&P.id(R)!==l&&P.id(R)!==null){if(j(S.results).filter(function(){return q(P.id(this),P.id(R))}).length===0){S.results.unshift(R)}}}if(S.results.length===0&&k(H.formatNoMatches,"formatNoMatches")){I("<li class='select2-no-results'>"+H.formatNoMatches(Q.val())+"</li>");return}L.empty();P.opts.populateResults.call(this,L,S.results,{term:Q.val(),page:this.resultsPage,context:null});if(S.more===true&&k(H.formatLoadMore,"formatLoadMore")){L.append("<li class='select2-more-results'>"+P.opts.escapeMarkup(H.formatLoadMore(this.resultsPage))+"</li>");window.setTimeout(function(){P.loadMoreIfNeeded()},10)}this.postprocessResults(S,N);M()})})},cancel:function(){this.close()},blur:function(){if(this.opts.selectOnBlur){this.selectHighlighted({noFocus:true})}this.close();this.container.removeClass("select2-container-active");if(this.search[0]===document.activeElement){this.search.blur()}this.clearSearch();this.selection.find(".select2-search-choice-focus").removeClass("select2-search-choice-focus")},focusSearch:function(){r(this.search)},selectHighlighted:function(I){var H=this.highlight(),J=this.results.find(".select2-highlighted"),K=J.closest(".select2-result").data("select2-data");if(K){this.highlight(H);this.onSelect(K,I)}},getPlaceholder:function(){return this.opts.element.attr("placeholder")||this.opts.element.attr("data-placeholder")||this.opts.element.data("placeholder")||this.opts.placeholder},initContainerWidth:function(){function I(){var M,K,N,L,J;if(this.opts.width==="off"){return null}else{if(this.opts.width==="element"){return this.opts.element.outerWidth(false)===0?"auto":this.opts.element.outerWidth(false)+"px"}else{if(this.opts.width==="copy"||this.opts.width==="resolve"){M=this.opts.element.attr("style");if(M!==l){K=M.split(";");for(L=0,J=K.length;L<J;L=L+1){N=K[L].replace(/\s/g,"").match(/width:(([-+]?([0-9]*\.)?[0-9]+)(px|em|ex|%|in|cm|mm|pt|pc))/);if(N!==null&&N.length>=1){return N[1]}}}if(this.opts.width==="resolve"){M=this.opts.element.css("width");if(M.indexOf("%")>0){return M}return(this.opts.element.outerWidth(false)===0?"auto":this.opts.element.outerWidth(false)+"px")}return null}else{if(j.isFunction(this.opts.width)){return this.opts.width()}else{return this.opts.width}}}}}var H=I.call(this);if(H!==null){this.container.css("width",H)}}});w=x(e,{createContainer:function(){var H=j(document.createElement("div")).attr({"class":"select2-container"}).html(["<a href='javascript:void(0)' onclick='return false;' class='select2-choice' tabindex='-1'>"," <span></span><abbr class='select2-search-choice-close' style='display:none;'></abbr>"," <div><b></b></div>","</a>","<input class='select2-focusser select2-offscreen' type='text'/>","<div class='select2-drop' style='display:none'>"," <div class='select2-search'>"," <input type='text' autocomplete='off' class='select2-input'/>"," </div>"," <ul class='select2-results'>"," </ul>","</div>"].join(""));return H},disable:function(){if(!this.enabled){return}this.parent.disable.apply(this,arguments);this.focusser.attr("disabled","disabled")},enable:function(){if(this.enabled){return}this.parent.enable.apply(this,arguments);this.focusser.removeAttr("disabled")},opening:function(){this.parent.opening.apply(this,arguments);this.focusser.attr("disabled","disabled");this.opts.element.trigger(j.Event("open"))},close:function(){if(!this.opened()){return}this.parent.close.apply(this,arguments);this.focusser.removeAttr("disabled");r(this.focusser)},focus:function(){if(this.opened()){this.close()}else{this.focusser.removeAttr("disabled");this.focusser.focus()}},isFocused:function(){return this.container.hasClass("select2-container-active")},cancel:function(){this.parent.cancel.apply(this,arguments);this.focusser.removeAttr("disabled");this.focusser.focus()},initContainer:function(){var J,I=this.container,K=this.dropdown,H=false;this.showSearch(this.opts.minimumResultsForSearch>=0);this.selection=J=I.find(".select2-choice");this.focusser=I.find(".select2-focusser");this.search.bind("keydown",this.bind(function(L){if(!this.enabled){return}if(L.which===c.PAGE_UP||L.which===c.PAGE_DOWN){d(L);return}switch(L.which){case c.UP:case c.DOWN:this.moveHighlight((L.which===c.UP)?-1:1);d(L);return;case c.TAB:case c.ENTER:this.selectHighlighted();d(L);return;case c.ESC:this.cancel(L);d(L);return}}));this.focusser.bind("keydown",this.bind(function(L){if(!this.enabled){return}if(L.which===c.TAB||c.isControl(L)||c.isFunctionKey(L)||L.which===c.ESC){return}if(this.opts.openOnEnter===false&&L.which===c.ENTER){d(L);return}if(L.which==c.DOWN||L.which==c.UP||(L.which==c.ENTER&&this.opts.openOnEnter)){this.open();d(L);return}if(L.which==c.DELETE||L.which==c.BACKSPACE){if(this.opts.allowClear){this.clear()}d(L);return}}));B(this.focusser);this.focusser.bind("keyup-change input",this.bind(function(L){if(this.opened()){return}this.open();if(this.showSearchInput!==false){this.search.val(this.focusser.val())}this.focusser.val("");d(L)}));J.delegate("abbr","mousedown",this.bind(function(L){if(!this.enabled){return}this.clear();F(L);this.close();this.selection.focus()}));J.bind("mousedown",this.bind(function(L){H=true;if(this.opened()){this.close()}else{if(this.enabled){this.open()}}d(L);H=false}));K.bind("mousedown",this.bind(function(){this.search.focus()}));J.bind("focus",this.bind(function(L){d(L)}));this.focusser.bind("focus",this.bind(function(){this.container.addClass("select2-container-active")})).bind("blur",this.bind(function(){if(!this.opened()){this.container.removeClass("select2-container-active")}}));this.search.bind("focus",this.bind(function(){this.container.addClass("select2-container-active")}));this.initContainerWidth();this.setPlaceholder()},clear:function(){var H=this.selection.data("select2-data");this.opts.element.val("");this.selection.find("span").empty();this.selection.removeData("select2-data");this.setPlaceholder();this.opts.element.trigger({type:"removed",val:this.id(H),choice:H});this.triggerChange({removed:H})},initSelection:function(){var I;if(this.opts.element.val()===""&&this.opts.element.text()===""){this.close();this.setPlaceholder()}else{var H=this;this.opts.initSelection.call(null,this.opts.element,function(J){if(J!==l&&J!==null){H.updateSelection(J);H.close();H.setPlaceholder()}})}},prepareOpts:function(){var H=this.parent.prepareOpts.apply(this,arguments);if(H.element.get(0).tagName.toLowerCase()==="select"){H.initSelection=function(I,K){var J=I.find(":selected");if(j.isFunction(K)){K({id:J.attr("value"),text:J.text(),element:J})}}}else{if("data" in H){H.initSelection=H.initSelection||function(I,K){var J=I.val();H.query({matcher:function(L,N,M){return q(J,H.id(M))},callback:!j.isFunction(K)?j.noop:function(L){K(L.results.length?L.results[0]:null)}})}}}return H},getPlaceholder:function(){if(this.select){if(this.select.find("option").first().text()!==""){return l}}return this.parent.getPlaceholder.apply(this,arguments)},setPlaceholder:function(){var H=this.getPlaceholder();if(this.opts.element.val()===""&&H!==l){if(this.select&&this.select.find("option:first").text()!==""){return}this.selection.find("span").html(this.opts.escapeMarkup(H));this.selection.addClass("select2-default");this.selection.find("abbr").hide()}},postprocessResults:function(L,I){var K=0,H=this,M=true;this.findHighlightableChoices().each2(function(N,O){if(q(H.id(O.data("select2-data")),H.opts.element.val())){K=N;return false}});this.highlight(K);if(I===true){var J=this.opts.minimumResultsForSearch;M=J<0?false:h(L.results)>=J;this.showSearch(M)}},showSearch:function(H){this.showSearchInput=H;this.dropdown.find(".select2-search")[H?"removeClass":"addClass"]("select2-search-hidden");j(this.dropdown,this.container)[H?"addClass":"removeClass"]("select2-with-searchbox")},onSelect:function(J,I){var H=this.opts.element.val();this.opts.element.val(this.id(J));this.updateSelection(J);this.opts.element.trigger({type:"selected",val:this.id(J),choice:J});this.close();if(!I||!I.noFocus){this.selection.focus()}if(!q(H,this.id(J))){this.triggerChange()}},updateSelection:function(J){var H=this.selection.find("span"),I;this.selection.data("select2-data",J);H.empty();I=this.opts.formatSelection(J,H);if(I!==l){H.append(this.opts.escapeMarkup(I))}this.selection.removeClass("select2-default");if(this.opts.allowClear&&this.getPlaceholder()!==l){this.selection.find("abbr").show()}},val:function(){var K,I=false,J=null,H=this;if(arguments.length===0){return this.opts.element.val()}K=arguments[0];if(arguments.length>1){I=arguments[1]}if(this.select){this.select.val(K).find(":selected").each2(function(L,M){J={id:M.attr("value"),text:M.text()};return false});this.updateSelection(J);this.setPlaceholder();if(I){this.triggerChange()}}else{if(this.opts.initSelection===l){throw new Error("cannot call val() if initSelection() is not defined")}if(!K&&K!==0){this.clear();if(I){this.triggerChange()}return}this.opts.element.val(K);this.opts.initSelection(this.opts.element,function(L){H.opts.element.val(!L?"":H.id(L));H.updateSelection(L);H.setPlaceholder();if(I){H.triggerChange()}})}},clearSearch:function(){this.search.val("");this.focusser.val("")},data:function(I){var H;if(arguments.length===0){H=this.selection.data("select2-data");if(H==l){H=null}return H}else{if(!I||I===""){this.clear()}else{this.opts.element.val(!I?"":this.id(I));this.updateSelection(I)}}}});G=x(e,{createContainer:function(){var H=j(document.createElement("div")).attr({"class":"select2-container select2-container-multi"}).html([" <ul class='select2-choices'>"," <li class='select2-search-field'>"," <input type='text' autocomplete='off' class='select2-input'>"," </li>","</ul>","<div class='select2-drop select2-drop-multi' style='display:none;'>"," <ul class='select2-results'>"," </ul>","</div>"].join(""));return H},prepareOpts:function(){var H=this.parent.prepareOpts.apply(this,arguments);if(H.element.get(0).tagName.toLowerCase()==="select"){H.initSelection=function(I,K){var J=[];I.find(":selected").each2(function(L,M){J.push({id:M.attr("value"),text:M.text(),element:M[0]})});K(J)}}else{if("data" in H){H.initSelection=H.initSelection||function(I,K){var J=m(I.val(),H.separator);H.query({matcher:function(L,N,M){return j.grep(J,function(O){return q(O,H.id(M))}).length},callback:!j.isFunction(K)?j.noop:function(L){K(L.results)}})}}}return H},initContainer:function(){var H=".select2-choices",I;this.searchContainer=this.container.find(".select2-search-field");this.selection=I=this.container.find(H);this.search.bind("input paste",this.bind(function(){if(!this.enabled){return}if(!this.opened()){this.open()}}));this.search.bind("keydown",this.bind(function(K){if(!this.enabled){return}if(K.which===c.BACKSPACE&&this.search.val()===""){this.close();var L,J=I.find(".select2-search-choice-focus");if(J.length>0){this.unselect(J.first());this.search.width(10);d(K);return}L=I.find(".select2-search-choice:not(.select2-locked)");if(L.length>0){L.last().addClass("select2-search-choice-focus")}}else{I.find(".select2-search-choice-focus").removeClass("select2-search-choice-focus")}if(this.opened()){switch(K.which){case c.UP:case c.DOWN:this.moveHighlight((K.which===c.UP)?-1:1);d(K);return;case c.ENTER:case c.TAB:this.selectHighlighted();d(K);return;case c.ESC:this.cancel(K);d(K);return}}if(K.which===c.TAB||c.isControl(K)||c.isFunctionKey(K)||K.which===c.BACKSPACE||K.which===c.ESC){return}if(K.which===c.ENTER){if(this.opts.openOnEnter===false){return}else{if(K.altKey||K.ctrlKey||K.shiftKey||K.metaKey){return}}}this.open();if(K.which===c.PAGE_UP||K.which===c.PAGE_DOWN){d(K)}}));this.search.bind("keyup",this.bind(this.resizeSearch));this.search.bind("blur",this.bind(function(J){this.container.removeClass("select2-container-active");this.search.removeClass("select2-focused");if(!this.opened()){this.clearSearch()}J.stopImmediatePropagation()}));this.container.delegate(H,"mousedown",this.bind(function(J){if(!this.enabled){return}if(j(J.target).closest(".select2-search-choice").length>0){return}this.clearPlaceholder();this.open();this.focusSearch();J.preventDefault()}));this.container.delegate(H,"focus",this.bind(function(){if(!this.enabled){return}this.container.addClass("select2-container-active");this.dropdown.addClass("select2-drop-active");this.clearPlaceholder()}));this.initContainerWidth();this.clearSearch()},enable:function(){if(this.enabled){return}this.parent.enable.apply(this,arguments);this.search.removeAttr("disabled")},disable:function(){if(!this.enabled){return}this.parent.disable.apply(this,arguments);this.search.attr("disabled",true)},initSelection:function(){var I;if(this.opts.element.val()===""&&this.opts.element.text()===""){this.updateSelection([]);this.close();this.clearSearch()}if(this.select||this.opts.element.val()!==""){var H=this;this.opts.initSelection.call(null,this.opts.element,function(J){if(J!==l&&J!==null){H.updateSelection(J);H.close();H.clearSearch()}})}},clearSearch:function(){var H=this.getPlaceholder();if(H!==l&&this.getVal().length===0&&this.search.hasClass("select2-focused")===false){this.search.val(H).addClass("select2-default");this.resizeSearch()}else{this.search.val("").width(10)}},clearPlaceholder:function(){if(this.search.hasClass("select2-default")){this.search.val("").removeClass("select2-default")}},opening:function(){this.parent.opening.apply(this,arguments);this.clearPlaceholder();this.resizeSearch();this.focusSearch();this.opts.element.trigger(j.Event("open"))},close:function(){if(!this.opened()){return}this.parent.close.apply(this,arguments)},focus:function(){this.close();this.search.focus();this.opts.element.triggerHandler("focus")},isFocused:function(){return this.search.hasClass("select2-focused")},updateSelection:function(K){var J=[],I=[],H=this;j(K).each(function(){if(b(H.id(this),J)<0){J.push(H.id(this));I.push(this)}});K=I;this.selection.find(".select2-search-choice").remove();j(K).each(function(){H.addSelectedChoice(this)});H.postprocessResults()},tokenize:function(){var H=this.search.val();H=this.opts.tokenizer(H,this.data(),this.bind(this.onSelect),this.opts);if(H!=null&&H!=l){this.search.val(H);if(H.length>0){this.open()}}},onSelect:function(I,H){this.addSelectedChoice(I);this.opts.element.trigger({type:"selected",val:this.id(I),choice:I});if(this.select||!this.opts.closeOnSelect){this.postprocessResults()}if(this.opts.closeOnSelect){this.close();this.search.width(10)}else{if(this.countSelectableResults()>0){this.search.width(10);this.resizeSearch();if(this.val().length>=this.getMaximumSelectionSize()){this.updateResults(true)}this.positionDropdown()}else{this.close();this.search.width(10)}}this.triggerChange({added:I});if(!H||!H.noFocus){this.focusSearch()}},cancel:function(){this.close();this.focusSearch()},addSelectedChoice:function(K){var I=!K.locked,O=j("<li class='select2-search-choice'> <div></div> <a href='#' onclick='return false;' class='select2-search-choice-close' tabindex='-1'></a></li>"),N=j("<li class='select2-search-choice select2-locked'><div></div></li>");var H=I?O:N,M=this.id(K),L=this.getVal(),J;J=this.opts.formatSelection(K,H.find("div"));if(J!=l){H.find("div").replaceWith("<div>"+this.opts.escapeMarkup(J)+"</div>")}if(I){H.find(".select2-search-choice-close").bind("mousedown",d).bind("click dblclick",this.bind(function(P){if(!this.enabled){return}j(P.target).closest(".select2-search-choice").fadeOut("fast",this.bind(function(){this.unselect(j(P.target));this.selection.find(".select2-search-choice-focus").removeClass("select2-search-choice-focus");this.close();this.focusSearch()})).dequeue();d(P)})).bind("focus",this.bind(function(){if(!this.enabled){return}this.container.addClass("select2-container-active");this.dropdown.addClass("select2-drop-active")}))}H.data("select2-data",K);H.insertBefore(this.searchContainer);L.push(M);this.setVal(L)},unselect:function(I){var K=this.getVal(),J,H;I=I.closest(".select2-search-choice");if(I.length===0){throw"Invalid argument: "+I+". Must be .select2-search-choice"}J=I.data("select2-data");if(!J){return}H=b(this.id(J),K);if(H>=0){K.splice(H,1);this.setVal(K);if(this.select){this.postprocessResults()}}I.remove();this.opts.element.trigger({type:"removed",val:this.id(J),choice:J});this.triggerChange({removed:J})},postprocessResults:function(){var J=this.getVal(),K=this.results.find(".select2-result"),I=this.results.find(".select2-result-with-children"),H=this;K.each2(function(M,L){var N=H.id(L.data("select2-data"));if(b(N,J)>=0){L.addClass("select2-selected");L.find(".select2-result-selectable").addClass("select2-selected")}});I.each2(function(M,L){if(!L.is(".select2-result-selectable")&&L.find(".select2-result-selectable:not(.select2-selected)").length===0){L.addClass("select2-selected")}});if(this.highlight()==-1){H.highlight(0)}},resizeSearch:function(){var M,K,J,H,I,L=n(this.search);M=z(this.search)+10;K=this.search.offset().left;J=this.selection.width();H=this.selection.offset().left;I=J-(K-H)-L;if(I<M){I=J-L}if(I<40){I=J-L}if(I<=0){I=M}this.search.width(I)},getVal:function(){var H;if(this.select){H=this.select.val();return H===null?[]:H}else{H=this.opts.element.val();return m(H,this.opts.separator)}},setVal:function(I){var H;if(this.select){this.select.val(I)}else{H=[];j(I).each(function(){if(b(this,H)<0){H.push(this)}});this.opts.element.val(H.length===0?"":H.join(this.opts.separator))}},val:function(){var K,I=false,J=[],H=this;if(arguments.length===0){return this.getVal()}K=arguments[0];if(arguments.length>1){I=arguments[1]}if(!K&&K!==0){this.opts.element.val("");this.updateSelection([]);this.clearSearch();if(I){this.triggerChange()}return}this.setVal(K);if(this.select){this.opts.initSelection(this.select,this.bind(this.updateSelection));if(I){this.triggerChange()}}else{if(this.opts.initSelection===l){throw new Error("val() cannot be called if initSelection() is not defined")}this.opts.initSelection(this.opts.element,function(M){var L=j(M).map(H.id);H.setVal(L);H.updateSelection(M);H.clearSearch();if(I){H.triggerChange()}})}this.clearSearch()},onSortStart:function(){if(this.select){throw new Error("Sorting of elements is not supported when attached to <select>. Attach to <input type='hidden'/> instead.")}this.search.width(0);this.searchContainer.hide()},onSortEnd:function(){var I=[],H=this;this.searchContainer.show();this.searchContainer.appendTo(this.searchContainer.parent());this.resizeSearch();this.selection.find(".select2-search-choice").each(function(){I.push(H.opts.id(j(this).data("select2-data")))});this.setVal(I);this.triggerChange()},data:function(I){var H=this,J;if(arguments.length===0){return this.selection.find(".select2-search-choice").map(function(){return j(this).data("select2-data")}).get()}else{if(!I){I=[]}J=j.map(I,function(K){return H.opts.id(K)});this.setVal(J);this.updateSelection(I);this.clearSearch()}}});j.fn.select2=function(){var K=Array.prototype.slice.call(arguments,0),L,J,M,I,H=["val","destroy","opened","open","close","focus","isFocused","container","onSortStart","onSortEnd","enable","disable","positionDropdown","data"];this.each(function(){if(K.length===0||typeof(K[0])==="object"){L=K.length===0?{}:j.extend({},K[0]);L.element=j(this);if(L.element.get(0).tagName.toLowerCase()==="select"){I=L.element.attr("multiple")}else{I=L.multiple||false;if("tags" in L){L.multiple=I=true}}J=I?new G():new w();J.init(L)}else{if(typeof(K[0])==="string"){if(b(K[0],H)<0){throw"Unknown method: "+K[0]}M=l;J=j(this).data("select2");if(J===l){return}if(K[0]==="container"){M=J.container}else{M=J[K[0]].apply(J,K.slice(1))}if(M!==l){return false}}else{throw"Invalid arguments to select2 plugin: "+K}}});return(M===l)?this:M};j.fn.select2.defaults={width:"copy",loadMorePadding:0,closeOnSelect:true,openOnEnter:true,containerCss:{},dropdownCss:{},containerCssClass:"",dropdownCssClass:"",formatResult:function(I,J,L,H){var K=[];i(I.text,L.term,K,H);return K.join("")},formatSelection:function(I,H){return I?I.text:l},sortResults:function(I,H,J){return I},formatResultCssClass:function(H){return l},formatNoMatches:function(){return"No matches found"},formatInputTooShort:function(H,I){var J=I-H.length;return"Please enter "+J+" more character"+(J==1?"":"s")},formatInputTooLong:function(I,H){var J=I.length-H;return"Please enter "+J+" less character"+(J==1?"":"s")},formatSelectionTooBig:function(H){return"You can only select "+H+" item"+(H==1?"":"s")},formatLoadMore:function(H){return"Loading more results..."},formatSearching:function(){return"Searching..."},minimumResultsForSearch:0,minimumInputLength:0,maximumInputLength:null,maximumSelectionSize:0,id:function(H){return H.id},matcher:function(H,I){return I.toUpperCase().indexOf(H.toUpperCase())>=0},separator:",",tokenSeparators:[],tokenizer:A,escapeMarkup:function(H){var I={"\\":"\","&":"&","<":"<",">":">",'"':""","'":"'","/":"/"};return String(H).replace(/[&<>"'/\\]/g,function(J){return I[J[0]]})},blurOnChange:false,selectOnBlur:false,adaptContainerCssClass:function(H){return H},adaptDropdownCssClass:function(H){return null}};window.Select2={query:{ajax:p,local:s,tags:o},util:{debounce:g,markMatch:i},"class":{"abstract":e,single:w,multi:G}}}(jQuery)); |