django-select2/django_select2/static/js/select2.min.js

1 line
40 KiB
JavaScript
Raw Normal View History

2013-03-12 18:59:02 +00:00
(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.pa