tenon 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tenon/version.rb +1 -1
  3. data/vendor/assets/images/Jcrop.gif +0 -0
  4. data/vendor/assets/javascripts/backstretch.js +4 -0
  5. data/vendor/assets/javascripts/bootstrap.collapse.js +179 -0
  6. data/vendor/assets/javascripts/bootstrap.datetimepicker.js +954 -0
  7. data/vendor/assets/javascripts/bootstrap.js +561 -0
  8. data/vendor/assets/javascripts/bootstrap.modal.js +246 -0
  9. data/vendor/assets/javascripts/bootstrap.tabs.js +135 -0
  10. data/vendor/assets/javascripts/canvasjs.min.js +343 -0
  11. data/vendor/assets/javascripts/cufon/Aller_400.font.js +7 -0
  12. data/vendor/assets/javascripts/cufon/Aller_700.font.js +7 -0
  13. data/vendor/assets/javascripts/cufon/cufon.js +7 -0
  14. data/vendor/assets/javascripts/imagesloaded.js +7 -0
  15. data/vendor/assets/javascripts/jquery.Jcrop.js +1704 -0
  16. data/vendor/assets/javascripts/jquery.corner.js +249 -0
  17. data/vendor/assets/javascripts/jquery.debounce.js +9 -0
  18. data/vendor/assets/javascripts/jquery.equalHeights.js +52 -0
  19. data/vendor/assets/javascripts/jquery.form.js +911 -0
  20. data/vendor/assets/javascripts/jquery.hoverIntent.js +115 -0
  21. data/vendor/assets/javascripts/jquery.mousewheel.js +78 -0
  22. data/vendor/assets/javascripts/jquery.radioSlider.js +55 -0
  23. data/vendor/assets/javascripts/jquery.twoLevelSort.js +57 -0
  24. data/vendor/assets/javascripts/jquery.ui.sortable.js +2252 -0
  25. data/vendor/assets/javascripts/jscrollpane.js +1435 -0
  26. data/vendor/assets/javascripts/moment.js +6 -0
  27. data/vendor/assets/javascripts/select2.js +3448 -0
  28. data/vendor/assets/javascripts/underscore.inflection.js +177 -0
  29. data/vendor/assets/javascripts/underscore.string.js +1 -0
  30. data/vendor/assets/javascripts/uri.js +53 -0
  31. data/vendor/assets/stylesheets/bootstrap.css.scss +560 -0
  32. data/vendor/assets/stylesheets/bootstrap.datetimepicker.css +152 -0
  33. data/vendor/assets/stylesheets/bootstrap.tables.css.scss +201 -0
  34. data/vendor/assets/stylesheets/jquery.Jcrop.css +204 -0
  35. data/vendor/assets/stylesheets/jscrollpane.css.scss +20 -0
  36. data/vendor/assets/stylesheets/select2.css +646 -0
  37. metadata +35 -1
@@ -0,0 +1,6 @@
1
+ //! moment.js
2
+ //! version : 2.4.0
3
+ //! authors : Tim Wood, Iskren Chernev, Moment.js contributors
4
+ //! license : MIT
5
+ //! momentjs.com
6
+ (function(a){function b(a,b){return function(c){return i(a.call(this,c),b)}}function c(a,b){return function(c){return this.lang().ordinal(a.call(this,c),b)}}function d(){}function e(a){u(a),g(this,a)}function f(a){var b=o(a),c=b.year||0,d=b.month||0,e=b.week||0,f=b.day||0,g=b.hour||0,h=b.minute||0,i=b.second||0,j=b.millisecond||0;this._input=a,this._milliseconds=+j+1e3*i+6e4*h+36e5*g,this._days=+f+7*e,this._months=+d+12*c,this._data={},this._bubble()}function g(a,b){for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return b.hasOwnProperty("toString")&&(a.toString=b.toString),b.hasOwnProperty("valueOf")&&(a.valueOf=b.valueOf),a}function h(a){return 0>a?Math.ceil(a):Math.floor(a)}function i(a,b){for(var c=a+"";c.length<b;)c="0"+c;return c}function j(a,b,c,d){var e,f,g=b._milliseconds,h=b._days,i=b._months;g&&a._d.setTime(+a._d+g*c),(h||i)&&(e=a.minute(),f=a.hour()),h&&a.date(a.date()+h*c),i&&a.month(a.month()+i*c),g&&!d&&bb.updateOffset(a),(h||i)&&(a.minute(e),a.hour(f))}function k(a){return"[object Array]"===Object.prototype.toString.call(a)}function l(a){return"[object Date]"===Object.prototype.toString.call(a)||a instanceof Date}function m(a,b,c){var d,e=Math.min(a.length,b.length),f=Math.abs(a.length-b.length),g=0;for(d=0;e>d;d++)(c&&a[d]!==b[d]||!c&&q(a[d])!==q(b[d]))&&g++;return g+f}function n(a){if(a){var b=a.toLowerCase().replace(/(.)s$/,"$1");a=Kb[a]||Lb[b]||b}return a}function o(a){var b,c,d={};for(c in a)a.hasOwnProperty(c)&&(b=n(c),b&&(d[b]=a[c]));return d}function p(b){var c,d;if(0===b.indexOf("week"))c=7,d="day";else{if(0!==b.indexOf("month"))return;c=12,d="month"}bb[b]=function(e,f){var g,h,i=bb.fn._lang[b],j=[];if("number"==typeof e&&(f=e,e=a),h=function(a){var b=bb().utc().set(d,a);return i.call(bb.fn._lang,b,e||"")},null!=f)return h(f);for(g=0;c>g;g++)j.push(h(g));return j}}function q(a){var b=+a,c=0;return 0!==b&&isFinite(b)&&(c=b>=0?Math.floor(b):Math.ceil(b)),c}function r(a,b){return new Date(Date.UTC(a,b+1,0)).getUTCDate()}function s(a){return t(a)?366:365}function t(a){return 0===a%4&&0!==a%100||0===a%400}function u(a){var b;a._a&&-2===a._pf.overflow&&(b=a._a[gb]<0||a._a[gb]>11?gb:a._a[hb]<1||a._a[hb]>r(a._a[fb],a._a[gb])?hb:a._a[ib]<0||a._a[ib]>23?ib:a._a[jb]<0||a._a[jb]>59?jb:a._a[kb]<0||a._a[kb]>59?kb:a._a[lb]<0||a._a[lb]>999?lb:-1,a._pf._overflowDayOfYear&&(fb>b||b>hb)&&(b=hb),a._pf.overflow=b)}function v(a){a._pf={empty:!1,unusedTokens:[],unusedInput:[],overflow:-2,charsLeftOver:0,nullInput:!1,invalidMonth:null,invalidFormat:!1,userInvalidated:!1,iso:!1}}function w(a){return null==a._isValid&&(a._isValid=!isNaN(a._d.getTime())&&a._pf.overflow<0&&!a._pf.empty&&!a._pf.invalidMonth&&!a._pf.nullInput&&!a._pf.invalidFormat&&!a._pf.userInvalidated,a._strict&&(a._isValid=a._isValid&&0===a._pf.charsLeftOver&&0===a._pf.unusedTokens.length)),a._isValid}function x(a){return a?a.toLowerCase().replace("_","-"):a}function y(a,b){return b.abbr=a,mb[a]||(mb[a]=new d),mb[a].set(b),mb[a]}function z(a){delete mb[a]}function A(a){var b,c,d,e,f=0,g=function(a){if(!mb[a]&&nb)try{require("./lang/"+a)}catch(b){}return mb[a]};if(!a)return bb.fn._lang;if(!k(a)){if(c=g(a))return c;a=[a]}for(;f<a.length;){for(e=x(a[f]).split("-"),b=e.length,d=x(a[f+1]),d=d?d.split("-"):null;b>0;){if(c=g(e.slice(0,b).join("-")))return c;if(d&&d.length>=b&&m(e,d,!0)>=b-1)break;b--}f++}return bb.fn._lang}function B(a){return a.match(/\[[\s\S]/)?a.replace(/^\[|\]$/g,""):a.replace(/\\/g,"")}function C(a){var b,c,d=a.match(rb);for(b=0,c=d.length;c>b;b++)d[b]=Pb[d[b]]?Pb[d[b]]:B(d[b]);return function(e){var f="";for(b=0;c>b;b++)f+=d[b]instanceof Function?d[b].call(e,a):d[b];return f}}function D(a,b){return a.isValid()?(b=E(b,a.lang()),Mb[b]||(Mb[b]=C(b)),Mb[b](a)):a.lang().invalidDate()}function E(a,b){function c(a){return b.longDateFormat(a)||a}var d=5;for(sb.lastIndex=0;d>=0&&sb.test(a);)a=a.replace(sb,c),sb.lastIndex=0,d-=1;return a}function F(a,b){var c;switch(a){case"DDDD":return vb;case"YYYY":case"GGGG":case"gggg":return wb;case"YYYYY":case"GGGGG":case"ggggg":return xb;case"S":case"SS":case"SSS":case"DDD":return ub;case"MMM":case"MMMM":case"dd":case"ddd":case"dddd":return zb;case"a":case"A":return A(b._l)._meridiemParse;case"X":return Cb;case"Z":case"ZZ":return Ab;case"T":return Bb;case"SSSS":return yb;case"MM":case"DD":case"YY":case"GG":case"gg":case"HH":case"hh":case"mm":case"ss":case"M":case"D":case"d":case"H":case"h":case"m":case"s":case"w":case"ww":case"W":case"WW":case"e":case"E":return tb;default:return c=new RegExp(N(M(a.replace("\\","")),"i"))}}function G(a){var b=(Ab.exec(a)||[])[0],c=(b+"").match(Hb)||["-",0,0],d=+(60*c[1])+q(c[2]);return"+"===c[0]?-d:d}function H(a,b,c){var d,e=c._a;switch(a){case"M":case"MM":null!=b&&(e[gb]=q(b)-1);break;case"MMM":case"MMMM":d=A(c._l).monthsParse(b),null!=d?e[gb]=d:c._pf.invalidMonth=b;break;case"D":case"DD":null!=b&&(e[hb]=q(b));break;case"DDD":case"DDDD":null!=b&&(c._dayOfYear=q(b));break;case"YY":e[fb]=q(b)+(q(b)>68?1900:2e3);break;case"YYYY":case"YYYYY":e[fb]=q(b);break;case"a":case"A":c._isPm=A(c._l).isPM(b);break;case"H":case"HH":case"h":case"hh":e[ib]=q(b);break;case"m":case"mm":e[jb]=q(b);break;case"s":case"ss":e[kb]=q(b);break;case"S":case"SS":case"SSS":case"SSSS":e[lb]=q(1e3*("0."+b));break;case"X":c._d=new Date(1e3*parseFloat(b));break;case"Z":case"ZZ":c._useUTC=!0,c._tzm=G(b);break;case"w":case"ww":case"W":case"WW":case"d":case"dd":case"ddd":case"dddd":case"e":case"E":a=a.substr(0,1);case"gg":case"gggg":case"GG":case"GGGG":case"GGGGG":a=a.substr(0,2),b&&(c._w=c._w||{},c._w[a]=b)}}function I(a){var b,c,d,e,f,g,h,i,j,k,l=[];if(!a._d){for(d=K(a),a._w&&null==a._a[hb]&&null==a._a[gb]&&(f=function(b){return b?b.length<3?parseInt(b,10)>68?"19"+b:"20"+b:b:null==a._a[fb]?bb().weekYear():a._a[fb]},g=a._w,null!=g.GG||null!=g.W||null!=g.E?h=X(f(g.GG),g.W||1,g.E,4,1):(i=A(a._l),j=null!=g.d?T(g.d,i):null!=g.e?parseInt(g.e,10)+i._week.dow:0,k=parseInt(g.w,10)||1,null!=g.d&&j<i._week.dow&&k++,h=X(f(g.gg),k,j,i._week.doy,i._week.dow)),a._a[fb]=h.year,a._dayOfYear=h.dayOfYear),a._dayOfYear&&(e=null==a._a[fb]?d[fb]:a._a[fb],a._dayOfYear>s(e)&&(a._pf._overflowDayOfYear=!0),c=S(e,0,a._dayOfYear),a._a[gb]=c.getUTCMonth(),a._a[hb]=c.getUTCDate()),b=0;3>b&&null==a._a[b];++b)a._a[b]=l[b]=d[b];for(;7>b;b++)a._a[b]=l[b]=null==a._a[b]?2===b?1:0:a._a[b];l[ib]+=q((a._tzm||0)/60),l[jb]+=q((a._tzm||0)%60),a._d=(a._useUTC?S:R).apply(null,l)}}function J(a){var b;a._d||(b=o(a._i),a._a=[b.year,b.month,b.day,b.hour,b.minute,b.second,b.millisecond],I(a))}function K(a){var b=new Date;return a._useUTC?[b.getUTCFullYear(),b.getUTCMonth(),b.getUTCDate()]:[b.getFullYear(),b.getMonth(),b.getDate()]}function L(a){a._a=[],a._pf.empty=!0;var b,c,d,e,f,g=A(a._l),h=""+a._i,i=h.length,j=0;for(d=E(a._f,g).match(rb)||[],b=0;b<d.length;b++)e=d[b],c=(F(e,a).exec(h)||[])[0],c&&(f=h.substr(0,h.indexOf(c)),f.length>0&&a._pf.unusedInput.push(f),h=h.slice(h.indexOf(c)+c.length),j+=c.length),Pb[e]?(c?a._pf.empty=!1:a._pf.unusedTokens.push(e),H(e,c,a)):a._strict&&!c&&a._pf.unusedTokens.push(e);a._pf.charsLeftOver=i-j,h.length>0&&a._pf.unusedInput.push(h),a._isPm&&a._a[ib]<12&&(a._a[ib]+=12),a._isPm===!1&&12===a._a[ib]&&(a._a[ib]=0),I(a),u(a)}function M(a){return a.replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g,function(a,b,c,d,e){return b||c||d||e})}function N(a){return a.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}function O(a){var b,c,d,e,f;if(0===a._f.length)return a._pf.invalidFormat=!0,a._d=new Date(0/0),void 0;for(e=0;e<a._f.length;e++)f=0,b=g({},a),v(b),b._f=a._f[e],L(b),w(b)&&(f+=b._pf.charsLeftOver,f+=10*b._pf.unusedTokens.length,b._pf.score=f,(null==d||d>f)&&(d=f,c=b));g(a,c||b)}function P(a){var b,c=a._i,d=Db.exec(c);if(d){for(a._pf.iso=!0,b=4;b>0;b--)if(d[b]){a._f=Fb[b-1]+(d[6]||" ");break}for(b=0;4>b;b++)if(Gb[b][1].exec(c)){a._f+=Gb[b][0];break}Ab.exec(c)&&(a._f+="Z"),L(a)}else a._d=new Date(c)}function Q(b){var c=b._i,d=ob.exec(c);c===a?b._d=new Date:d?b._d=new Date(+d[1]):"string"==typeof c?P(b):k(c)?(b._a=c.slice(0),I(b)):l(c)?b._d=new Date(+c):"object"==typeof c?J(b):b._d=new Date(c)}function R(a,b,c,d,e,f,g){var h=new Date(a,b,c,d,e,f,g);return 1970>a&&h.setFullYear(a),h}function S(a){var b=new Date(Date.UTC.apply(null,arguments));return 1970>a&&b.setUTCFullYear(a),b}function T(a,b){if("string"==typeof a)if(isNaN(a)){if(a=b.weekdaysParse(a),"number"!=typeof a)return null}else a=parseInt(a,10);return a}function U(a,b,c,d,e){return e.relativeTime(b||1,!!c,a,d)}function V(a,b,c){var d=eb(Math.abs(a)/1e3),e=eb(d/60),f=eb(e/60),g=eb(f/24),h=eb(g/365),i=45>d&&["s",d]||1===e&&["m"]||45>e&&["mm",e]||1===f&&["h"]||22>f&&["hh",f]||1===g&&["d"]||25>=g&&["dd",g]||45>=g&&["M"]||345>g&&["MM",eb(g/30)]||1===h&&["y"]||["yy",h];return i[2]=b,i[3]=a>0,i[4]=c,U.apply({},i)}function W(a,b,c){var d,e=c-b,f=c-a.day();return f>e&&(f-=7),e-7>f&&(f+=7),d=bb(a).add("d",f),{week:Math.ceil(d.dayOfYear()/7),year:d.year()}}function X(a,b,c,d,e){var f,g,h=new Date(Date.UTC(a,0)).getUTCDay();return c=null!=c?c:e,f=e-h+(h>d?7:0),g=7*(b-1)+(c-e)+f+1,{year:g>0?a:a-1,dayOfYear:g>0?g:s(a-1)+g}}function Y(a){var b=a._i,c=a._f;return"undefined"==typeof a._pf&&v(a),null===b?bb.invalid({nullInput:!0}):("string"==typeof b&&(a._i=b=A().preparse(b)),bb.isMoment(b)?(a=g({},b),a._d=new Date(+b._d)):c?k(c)?O(a):L(a):Q(a),new e(a))}function Z(a,b){bb.fn[a]=bb.fn[a+"s"]=function(a){var c=this._isUTC?"UTC":"";return null!=a?(this._d["set"+c+b](a),bb.updateOffset(this),this):this._d["get"+c+b]()}}function $(a){bb.duration.fn[a]=function(){return this._data[a]}}function _(a,b){bb.duration.fn["as"+a]=function(){return+this/b}}function ab(a){var b=!1,c=bb;"undefined"==typeof ender&&(this.moment=a?function(){return!b&&console&&console.warn&&(b=!0,console.warn("Accessing Moment through the global scope is deprecated, and will be removed in an upcoming release.")),c.apply(null,arguments)}:bb)}for(var bb,cb,db="2.4.0",eb=Math.round,fb=0,gb=1,hb=2,ib=3,jb=4,kb=5,lb=6,mb={},nb="undefined"!=typeof module&&module.exports,ob=/^\/?Date\((\-?\d+)/i,pb=/(\-)?(?:(\d*)\.)?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?)?/,qb=/^(-)?P(?:(?:([0-9,.]*)Y)?(?:([0-9,.]*)M)?(?:([0-9,.]*)D)?(?:T(?:([0-9,.]*)H)?(?:([0-9,.]*)M)?(?:([0-9,.]*)S)?)?|([0-9,.]*)W)$/,rb=/(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|mm?|ss?|S{1,4}|X|zz?|ZZ?|.)/g,sb=/(\[[^\[]*\])|(\\)?(LT|LL?L?L?|l{1,4})/g,tb=/\d\d?/,ub=/\d{1,3}/,vb=/\d{3}/,wb=/\d{1,4}/,xb=/[+\-]?\d{1,6}/,yb=/\d+/,zb=/[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i,Ab=/Z|[\+\-]\d\d:?\d\d/i,Bb=/T/i,Cb=/[\+\-]?\d+(\.\d{1,3})?/,Db=/^\s*\d{4}-(?:(\d\d-\d\d)|(W\d\d$)|(W\d\d-\d)|(\d\d\d))((T| )(\d\d(:\d\d(:\d\d(\.\d+)?)?)?)?([\+\-]\d\d:?\d\d|Z)?)?$/,Eb="YYYY-MM-DDTHH:mm:ssZ",Fb=["YYYY-MM-DD","GGGG-[W]WW","GGGG-[W]WW-E","YYYY-DDD"],Gb=[["HH:mm:ss.SSSS",/(T| )\d\d:\d\d:\d\d\.\d{1,3}/],["HH:mm:ss",/(T| )\d\d:\d\d:\d\d/],["HH:mm",/(T| )\d\d:\d\d/],["HH",/(T| )\d\d/]],Hb=/([\+\-]|\d\d)/gi,Ib="Date|Hours|Minutes|Seconds|Milliseconds".split("|"),Jb={Milliseconds:1,Seconds:1e3,Minutes:6e4,Hours:36e5,Days:864e5,Months:2592e6,Years:31536e6},Kb={ms:"millisecond",s:"second",m:"minute",h:"hour",d:"day",D:"date",w:"week",W:"isoWeek",M:"month",y:"year",DDD:"dayOfYear",e:"weekday",E:"isoWeekday",gg:"weekYear",GG:"isoWeekYear"},Lb={dayofyear:"dayOfYear",isoweekday:"isoWeekday",isoweek:"isoWeek",weekyear:"weekYear",isoweekyear:"isoWeekYear"},Mb={},Nb="DDD w W M D d".split(" "),Ob="M D H h m s w W".split(" "),Pb={M:function(){return this.month()+1},MMM:function(a){return this.lang().monthsShort(this,a)},MMMM:function(a){return this.lang().months(this,a)},D:function(){return this.date()},DDD:function(){return this.dayOfYear()},d:function(){return this.day()},dd:function(a){return this.lang().weekdaysMin(this,a)},ddd:function(a){return this.lang().weekdaysShort(this,a)},dddd:function(a){return this.lang().weekdays(this,a)},w:function(){return this.week()},W:function(){return this.isoWeek()},YY:function(){return i(this.year()%100,2)},YYYY:function(){return i(this.year(),4)},YYYYY:function(){return i(this.year(),5)},gg:function(){return i(this.weekYear()%100,2)},gggg:function(){return this.weekYear()},ggggg:function(){return i(this.weekYear(),5)},GG:function(){return i(this.isoWeekYear()%100,2)},GGGG:function(){return this.isoWeekYear()},GGGGG:function(){return i(this.isoWeekYear(),5)},e:function(){return this.weekday()},E:function(){return this.isoWeekday()},a:function(){return this.lang().meridiem(this.hours(),this.minutes(),!0)},A:function(){return this.lang().meridiem(this.hours(),this.minutes(),!1)},H:function(){return this.hours()},h:function(){return this.hours()%12||12},m:function(){return this.minutes()},s:function(){return this.seconds()},S:function(){return q(this.milliseconds()/100)},SS:function(){return i(q(this.milliseconds()/10),2)},SSS:function(){return i(this.milliseconds(),3)},SSSS:function(){return i(this.milliseconds(),3)},Z:function(){var a=-this.zone(),b="+";return 0>a&&(a=-a,b="-"),b+i(q(a/60),2)+":"+i(q(a)%60,2)},ZZ:function(){var a=-this.zone(),b="+";return 0>a&&(a=-a,b="-"),b+i(q(10*a/6),4)},z:function(){return this.zoneAbbr()},zz:function(){return this.zoneName()},X:function(){return this.unix()}},Qb=["months","monthsShort","weekdays","weekdaysShort","weekdaysMin"];Nb.length;)cb=Nb.pop(),Pb[cb+"o"]=c(Pb[cb],cb);for(;Ob.length;)cb=Ob.pop(),Pb[cb+cb]=b(Pb[cb],2);for(Pb.DDDD=b(Pb.DDD,3),g(d.prototype,{set:function(a){var b,c;for(c in a)b=a[c],"function"==typeof b?this[c]=b:this["_"+c]=b},_months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),months:function(a){return this._months[a.month()]},_monthsShort:"Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec".split("_"),monthsShort:function(a){return this._monthsShort[a.month()]},monthsParse:function(a){var b,c,d;for(this._monthsParse||(this._monthsParse=[]),b=0;12>b;b++)if(this._monthsParse[b]||(c=bb.utc([2e3,b]),d="^"+this.months(c,"")+"|^"+this.monthsShort(c,""),this._monthsParse[b]=new RegExp(d.replace(".",""),"i")),this._monthsParse[b].test(a))return b},_weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),weekdays:function(a){return this._weekdays[a.day()]},_weekdaysShort:"Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_"),weekdaysShort:function(a){return this._weekdaysShort[a.day()]},_weekdaysMin:"Su_Mo_Tu_We_Th_Fr_Sa".split("_"),weekdaysMin:function(a){return this._weekdaysMin[a.day()]},weekdaysParse:function(a){var b,c,d;for(this._weekdaysParse||(this._weekdaysParse=[]),b=0;7>b;b++)if(this._weekdaysParse[b]||(c=bb([2e3,1]).day(b),d="^"+this.weekdays(c,"")+"|^"+this.weekdaysShort(c,"")+"|^"+this.weekdaysMin(c,""),this._weekdaysParse[b]=new RegExp(d.replace(".",""),"i")),this._weekdaysParse[b].test(a))return b},_longDateFormat:{LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D YYYY",LLL:"MMMM D YYYY LT",LLLL:"dddd, MMMM D YYYY LT"},longDateFormat:function(a){var b=this._longDateFormat[a];return!b&&this._longDateFormat[a.toUpperCase()]&&(b=this._longDateFormat[a.toUpperCase()].replace(/MMMM|MM|DD|dddd/g,function(a){return a.slice(1)}),this._longDateFormat[a]=b),b},isPM:function(a){return"p"===(a+"").toLowerCase().charAt(0)},_meridiemParse:/[ap]\.?m?\.?/i,meridiem:function(a,b,c){return a>11?c?"pm":"PM":c?"am":"AM"},_calendar:{sameDay:"[Today at] LT",nextDay:"[Tomorrow at] LT",nextWeek:"dddd [at] LT",lastDay:"[Yesterday at] LT",lastWeek:"[Last] dddd [at] LT",sameElse:"L"},calendar:function(a,b){var c=this._calendar[a];return"function"==typeof c?c.apply(b):c},_relativeTime:{future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"},relativeTime:function(a,b,c,d){var e=this._relativeTime[c];return"function"==typeof e?e(a,b,c,d):e.replace(/%d/i,a)},pastFuture:function(a,b){var c=this._relativeTime[a>0?"future":"past"];return"function"==typeof c?c(b):c.replace(/%s/i,b)},ordinal:function(a){return this._ordinal.replace("%d",a)},_ordinal:"%d",preparse:function(a){return a},postformat:function(a){return a},week:function(a){return W(a,this._week.dow,this._week.doy).week},_week:{dow:0,doy:6},_invalidDate:"Invalid date",invalidDate:function(){return this._invalidDate}}),bb=function(b,c,d,e){return"boolean"==typeof d&&(e=d,d=a),Y({_i:b,_f:c,_l:d,_strict:e,_isUTC:!1})},bb.utc=function(b,c,d,e){var f;return"boolean"==typeof d&&(e=d,d=a),f=Y({_useUTC:!0,_isUTC:!0,_l:d,_i:b,_f:c,_strict:e}).utc()},bb.unix=function(a){return bb(1e3*a)},bb.duration=function(a,b){var c,d,e,g=bb.isDuration(a),h="number"==typeof a,i=g?a._input:h?{}:a,j=null;return h?b?i[b]=a:i.milliseconds=a:(j=pb.exec(a))?(c="-"===j[1]?-1:1,i={y:0,d:q(j[hb])*c,h:q(j[ib])*c,m:q(j[jb])*c,s:q(j[kb])*c,ms:q(j[lb])*c}):(j=qb.exec(a))&&(c="-"===j[1]?-1:1,e=function(a){var b=a&&parseFloat(a.replace(",","."));return(isNaN(b)?0:b)*c},i={y:e(j[2]),M:e(j[3]),d:e(j[4]),h:e(j[5]),m:e(j[6]),s:e(j[7]),w:e(j[8])}),d=new f(i),g&&a.hasOwnProperty("_lang")&&(d._lang=a._lang),d},bb.version=db,bb.defaultFormat=Eb,bb.updateOffset=function(){},bb.lang=function(a,b){var c;return a?(b?y(x(a),b):null===b?(z(a),a="en"):mb[a]||A(a),c=bb.duration.fn._lang=bb.fn._lang=A(a),c._abbr):bb.fn._lang._abbr},bb.langData=function(a){return a&&a._lang&&a._lang._abbr&&(a=a._lang._abbr),A(a)},bb.isMoment=function(a){return a instanceof e},bb.isDuration=function(a){return a instanceof f},cb=Qb.length-1;cb>=0;--cb)p(Qb[cb]);for(bb.normalizeUnits=function(a){return n(a)},bb.invalid=function(a){var b=bb.utc(0/0);return null!=a?g(b._pf,a):b._pf.userInvalidated=!0,b},bb.parseZone=function(a){return bb(a).parseZone()},g(bb.fn=e.prototype,{clone:function(){return bb(this)},valueOf:function(){return+this._d+6e4*(this._offset||0)},unix:function(){return Math.floor(+this/1e3)},toString:function(){return this.clone().lang("en").format("ddd MMM DD YYYY HH:mm:ss [GMT]ZZ")},toDate:function(){return this._offset?new Date(+this):this._d},toISOString:function(){return D(bb(this).utc(),"YYYY-MM-DD[T]HH:mm:ss.SSS[Z]")},toArray:function(){var a=this;return[a.year(),a.month(),a.date(),a.hours(),a.minutes(),a.seconds(),a.milliseconds()]},isValid:function(){return w(this)},isDSTShifted:function(){return this._a?this.isValid()&&m(this._a,(this._isUTC?bb.utc(this._a):bb(this._a)).toArray())>0:!1},parsingFlags:function(){return g({},this._pf)},invalidAt:function(){return this._pf.overflow},utc:function(){return this.zone(0)},local:function(){return this.zone(0),this._isUTC=!1,this},format:function(a){var b=D(this,a||bb.defaultFormat);return this.lang().postformat(b)},add:function(a,b){var c;return c="string"==typeof a?bb.duration(+b,a):bb.duration(a,b),j(this,c,1),this},subtract:function(a,b){var c;return c="string"==typeof a?bb.duration(+b,a):bb.duration(a,b),j(this,c,-1),this},diff:function(a,b,c){var d,e,f=this._isUTC?bb(a).zone(this._offset||0):bb(a).local(),g=6e4*(this.zone()-f.zone());return b=n(b),"year"===b||"month"===b?(d=432e5*(this.daysInMonth()+f.daysInMonth()),e=12*(this.year()-f.year())+(this.month()-f.month()),e+=(this-bb(this).startOf("month")-(f-bb(f).startOf("month")))/d,e-=6e4*(this.zone()-bb(this).startOf("month").zone()-(f.zone()-bb(f).startOf("month").zone()))/d,"year"===b&&(e/=12)):(d=this-f,e="second"===b?d/1e3:"minute"===b?d/6e4:"hour"===b?d/36e5:"day"===b?(d-g)/864e5:"week"===b?(d-g)/6048e5:d),c?e:h(e)},from:function(a,b){return bb.duration(this.diff(a)).lang(this.lang()._abbr).humanize(!b)},fromNow:function(a){return this.from(bb(),a)},calendar:function(){var a=this.diff(bb().zone(this.zone()).startOf("day"),"days",!0),b=-6>a?"sameElse":-1>a?"lastWeek":0>a?"lastDay":1>a?"sameDay":2>a?"nextDay":7>a?"nextWeek":"sameElse";return this.format(this.lang().calendar(b,this))},isLeapYear:function(){return t(this.year())},isDST:function(){return this.zone()<this.clone().month(0).zone()||this.zone()<this.clone().month(5).zone()},day:function(a){var b=this._isUTC?this._d.getUTCDay():this._d.getDay();return null!=a?(a=T(a,this.lang()),this.add({d:a-b})):b},month:function(a){var b,c=this._isUTC?"UTC":"";return null!=a?"string"==typeof a&&(a=this.lang().monthsParse(a),"number"!=typeof a)?this:(b=this.date(),this.date(1),this._d["set"+c+"Month"](a),this.date(Math.min(b,this.daysInMonth())),bb.updateOffset(this),this):this._d["get"+c+"Month"]()},startOf:function(a){switch(a=n(a)){case"year":this.month(0);case"month":this.date(1);case"week":case"isoWeek":case"day":this.hours(0);case"hour":this.minutes(0);case"minute":this.seconds(0);case"second":this.milliseconds(0)}return"week"===a?this.weekday(0):"isoWeek"===a&&this.isoWeekday(1),this},endOf:function(a){return a=n(a),this.startOf(a).add("isoWeek"===a?"week":a,1).subtract("ms",1)},isAfter:function(a,b){return b="undefined"!=typeof b?b:"millisecond",+this.clone().startOf(b)>+bb(a).startOf(b)},isBefore:function(a,b){return b="undefined"!=typeof b?b:"millisecond",+this.clone().startOf(b)<+bb(a).startOf(b)},isSame:function(a,b){return b="undefined"!=typeof b?b:"millisecond",+this.clone().startOf(b)===+bb(a).startOf(b)},min:function(a){return a=bb.apply(null,arguments),this>a?this:a},max:function(a){return a=bb.apply(null,arguments),a>this?this:a},zone:function(a){var b=this._offset||0;return null==a?this._isUTC?b:this._d.getTimezoneOffset():("string"==typeof a&&(a=G(a)),Math.abs(a)<16&&(a=60*a),this._offset=a,this._isUTC=!0,b!==a&&j(this,bb.duration(b-a,"m"),1,!0),this)},zoneAbbr:function(){return this._isUTC?"UTC":""},zoneName:function(){return this._isUTC?"Coordinated Universal Time":""},parseZone:function(){return"string"==typeof this._i&&this.zone(this._i),this},hasAlignedHourOffset:function(a){return a=a?bb(a).zone():0,0===(this.zone()-a)%60},daysInMonth:function(){return r(this.year(),this.month())},dayOfYear:function(a){var b=eb((bb(this).startOf("day")-bb(this).startOf("year"))/864e5)+1;return null==a?b:this.add("d",a-b)},weekYear:function(a){var b=W(this,this.lang()._week.dow,this.lang()._week.doy).year;return null==a?b:this.add("y",a-b)},isoWeekYear:function(a){var b=W(this,1,4).year;return null==a?b:this.add("y",a-b)},week:function(a){var b=this.lang().week(this);return null==a?b:this.add("d",7*(a-b))},isoWeek:function(a){var b=W(this,1,4).week;return null==a?b:this.add("d",7*(a-b))},weekday:function(a){var b=(this.day()+7-this.lang()._week.dow)%7;return null==a?b:this.add("d",a-b)},isoWeekday:function(a){return null==a?this.day()||7:this.day(this.day()%7?a:a-7)},get:function(a){return a=n(a),this[a]()},set:function(a,b){return a=n(a),"function"==typeof this[a]&&this[a](b),this},lang:function(b){return b===a?this._lang:(this._lang=A(b),this)}}),cb=0;cb<Ib.length;cb++)Z(Ib[cb].toLowerCase().replace(/s$/,""),Ib[cb]);Z("year","FullYear"),bb.fn.days=bb.fn.day,bb.fn.months=bb.fn.month,bb.fn.weeks=bb.fn.week,bb.fn.isoWeeks=bb.fn.isoWeek,bb.fn.toJSON=bb.fn.toISOString,g(bb.duration.fn=f.prototype,{_bubble:function(){var a,b,c,d,e=this._milliseconds,f=this._days,g=this._months,i=this._data;i.milliseconds=e%1e3,a=h(e/1e3),i.seconds=a%60,b=h(a/60),i.minutes=b%60,c=h(b/60),i.hours=c%24,f+=h(c/24),i.days=f%30,g+=h(f/30),i.months=g%12,d=h(g/12),i.years=d},weeks:function(){return h(this.days()/7)},valueOf:function(){return this._milliseconds+864e5*this._days+2592e6*(this._months%12)+31536e6*q(this._months/12)},humanize:function(a){var b=+this,c=V(b,!a,this.lang());return a&&(c=this.lang().pastFuture(b,c)),this.lang().postformat(c)},add:function(a,b){var c=bb.duration(a,b);return this._milliseconds+=c._milliseconds,this._days+=c._days,this._months+=c._months,this._bubble(),this},subtract:function(a,b){var c=bb.duration(a,b);return this._milliseconds-=c._milliseconds,this._days-=c._days,this._months-=c._months,this._bubble(),this},get:function(a){return a=n(a),this[a.toLowerCase()+"s"]()},as:function(a){return a=n(a),this["as"+a.charAt(0).toUpperCase()+a.slice(1)+"s"]()},lang:bb.fn.lang,toIsoString:function(){var a=Math.abs(this.years()),b=Math.abs(this.months()),c=Math.abs(this.days()),d=Math.abs(this.hours()),e=Math.abs(this.minutes()),f=Math.abs(this.seconds()+this.milliseconds()/1e3);return this.asSeconds()?(this.asSeconds()<0?"-":"")+"P"+(a?a+"Y":"")+(b?b+"M":"")+(c?c+"D":"")+(d||e||f?"T":"")+(d?d+"H":"")+(e?e+"M":"")+(f?f+"S":""):"P0D"}});for(cb in Jb)Jb.hasOwnProperty(cb)&&(_(cb,Jb[cb]),$(cb.toLowerCase()));_("Weeks",6048e5),bb.duration.fn.asMonths=function(){return(+this-31536e6*this.years())/2592e6+12*this.years()},bb.lang("en",{ordinal:function(a){var b=a%10,c=1===q(a%100/10)?"th":1===b?"st":2===b?"nd":3===b?"rd":"th";return a+c}}),nb?(module.exports=bb,ab(!0)):"function"==typeof define&&define.amd?define("moment",function(b,c,d){return d.config().noGlobal!==!0&&ab(d.config().noGlobal===a),bb}):ab()}).call(this);
@@ -0,0 +1,3448 @@
1
+ /*
2
+ Copyright 2012 Igor Vaynberg
3
+
4
+ Version: 3.4.8 Timestamp: Thu May 1 09:50:32 EDT 2014
5
+
6
+ This software is licensed under the Apache License, Version 2.0 (the "Apache License") or the GNU
7
+ General Public License version 2 (the "GPL License"). You may choose either license to govern your
8
+ use of this software only upon the condition that you accept all of the terms of either the Apache
9
+ License or the GPL License.
10
+
11
+ You may obtain a copy of the Apache License and the GPL License at:
12
+
13
+ http://www.apache.org/licenses/LICENSE-2.0
14
+ http://www.gnu.org/licenses/gpl-2.0.html
15
+
16
+ Unless required by applicable law or agreed to in writing, software distributed under the
17
+ Apache License or the GPL License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
18
+ CONDITIONS OF ANY KIND, either express or implied. See the Apache License and the GPL License for
19
+ the specific language governing permissions and limitations under the Apache License and the GPL License.
20
+ */
21
+ (function ($) {
22
+ if(typeof $.fn.each2 == "undefined") {
23
+ $.extend($.fn, {
24
+ /*
25
+ * 4-10 times faster .each replacement
26
+ * use it carefully, as it overrides jQuery context of element on each iteration
27
+ */
28
+ each2 : function (c) {
29
+ var j = $([0]), i = -1, l = this.length;
30
+ while (
31
+ ++i < l
32
+ && (j.context = j[0] = this[i])
33
+ && c.call(j[0], i, j) !== false //"this"=DOM, i=index, j=jQuery object
34
+ );
35
+ return this;
36
+ }
37
+ });
38
+ }
39
+ })(jQuery);
40
+
41
+ (function ($, undefined) {
42
+ "use strict";
43
+ /*global document, window, jQuery, console */
44
+
45
+ if (window.Select2 !== undefined) {
46
+ return;
47
+ }
48
+
49
+ var KEY, AbstractSelect2, SingleSelect2, MultiSelect2, nextUid, sizer,
50
+ lastMousePosition={x:0,y:0}, $document, scrollBarDimensions,
51
+
52
+ KEY = {
53
+ TAB: 9,
54
+ ENTER: 13,
55
+ ESC: 27,
56
+ SPACE: 32,
57
+ LEFT: 37,
58
+ UP: 38,
59
+ RIGHT: 39,
60
+ DOWN: 40,
61
+ SHIFT: 16,
62
+ CTRL: 17,
63
+ ALT: 18,
64
+ PAGE_UP: 33,
65
+ PAGE_DOWN: 34,
66
+ HOME: 36,
67
+ END: 35,
68
+ BACKSPACE: 8,
69
+ DELETE: 46,
70
+ isArrow: function (k) {
71
+ k = k.which ? k.which : k;
72
+ switch (k) {
73
+ case KEY.LEFT:
74
+ case KEY.RIGHT:
75
+ case KEY.UP:
76
+ case KEY.DOWN:
77
+ return true;
78
+ }
79
+ return false;
80
+ },
81
+ isControl: function (e) {
82
+ var k = e.which;
83
+ switch (k) {
84
+ case KEY.SHIFT:
85
+ case KEY.CTRL:
86
+ case KEY.ALT:
87
+ return true;
88
+ }
89
+
90
+ if (e.metaKey) return true;
91
+
92
+ return false;
93
+ },
94
+ isFunctionKey: function (k) {
95
+ k = k.which ? k.which : k;
96
+ return k >= 112 && k <= 123;
97
+ }
98
+ },
99
+ MEASURE_SCROLLBAR_TEMPLATE = "<div class='select2-measure-scrollbar'></div>",
100
+
101
+ DIACRITICS = {"\u24B6":"A","\uFF21":"A","\u00C0":"A","\u00C1":"A","\u00C2":"A","\u1EA6":"A","\u1EA4":"A","\u1EAA":"A","\u1EA8":"A","\u00C3":"A","\u0100":"A","\u0102":"A","\u1EB0":"A","\u1EAE":"A","\u1EB4":"A","\u1EB2":"A","\u0226":"A","\u01E0":"A","\u00C4":"A","\u01DE":"A","\u1EA2":"A","\u00C5":"A","\u01FA":"A","\u01CD":"A","\u0200":"A","\u0202":"A","\u1EA0":"A","\u1EAC":"A","\u1EB6":"A","\u1E00":"A","\u0104":"A","\u023A":"A","\u2C6F":"A","\uA732":"AA","\u00C6":"AE","\u01FC":"AE","\u01E2":"AE","\uA734":"AO","\uA736":"AU","\uA738":"AV","\uA73A":"AV","\uA73C":"AY","\u24B7":"B","\uFF22":"B","\u1E02":"B","\u1E04":"B","\u1E06":"B","\u0243":"B","\u0182":"B","\u0181":"B","\u24B8":"C","\uFF23":"C","\u0106":"C","\u0108":"C","\u010A":"C","\u010C":"C","\u00C7":"C","\u1E08":"C","\u0187":"C","\u023B":"C","\uA73E":"C","\u24B9":"D","\uFF24":"D","\u1E0A":"D","\u010E":"D","\u1E0C":"D","\u1E10":"D","\u1E12":"D","\u1E0E":"D","\u0110":"D","\u018B":"D","\u018A":"D","\u0189":"D","\uA779":"D","\u01F1":"DZ","\u01C4":"DZ","\u01F2":"Dz","\u01C5":"Dz","\u24BA":"E","\uFF25":"E","\u00C8":"E","\u00C9":"E","\u00CA":"E","\u1EC0":"E","\u1EBE":"E","\u1EC4":"E","\u1EC2":"E","\u1EBC":"E","\u0112":"E","\u1E14":"E","\u1E16":"E","\u0114":"E","\u0116":"E","\u00CB":"E","\u1EBA":"E","\u011A":"E","\u0204":"E","\u0206":"E","\u1EB8":"E","\u1EC6":"E","\u0228":"E","\u1E1C":"E","\u0118":"E","\u1E18":"E","\u1E1A":"E","\u0190":"E","\u018E":"E","\u24BB":"F","\uFF26":"F","\u1E1E":"F","\u0191":"F","\uA77B":"F","\u24BC":"G","\uFF27":"G","\u01F4":"G","\u011C":"G","\u1E20":"G","\u011E":"G","\u0120":"G","\u01E6":"G","\u0122":"G","\u01E4":"G","\u0193":"G","\uA7A0":"G","\uA77D":"G","\uA77E":"G","\u24BD":"H","\uFF28":"H","\u0124":"H","\u1E22":"H","\u1E26":"H","\u021E":"H","\u1E24":"H","\u1E28":"H","\u1E2A":"H","\u0126":"H","\u2C67":"H","\u2C75":"H","\uA78D":"H","\u24BE":"I","\uFF29":"I","\u00CC":"I","\u00CD":"I","\u00CE":"I","\u0128":"I","\u012A":"I","\u012C":"I","\u0130":"I","\u00CF":"I","\u1E2E":"I","\u1EC8":"I","\u01CF":"I","\u0208":"I","\u020A":"I","\u1ECA":"I","\u012E":"I","\u1E2C":"I","\u0197":"I","\u24BF":"J","\uFF2A":"J","\u0134":"J","\u0248":"J","\u24C0":"K","\uFF2B":"K","\u1E30":"K","\u01E8":"K","\u1E32":"K","\u0136":"K","\u1E34":"K","\u0198":"K","\u2C69":"K","\uA740":"K","\uA742":"K","\uA744":"K","\uA7A2":"K","\u24C1":"L","\uFF2C":"L","\u013F":"L","\u0139":"L","\u013D":"L","\u1E36":"L","\u1E38":"L","\u013B":"L","\u1E3C":"L","\u1E3A":"L","\u0141":"L","\u023D":"L","\u2C62":"L","\u2C60":"L","\uA748":"L","\uA746":"L","\uA780":"L","\u01C7":"LJ","\u01C8":"Lj","\u24C2":"M","\uFF2D":"M","\u1E3E":"M","\u1E40":"M","\u1E42":"M","\u2C6E":"M","\u019C":"M","\u24C3":"N","\uFF2E":"N","\u01F8":"N","\u0143":"N","\u00D1":"N","\u1E44":"N","\u0147":"N","\u1E46":"N","\u0145":"N","\u1E4A":"N","\u1E48":"N","\u0220":"N","\u019D":"N","\uA790":"N","\uA7A4":"N","\u01CA":"NJ","\u01CB":"Nj","\u24C4":"O","\uFF2F":"O","\u00D2":"O","\u00D3":"O","\u00D4":"O","\u1ED2":"O","\u1ED0":"O","\u1ED6":"O","\u1ED4":"O","\u00D5":"O","\u1E4C":"O","\u022C":"O","\u1E4E":"O","\u014C":"O","\u1E50":"O","\u1E52":"O","\u014E":"O","\u022E":"O","\u0230":"O","\u00D6":"O","\u022A":"O","\u1ECE":"O","\u0150":"O","\u01D1":"O","\u020C":"O","\u020E":"O","\u01A0":"O","\u1EDC":"O","\u1EDA":"O","\u1EE0":"O","\u1EDE":"O","\u1EE2":"O","\u1ECC":"O","\u1ED8":"O","\u01EA":"O","\u01EC":"O","\u00D8":"O","\u01FE":"O","\u0186":"O","\u019F":"O","\uA74A":"O","\uA74C":"O","\u01A2":"OI","\uA74E":"OO","\u0222":"OU","\u24C5":"P","\uFF30":"P","\u1E54":"P","\u1E56":"P","\u01A4":"P","\u2C63":"P","\uA750":"P","\uA752":"P","\uA754":"P","\u24C6":"Q","\uFF31":"Q","\uA756":"Q","\uA758":"Q","\u024A":"Q","\u24C7":"R","\uFF32":"R","\u0154":"R","\u1E58":"R","\u0158":"R","\u0210":"R","\u0212":"R","\u1E5A":"R","\u1E5C":"R","\u0156":"R","\u1E5E":"R","\u024C":"R","\u2C64":"R","\uA75A":"R","\uA7A6":"R","\uA782":"R","\u24C8":"S","\uFF33":"S","\u1E9E":"S","\u015A":"S","\u1E64":"S","\u015C":"S","\u1E60":"S","\u0160":"S","\u1E66":"S","\u1E62":"S","\u1E68":"S","\u0218":"S","\u015E":"S","\u2C7E":"S","\uA7A8":"S","\uA784":"S","\u24C9":"T","\uFF34":"T","\u1E6A":"T","\u0164":"T","\u1E6C":"T","\u021A":"T","\u0162":"T","\u1E70":"T","\u1E6E":"T","\u0166":"T","\u01AC":"T","\u01AE":"T","\u023E":"T","\uA786":"T","\uA728":"TZ","\u24CA":"U","\uFF35":"U","\u00D9":"U","\u00DA":"U","\u00DB":"U","\u0168":"U","\u1E78":"U","\u016A":"U","\u1E7A":"U","\u016C":"U","\u00DC":"U","\u01DB":"U","\u01D7":"U","\u01D5":"U","\u01D9":"U","\u1EE6":"U","\u016E":"U","\u0170":"U","\u01D3":"U","\u0214":"U","\u0216":"U","\u01AF":"U","\u1EEA":"U","\u1EE8":"U","\u1EEE":"U","\u1EEC":"U","\u1EF0":"U","\u1EE4":"U","\u1E72":"U","\u0172":"U","\u1E76":"U","\u1E74":"U","\u0244":"U","\u24CB":"V","\uFF36":"V","\u1E7C":"V","\u1E7E":"V","\u01B2":"V","\uA75E":"V","\u0245":"V","\uA760":"VY","\u24CC":"W","\uFF37":"W","\u1E80":"W","\u1E82":"W","\u0174":"W","\u1E86":"W","\u1E84":"W","\u1E88":"W","\u2C72":"W","\u24CD":"X","\uFF38":"X","\u1E8A":"X","\u1E8C":"X","\u24CE":"Y","\uFF39":"Y","\u1EF2":"Y","\u00DD":"Y","\u0176":"Y","\u1EF8":"Y","\u0232":"Y","\u1E8E":"Y","\u0178":"Y","\u1EF6":"Y","\u1EF4":"Y","\u01B3":"Y","\u024E":"Y","\u1EFE":"Y","\u24CF":"Z","\uFF3A":"Z","\u0179":"Z","\u1E90":"Z","\u017B":"Z","\u017D":"Z","\u1E92":"Z","\u1E94":"Z","\u01B5":"Z","\u0224":"Z","\u2C7F":"Z","\u2C6B":"Z","\uA762":"Z","\u24D0":"a","\uFF41":"a","\u1E9A":"a","\u00E0":"a","\u00E1":"a","\u00E2":"a","\u1EA7":"a","\u1EA5":"a","\u1EAB":"a","\u1EA9":"a","\u00E3":"a","\u0101":"a","\u0103":"a","\u1EB1":"a","\u1EAF":"a","\u1EB5":"a","\u1EB3":"a","\u0227":"a","\u01E1":"a","\u00E4":"a","\u01DF":"a","\u1EA3":"a","\u00E5":"a","\u01FB":"a","\u01CE":"a","\u0201":"a","\u0203":"a","\u1EA1":"a","\u1EAD":"a","\u1EB7":"a","\u1E01":"a","\u0105":"a","\u2C65":"a","\u0250":"a","\uA733":"aa","\u00E6":"ae","\u01FD":"ae","\u01E3":"ae","\uA735":"ao","\uA737":"au","\uA739":"av","\uA73B":"av","\uA73D":"ay","\u24D1":"b","\uFF42":"b","\u1E03":"b","\u1E05":"b","\u1E07":"b","\u0180":"b","\u0183":"b","\u0253":"b","\u24D2":"c","\uFF43":"c","\u0107":"c","\u0109":"c","\u010B":"c","\u010D":"c","\u00E7":"c","\u1E09":"c","\u0188":"c","\u023C":"c","\uA73F":"c","\u2184":"c","\u24D3":"d","\uFF44":"d","\u1E0B":"d","\u010F":"d","\u1E0D":"d","\u1E11":"d","\u1E13":"d","\u1E0F":"d","\u0111":"d","\u018C":"d","\u0256":"d","\u0257":"d","\uA77A":"d","\u01F3":"dz","\u01C6":"dz","\u24D4":"e","\uFF45":"e","\u00E8":"e","\u00E9":"e","\u00EA":"e","\u1EC1":"e","\u1EBF":"e","\u1EC5":"e","\u1EC3":"e","\u1EBD":"e","\u0113":"e","\u1E15":"e","\u1E17":"e","\u0115":"e","\u0117":"e","\u00EB":"e","\u1EBB":"e","\u011B":"e","\u0205":"e","\u0207":"e","\u1EB9":"e","\u1EC7":"e","\u0229":"e","\u1E1D":"e","\u0119":"e","\u1E19":"e","\u1E1B":"e","\u0247":"e","\u025B":"e","\u01DD":"e","\u24D5":"f","\uFF46":"f","\u1E1F":"f","\u0192":"f","\uA77C":"f","\u24D6":"g","\uFF47":"g","\u01F5":"g","\u011D":"g","\u1E21":"g","\u011F":"g","\u0121":"g","\u01E7":"g","\u0123":"g","\u01E5":"g","\u0260":"g","\uA7A1":"g","\u1D79":"g","\uA77F":"g","\u24D7":"h","\uFF48":"h","\u0125":"h","\u1E23":"h","\u1E27":"h","\u021F":"h","\u1E25":"h","\u1E29":"h","\u1E2B":"h","\u1E96":"h","\u0127":"h","\u2C68":"h","\u2C76":"h","\u0265":"h","\u0195":"hv","\u24D8":"i","\uFF49":"i","\u00EC":"i","\u00ED":"i","\u00EE":"i","\u0129":"i","\u012B":"i","\u012D":"i","\u00EF":"i","\u1E2F":"i","\u1EC9":"i","\u01D0":"i","\u0209":"i","\u020B":"i","\u1ECB":"i","\u012F":"i","\u1E2D":"i","\u0268":"i","\u0131":"i","\u24D9":"j","\uFF4A":"j","\u0135":"j","\u01F0":"j","\u0249":"j","\u24DA":"k","\uFF4B":"k","\u1E31":"k","\u01E9":"k","\u1E33":"k","\u0137":"k","\u1E35":"k","\u0199":"k","\u2C6A":"k","\uA741":"k","\uA743":"k","\uA745":"k","\uA7A3":"k","\u24DB":"l","\uFF4C":"l","\u0140":"l","\u013A":"l","\u013E":"l","\u1E37":"l","\u1E39":"l","\u013C":"l","\u1E3D":"l","\u1E3B":"l","\u017F":"l","\u0142":"l","\u019A":"l","\u026B":"l","\u2C61":"l","\uA749":"l","\uA781":"l","\uA747":"l","\u01C9":"lj","\u24DC":"m","\uFF4D":"m","\u1E3F":"m","\u1E41":"m","\u1E43":"m","\u0271":"m","\u026F":"m","\u24DD":"n","\uFF4E":"n","\u01F9":"n","\u0144":"n","\u00F1":"n","\u1E45":"n","\u0148":"n","\u1E47":"n","\u0146":"n","\u1E4B":"n","\u1E49":"n","\u019E":"n","\u0272":"n","\u0149":"n","\uA791":"n","\uA7A5":"n","\u01CC":"nj","\u24DE":"o","\uFF4F":"o","\u00F2":"o","\u00F3":"o","\u00F4":"o","\u1ED3":"o","\u1ED1":"o","\u1ED7":"o","\u1ED5":"o","\u00F5":"o","\u1E4D":"o","\u022D":"o","\u1E4F":"o","\u014D":"o","\u1E51":"o","\u1E53":"o","\u014F":"o","\u022F":"o","\u0231":"o","\u00F6":"o","\u022B":"o","\u1ECF":"o","\u0151":"o","\u01D2":"o","\u020D":"o","\u020F":"o","\u01A1":"o","\u1EDD":"o","\u1EDB":"o","\u1EE1":"o","\u1EDF":"o","\u1EE3":"o","\u1ECD":"o","\u1ED9":"o","\u01EB":"o","\u01ED":"o","\u00F8":"o","\u01FF":"o","\u0254":"o","\uA74B":"o","\uA74D":"o","\u0275":"o","\u01A3":"oi","\u0223":"ou","\uA74F":"oo","\u24DF":"p","\uFF50":"p","\u1E55":"p","\u1E57":"p","\u01A5":"p","\u1D7D":"p","\uA751":"p","\uA753":"p","\uA755":"p","\u24E0":"q","\uFF51":"q","\u024B":"q","\uA757":"q","\uA759":"q","\u24E1":"r","\uFF52":"r","\u0155":"r","\u1E59":"r","\u0159":"r","\u0211":"r","\u0213":"r","\u1E5B":"r","\u1E5D":"r","\u0157":"r","\u1E5F":"r","\u024D":"r","\u027D":"r","\uA75B":"r","\uA7A7":"r","\uA783":"r","\u24E2":"s","\uFF53":"s","\u00DF":"s","\u015B":"s","\u1E65":"s","\u015D":"s","\u1E61":"s","\u0161":"s","\u1E67":"s","\u1E63":"s","\u1E69":"s","\u0219":"s","\u015F":"s","\u023F":"s","\uA7A9":"s","\uA785":"s","\u1E9B":"s","\u24E3":"t","\uFF54":"t","\u1E6B":"t","\u1E97":"t","\u0165":"t","\u1E6D":"t","\u021B":"t","\u0163":"t","\u1E71":"t","\u1E6F":"t","\u0167":"t","\u01AD":"t","\u0288":"t","\u2C66":"t","\uA787":"t","\uA729":"tz","\u24E4":"u","\uFF55":"u","\u00F9":"u","\u00FA":"u","\u00FB":"u","\u0169":"u","\u1E79":"u","\u016B":"u","\u1E7B":"u","\u016D":"u","\u00FC":"u","\u01DC":"u","\u01D8":"u","\u01D6":"u","\u01DA":"u","\u1EE7":"u","\u016F":"u","\u0171":"u","\u01D4":"u","\u0215":"u","\u0217":"u","\u01B0":"u","\u1EEB":"u","\u1EE9":"u","\u1EEF":"u","\u1EED":"u","\u1EF1":"u","\u1EE5":"u","\u1E73":"u","\u0173":"u","\u1E77":"u","\u1E75":"u","\u0289":"u","\u24E5":"v","\uFF56":"v","\u1E7D":"v","\u1E7F":"v","\u028B":"v","\uA75F":"v","\u028C":"v","\uA761":"vy","\u24E6":"w","\uFF57":"w","\u1E81":"w","\u1E83":"w","\u0175":"w","\u1E87":"w","\u1E85":"w","\u1E98":"w","\u1E89":"w","\u2C73":"w","\u24E7":"x","\uFF58":"x","\u1E8B":"x","\u1E8D":"x","\u24E8":"y","\uFF59":"y","\u1EF3":"y","\u00FD":"y","\u0177":"y","\u1EF9":"y","\u0233":"y","\u1E8F":"y","\u00FF":"y","\u1EF7":"y","\u1E99":"y","\u1EF5":"y","\u01B4":"y","\u024F":"y","\u1EFF":"y","\u24E9":"z","\uFF5A":"z","\u017A":"z","\u1E91":"z","\u017C":"z","\u017E":"z","\u1E93":"z","\u1E95":"z","\u01B6":"z","\u0225":"z","\u0240":"z","\u2C6C":"z","\uA763":"z"};
102
+
103
+ $document = $(document);
104
+
105
+ nextUid=(function() { var counter=1; return function() { return counter++; }; }());
106
+
107
+
108
+ function reinsertElement(element) {
109
+ var placeholder = $(document.createTextNode(''));
110
+
111
+ element.before(placeholder);
112
+ placeholder.before(element);
113
+ placeholder.remove();
114
+ }
115
+
116
+ function stripDiacritics(str) {
117
+ // Used 'uni range + named function' from http://jsperf.com/diacritics/18
118
+ function match(a) {
119
+ return DIACRITICS[a] || a;
120
+ }
121
+
122
+ return str.replace(/[^\u0000-\u007E]/g, match);
123
+ }
124
+
125
+ function indexOf(value, array) {
126
+ var i = 0, l = array.length;
127
+ for (; i < l; i = i + 1) {
128
+ if (equal(value, array[i])) return i;
129
+ }
130
+ return -1;
131
+ }
132
+
133
+ function measureScrollbar () {
134
+ var $template = $( MEASURE_SCROLLBAR_TEMPLATE );
135
+ $template.appendTo('body');
136
+
137
+ var dim = {
138
+ width: $template.width() - $template[0].clientWidth,
139
+ height: $template.height() - $template[0].clientHeight
140
+ };
141
+ $template.remove();
142
+
143
+ return dim;
144
+ }
145
+
146
+ /**
147
+ * Compares equality of a and b
148
+ * @param a
149
+ * @param b
150
+ */
151
+ function equal(a, b) {
152
+ if (a === b) return true;
153
+ if (a === undefined || b === undefined) return false;
154
+ if (a === null || b === null) return false;
155
+ // Check whether 'a' or 'b' is a string (primitive or object).
156
+ // The concatenation of an empty string (+'') converts its argument to a string's primitive.
157
+ if (a.constructor === String) return a+'' === b+''; // a+'' - in case 'a' is a String object
158
+ if (b.constructor === String) return b+'' === a+''; // b+'' - in case 'b' is a String object
159
+ return false;
160
+ }
161
+
162
+ /**
163
+ * Splits the string into an array of values, trimming each value. An empty array is returned for nulls or empty
164
+ * strings
165
+ * @param string
166
+ * @param separator
167
+ */
168
+ function splitVal(string, separator) {
169
+ var val, i, l;
170
+ if (string === null || string.length < 1) return [];
171
+ val = string.split(separator);
172
+ for (i = 0, l = val.length; i < l; i = i + 1) val[i] = $.trim(val[i]);
173
+ return val;
174
+ }
175
+
176
+ function getSideBorderPadding(element) {
177
+ return element.outerWidth(false) - element.width();
178
+ }
179
+
180
+ function installKeyUpChangeEvent(element) {
181
+ var key="keyup-change-value";
182
+ element.on("keydown", function () {
183
+ if ($.data(element, key) === undefined) {
184
+ $.data(element, key, element.val());
185
+ }
186
+ });
187
+ element.on("keyup", function () {
188
+ var val= $.data(element, key);
189
+ if (val !== undefined && element.val() !== val) {
190
+ $.removeData(element, key);
191
+ element.trigger("keyup-change");
192
+ }
193
+ });
194
+ }
195
+
196
+ $document.on("mousemove", function (e) {
197
+ lastMousePosition.x = e.pageX;
198
+ lastMousePosition.y = e.pageY;
199
+ });
200
+
201
+ /**
202
+ * filters mouse events so an event is fired only if the mouse moved.
203
+ *
204
+ * filters out mouse events that occur when mouse is stationary but
205
+ * the elements under the pointer are scrolled.
206
+ */
207
+ function installFilteredMouseMove(element) {
208
+ element.on("mousemove", function (e) {
209
+ var lastpos = lastMousePosition;
210
+ if (lastpos === undefined || lastpos.x !== e.pageX || lastpos.y !== e.pageY) {
211
+ $(e.target).trigger("mousemove-filtered", e);
212
+ }
213
+ });
214
+ }
215
+
216
+ /**
217
+ * Debounces a function. Returns a function that calls the original fn function only if no invocations have been made
218
+ * within the last quietMillis milliseconds.
219
+ *
220
+ * @param quietMillis number of milliseconds to wait before invoking fn
221
+ * @param fn function to be debounced
222
+ * @param ctx object to be used as this reference within fn
223
+ * @return debounced version of fn
224
+ */
225
+ function debounce(quietMillis, fn, ctx) {
226
+ ctx = ctx || undefined;
227
+ var timeout;
228
+ return function () {
229
+ var args = arguments;
230
+ window.clearTimeout(timeout);
231
+ timeout = window.setTimeout(function() {
232
+ fn.apply(ctx, args);
233
+ }, quietMillis);
234
+ };
235
+ }
236
+
237
+ function installDebouncedScroll(threshold, element) {
238
+ var notify = debounce(threshold, function (e) { element.trigger("scroll-debounced", e);});
239
+ element.on("scroll", function (e) {
240
+ if (indexOf(e.target, element.get()) >= 0) notify(e);
241
+ });
242
+ }
243
+
244
+ function focus($el) {
245
+ if ($el[0] === document.activeElement) return;
246
+
247
+ /* set the focus in a 0 timeout - that way the focus is set after the processing
248
+ of the current event has finished - which seems like the only reliable way
249
+ to set focus */
250
+ window.setTimeout(function() {
251
+ var el=$el[0], pos=$el.val().length, range;
252
+
253
+ $el.focus();
254
+
255
+ /* make sure el received focus so we do not error out when trying to manipulate the caret.
256
+ sometimes modals or others listeners may steal it after its set */
257
+ var isVisible = (el.offsetWidth > 0 || el.offsetHeight > 0);
258
+ if (isVisible && el === document.activeElement) {
259
+
260
+ /* after the focus is set move the caret to the end, necessary when we val()
261
+ just before setting focus */
262
+ if(el.setSelectionRange)
263
+ {
264
+ el.setSelectionRange(pos, pos);
265
+ }
266
+ else if (el.createTextRange) {
267
+ range = el.createTextRange();
268
+ range.collapse(false);
269
+ range.select();
270
+ }
271
+ }
272
+ }, 0);
273
+ }
274
+
275
+ function getCursorInfo(el) {
276
+ el = $(el)[0];
277
+ var offset = 0;
278
+ var length = 0;
279
+ if ('selectionStart' in el) {
280
+ offset = el.selectionStart;
281
+ length = el.selectionEnd - offset;
282
+ } else if ('selection' in document) {
283
+ el.focus();
284
+ var sel = document.selection.createRange();
285
+ length = document.selection.createRange().text.length;
286
+ sel.moveStart('character', -el.value.length);
287
+ offset = sel.text.length - length;
288
+ }
289
+ return { offset: offset, length: length };
290
+ }
291
+
292
+ function killEvent(event) {
293
+ event.preventDefault();
294
+ event.stopPropagation();
295
+ }
296
+ function killEventImmediately(event) {
297
+ event.preventDefault();
298
+ event.stopImmediatePropagation();
299
+ }
300
+
301
+ function measureTextWidth(e) {
302
+ if (!sizer){
303
+ var style = e[0].currentStyle || window.getComputedStyle(e[0], null);
304
+ sizer = $(document.createElement("div")).css({
305
+ position: "absolute",
306
+ left: "-10000px",
307
+ top: "-10000px",
308
+ display: "none",
309
+ fontSize: style.fontSize,
310
+ fontFamily: style.fontFamily,
311
+ fontStyle: style.fontStyle,
312
+ fontWeight: style.fontWeight,
313
+ letterSpacing: style.letterSpacing,
314
+ textTransform: style.textTransform,
315
+ whiteSpace: "nowrap"
316
+ });
317
+ sizer.attr("class","select2-sizer");
318
+ $("body").append(sizer);
319
+ }
320
+ sizer.text(e.val());
321
+ return sizer.width();
322
+ }
323
+
324
+ function syncCssClasses(dest, src, adapter) {
325
+ var classes, replacements = [], adapted;
326
+
327
+ classes = dest.attr("class");
328
+ if (classes) {
329
+ classes = '' + classes; // for IE which returns object
330
+ $(classes.split(" ")).each2(function() {
331
+ if (this.indexOf("select2-") === 0) {
332
+ replacements.push(this);
333
+ }
334
+ });
335
+ }
336
+ classes = src.attr("class");
337
+ if (classes) {
338
+ classes = '' + classes; // for IE which returns object
339
+ $(classes.split(" ")).each2(function() {
340
+ if (this.indexOf("select2-") !== 0) {
341
+ adapted = adapter(this);
342
+ if (adapted) {
343
+ replacements.push(adapted);
344
+ }
345
+ }
346
+ });
347
+ }
348
+ dest.attr("class", replacements.join(" "));
349
+ }
350
+
351
+
352
+ function markMatch(text, term, markup, escapeMarkup) {
353
+ var match=stripDiacritics(text.toUpperCase()).indexOf(stripDiacritics(term.toUpperCase())),
354
+ tl=term.length;
355
+
356
+ if (match<0) {
357
+ markup.push(escapeMarkup(text));
358
+ return;
359
+ }
360
+
361
+ markup.push(escapeMarkup(text.substring(0, match)));
362
+ markup.push("<span class='select2-match'>");
363
+ markup.push(escapeMarkup(text.substring(match, match + tl)));
364
+ markup.push("</span>");
365
+ markup.push(escapeMarkup(text.substring(match + tl, text.length)));
366
+ }
367
+
368
+ function defaultEscapeMarkup(markup) {
369
+ var replace_map = {
370
+ '\\': '&#92;',
371
+ '&': '&amp;',
372
+ '<': '&lt;',
373
+ '>': '&gt;',
374
+ '"': '&quot;',
375
+ "'": '&#39;',
376
+ "/": '&#47;'
377
+ };
378
+
379
+ return String(markup).replace(/[&<>"'\/\\]/g, function (match) {
380
+ return replace_map[match];
381
+ });
382
+ }
383
+
384
+ /**
385
+ * Produces an ajax-based query function
386
+ *
387
+ * @param options object containing configuration parameters
388
+ * @param options.params parameter map for the transport ajax call, can contain such options as cache, jsonpCallback, etc. see $.ajax
389
+ * @param options.transport function that will be used to execute the ajax request. must be compatible with parameters supported by $.ajax
390
+ * @param options.url url for the data
391
+ * @param options.data a function(searchTerm, pageNumber, context) that should return an object containing query string parameters for the above url.
392
+ * @param options.dataType request data type: ajax, jsonp, other datatypes supported by jQuery's $.ajax function or the transport function if specified
393
+ * @param options.quietMillis (optional) milliseconds to wait before making the ajaxRequest, helps debounce the ajax function if invoked too often
394
+ * @param options.results a function(remoteData, pageNumber) that converts data returned form the remote request to the format expected by Select2.
395
+ * The expected format is an object containing the following keys:
396
+ * results array of objects that will be used as choices
397
+ * more (optional) boolean indicating whether there are more results available
398
+ * Example: {results:[{id:1, text:'Red'},{id:2, text:'Blue'}], more:true}
399
+ */
400
+ function ajax(options) {
401
+ var timeout, // current scheduled but not yet executed request
402
+ handler = null,
403
+ quietMillis = options.quietMillis || 100,
404
+ ajaxUrl = options.url,
405
+ self = this;
406
+
407
+ return function (query) {
408
+ window.clearTimeout(timeout);
409
+ timeout = window.setTimeout(function () {
410
+ var data = options.data, // ajax data function
411
+ url = ajaxUrl, // ajax url string or function
412
+ transport = options.transport || $.fn.select2.ajaxDefaults.transport,
413
+ // deprecated - to be removed in 4.0 - use params instead
414
+ deprecated = {
415
+ type: options.type || 'GET', // set type of request (GET or POST)
416
+ cache: options.cache || false,
417
+ jsonpCallback: options.jsonpCallback||undefined,
418
+ dataType: options.dataType||"json"
419
+ },
420
+ params = $.extend({}, $.fn.select2.ajaxDefaults.params, deprecated);
421
+
422
+ data = data ? data.call(self, query.term, query.page, query.context) : null;
423
+ url = (typeof url === 'function') ? url.call(self, query.term, query.page, query.context) : url;
424
+
425
+ if (handler && typeof handler.abort === "function") { handler.abort(); }
426
+
427
+ if (options.params) {
428
+ if ($.isFunction(options.params)) {
429
+ $.extend(params, options.params.call(self));
430
+ } else {
431
+ $.extend(params, options.params);
432
+ }
433
+ }
434
+
435
+ $.extend(params, {
436
+ url: url,
437
+ dataType: options.dataType,
438
+ data: data,
439
+ success: function (data) {
440
+ // TODO - replace query.page with query so users have access to term, page, etc.
441
+ var results = options.results(data, query.page);
442
+ query.callback(results);
443
+ }
444
+ });
445
+ handler = transport.call(self, params);
446
+ }, quietMillis);
447
+ };
448
+ }
449
+
450
+ /**
451
+ * Produces a query function that works with a local array
452
+ *
453
+ * @param options object containing configuration parameters. The options parameter can either be an array or an
454
+ * object.
455
+ *
456
+ * If the array form is used it is assumed that it contains objects with 'id' and 'text' keys.
457
+ *
458
+ * If the object form is used it is assumed that it contains 'data' and 'text' keys. The 'data' key should contain
459
+ * an array of objects that will be used as choices. These objects must contain at least an 'id' key. The 'text'
460
+ * key can either be a String in which case it is expected that each element in the 'data' array has a key with the
461
+ * value of 'text' which will be used to match choices. Alternatively, text can be a function(item) that can extract
462
+ * the text.
463
+ */
464
+ function local(options) {
465
+ var data = options, // data elements
466
+ dataText,
467
+ tmp,
468
+ text = function (item) { return ""+item.text; }; // function used to retrieve the text portion of a data item that is matched against the search
469
+
470
+ if ($.isArray(data)) {
471
+ tmp = data;
472
+ data = { results: tmp };
473
+ }
474
+
475
+ if ($.isFunction(data) === false) {
476
+ tmp = data;
477
+ data = function() { return tmp; };
478
+ }
479
+
480
+ var dataItem = data();
481
+ if (dataItem.text) {
482
+ text = dataItem.text;
483
+ // if text is not a function we assume it to be a key name
484
+ if (!$.isFunction(text)) {
485
+ dataText = dataItem.text; // we need to store this in a separate variable because in the next step data gets reset and data.text is no longer available
486
+ text = function (item) { return item[dataText]; };
487
+ }
488
+ }
489
+
490
+ return function (query) {
491
+ var t = query.term, filtered = { results: [] }, process;
492
+ if (t === "") {
493
+ query.callback(data());
494
+ return;
495
+ }
496
+
497
+ process = function(datum, collection) {
498
+ var group, attr;
499
+ datum = datum[0];
500
+ if (datum.children) {
501
+ group = {};
502
+ for (attr in datum) {
503
+ if (datum.hasOwnProperty(attr)) group[attr]=datum[attr];
504
+ }
505
+ group.children=[];
506
+ $(datum.children).each2(function(i, childDatum) { process(childDatum, group.children); });
507
+ if (group.children.length || query.matcher(t, text(group), datum)) {
508
+ collection.push(group);
509
+ }
510
+ } else {
511
+ if (query.matcher(t, text(datum), datum)) {
512
+ collection.push(datum);
513
+ }
514
+ }
515
+ };
516
+
517
+ $(data().results).each2(function(i, datum) { process(datum, filtered.results); });
518
+ query.callback(filtered);
519
+ };
520
+ }
521
+
522
+ // TODO javadoc
523
+ function tags(data) {
524
+ var isFunc = $.isFunction(data);
525
+ return function (query) {
526
+ var t = query.term, filtered = {results: []};
527
+ var result = isFunc ? data(query) : data;
528
+ if ($.isArray(result)) {
529
+ $(result).each(function () {
530
+ var isObject = this.text !== undefined,
531
+ text = isObject ? this.text : this;
532
+ if (t === "" || query.matcher(t, text)) {
533
+ filtered.results.push(isObject ? this : {id: this, text: this});
534
+ }
535
+ });
536
+ query.callback(filtered);
537
+ }
538
+ };
539
+ }
540
+
541
+ /**
542
+ * Checks if the formatter function should be used.
543
+ *
544
+ * Throws an error if it is not a function. Returns true if it should be used,
545
+ * false if no formatting should be performed.
546
+ *
547
+ * @param formatter
548
+ */
549
+ function checkFormatter(formatter, formatterName) {
550
+ if ($.isFunction(formatter)) return true;
551
+ if (!formatter) return false;
552
+ if (typeof(formatter) === 'string') return true;
553
+ throw new Error(formatterName +" must be a string, function, or falsy value");
554
+ }
555
+
556
+ function evaluate(val) {
557
+ if ($.isFunction(val)) {
558
+ var args = Array.prototype.slice.call(arguments, 1);
559
+ return val.apply(null, args);
560
+ }
561
+ return val;
562
+ }
563
+
564
+ function countResults(results) {
565
+ var count = 0;
566
+ $.each(results, function(i, item) {
567
+ if (item.children) {
568
+ count += countResults(item.children);
569
+ } else {
570
+ count++;
571
+ }
572
+ });
573
+ return count;
574
+ }
575
+
576
+ /**
577
+ * Default tokenizer. This function uses breaks the input on substring match of any string from the
578
+ * opts.tokenSeparators array and uses opts.createSearchChoice to create the choice object. Both of those
579
+ * two options have to be defined in order for the tokenizer to work.
580
+ *
581
+ * @param input text user has typed so far or pasted into the search field
582
+ * @param selection currently selected choices
583
+ * @param selectCallback function(choice) callback tho add the choice to selection
584
+ * @param opts select2's opts
585
+ * @return undefined/null to leave the current input unchanged, or a string to change the input to the returned value
586
+ */
587
+ function defaultTokenizer(input, selection, selectCallback, opts) {
588
+ var original = input, // store the original so we can compare and know if we need to tell the search to update its text
589
+ dupe = false, // check for whether a token we extracted represents a duplicate selected choice
590
+ token, // token
591
+ index, // position at which the separator was found
592
+ i, l, // looping variables
593
+ separator; // the matched separator
594
+
595
+ if (!opts.createSearchChoice || !opts.tokenSeparators || opts.tokenSeparators.length < 1) return undefined;
596
+
597
+ while (true) {
598
+ index = -1;
599
+
600
+ for (i = 0, l = opts.tokenSeparators.length; i < l; i++) {
601
+ separator = opts.tokenSeparators[i];
602
+ index = input.indexOf(separator);
603
+ if (index >= 0) break;
604
+ }
605
+
606
+ if (index < 0) break; // did not find any token separator in the input string, bail
607
+
608
+ token = input.substring(0, index);
609
+ input = input.substring(index + separator.length);
610
+
611
+ if (token.length > 0) {
612
+ token = opts.createSearchChoice.call(this, token, selection);
613
+ if (token !== undefined && token !== null && opts.id(token) !== undefined && opts.id(token) !== null) {
614
+ dupe = false;
615
+ for (i = 0, l = selection.length; i < l; i++) {
616
+ if (equal(opts.id(token), opts.id(selection[i]))) {
617
+ dupe = true; break;
618
+ }
619
+ }
620
+
621
+ if (!dupe) selectCallback(token);
622
+ }
623
+ }
624
+ }
625
+
626
+ if (original!==input) return input;
627
+ }
628
+
629
+ function cleanupJQueryElements() {
630
+ var self = this;
631
+
632
+ Array.prototype.forEach.call(arguments, function (element) {
633
+ self[element].remove();
634
+ self[element] = null;
635
+ });
636
+ }
637
+
638
+ /**
639
+ * Creates a new class
640
+ *
641
+ * @param superClass
642
+ * @param methods
643
+ */
644
+ function clazz(SuperClass, methods) {
645
+ var constructor = function () {};
646
+ constructor.prototype = new SuperClass;
647
+ constructor.prototype.constructor = constructor;
648
+ constructor.prototype.parent = SuperClass.prototype;
649
+ constructor.prototype = $.extend(constructor.prototype, methods);
650
+ return constructor;
651
+ }
652
+
653
+ AbstractSelect2 = clazz(Object, {
654
+
655
+ // abstract
656
+ bind: function (func) {
657
+ var self = this;
658
+ return function () {
659
+ func.apply(self, arguments);
660
+ };
661
+ },
662
+
663
+ // abstract
664
+ init: function (opts) {
665
+ var results, search, resultsSelector = ".select2-results";
666
+
667
+ // prepare options
668
+ this.opts = opts = this.prepareOpts(opts);
669
+
670
+ this.id=opts.id;
671
+
672
+ // destroy if called on an existing component
673
+ if (opts.element.data("select2") !== undefined &&
674
+ opts.element.data("select2") !== null) {
675
+ opts.element.data("select2").destroy();
676
+ }
677
+
678
+ this.container = this.createContainer();
679
+
680
+ this.liveRegion = $("<span>", {
681
+ role: "status",
682
+ "aria-live": "polite"
683
+ })
684
+ .addClass("select2-hidden-accessible")
685
+ .appendTo(document.body);
686
+
687
+ this.containerId="s2id_"+(opts.element.attr("id") || "autogen"+nextUid());
688
+ this.containerEventName= this.containerId
689
+ .replace(/([.])/g, '_')
690
+ .replace(/([;&,\-\.\+\*\~':"\!\^#$%@\[\]\(\)=>\|])/g, '\\$1');
691
+ this.container.attr("id", this.containerId);
692
+
693
+ this.container.attr("title", opts.element.attr("title"));
694
+
695
+ this.body = $("body");
696
+
697
+ syncCssClasses(this.container, this.opts.element, this.opts.adaptContainerCssClass);
698
+
699
+ this.container.attr("style", opts.element.attr("style"));
700
+ this.container.css(evaluate(opts.containerCss));
701
+ this.container.addClass(evaluate(opts.containerCssClass));
702
+
703
+ this.elementTabIndex = this.opts.element.attr("tabindex");
704
+
705
+ // swap container for the element
706
+ this.opts.element
707
+ .data("select2", this)
708
+ .attr("tabindex", "-1")
709
+ .before(this.container)
710
+ .on("click.select2", killEvent); // do not leak click events
711
+
712
+ this.container.data("select2", this);
713
+
714
+ this.dropdown = this.container.find(".select2-drop");
715
+
716
+ syncCssClasses(this.dropdown, this.opts.element, this.opts.adaptDropdownCssClass);
717
+
718
+ this.dropdown.addClass(evaluate(opts.dropdownCssClass));
719
+ this.dropdown.data("select2", this);
720
+ this.dropdown.on("click", killEvent);
721
+
722
+ this.results = results = this.container.find(resultsSelector);
723
+ this.search = search = this.container.find("input.select2-input");
724
+
725
+ this.queryCount = 0;
726
+ this.resultsPage = 0;
727
+ this.context = null;
728
+
729
+ // initialize the container
730
+ this.initContainer();
731
+
732
+ this.container.on("click", killEvent);
733
+
734
+ installFilteredMouseMove(this.results);
735
+
736
+ this.dropdown.on("mousemove-filtered", resultsSelector, this.bind(this.highlightUnderEvent));
737
+ this.dropdown.on("touchstart touchmove touchend", resultsSelector, this.bind(function (event) {
738
+ this._touchEvent = true;
739
+ this.highlightUnderEvent(event);
740
+ }));
741
+ this.dropdown.on("touchmove", resultsSelector, this.bind(this.touchMoved));
742
+ this.dropdown.on("touchstart touchend", resultsSelector, this.bind(this.clearTouchMoved));
743
+
744
+ // Waiting for a click event on touch devices to select option and hide dropdown
745
+ // otherwise click will be triggered on an underlying element
746
+ this.dropdown.on('click', this.bind(function (event) {
747
+ if (this._touchEvent) {
748
+ this._touchEvent = false;
749
+ this.selectHighlighted();
750
+ }
751
+ }));
752
+
753
+ installDebouncedScroll(80, this.results);
754
+ this.dropdown.on("scroll-debounced", resultsSelector, this.bind(this.loadMoreIfNeeded));
755
+
756
+ // do not propagate change event from the search field out of the component
757
+ $(this.container).on("change", ".select2-input", function(e) {e.stopPropagation();});
758
+ $(this.dropdown).on("change", ".select2-input", function(e) {e.stopPropagation();});
759
+
760
+ // if jquery.mousewheel plugin is installed we can prevent out-of-bounds scrolling of results via mousewheel
761
+ if ($.fn.mousewheel) {
762
+ results.mousewheel(function (e, delta, deltaX, deltaY) {
763
+ var top = results.scrollTop();
764
+ if (deltaY > 0 && top - deltaY <= 0) {
765
+ results.scrollTop(0);
766
+ killEvent(e);
767
+ } else if (deltaY < 0 && results.get(0).scrollHeight - results.scrollTop() + deltaY <= results.height()) {
768
+ results.scrollTop(results.get(0).scrollHeight - results.height());
769
+ killEvent(e);
770
+ }
771
+ });
772
+ }
773
+
774
+ installKeyUpChangeEvent(search);
775
+ search.on("keyup-change input paste", this.bind(this.updateResults));
776
+ search.on("focus", function () { search.addClass("select2-focused"); });
777
+ search.on("blur", function () { search.removeClass("select2-focused");});
778
+
779
+ this.dropdown.on("mouseup", resultsSelector, this.bind(function (e) {
780
+ if ($(e.target).closest(".select2-result-selectable").length > 0) {
781
+ this.highlightUnderEvent(e);
782
+ this.selectHighlighted(e);
783
+ }
784
+ }));
785
+
786
+ // trap all mouse events from leaving the dropdown. sometimes there may be a modal that is listening
787
+ // for mouse events outside of itself so it can close itself. since the dropdown is now outside the select2's
788
+ // dom it will trigger the popup close, which is not what we want
789
+ // focusin can cause focus wars between modals and select2 since the dropdown is outside the modal.
790
+ this.dropdown.on("click mouseup mousedown touchstart touchend focusin", function (e) { e.stopPropagation(); });
791
+
792
+ this.nextSearchTerm = undefined;
793
+
794
+ if ($.isFunction(this.opts.initSelection)) {
795
+ // initialize selection based on the current value of the source element
796
+ this.initSelection();
797
+
798
+ // if the user has provided a function that can set selection based on the value of the source element
799
+ // we monitor the change event on the element and trigger it, allowing for two way synchronization
800
+ this.monitorSource();
801
+ }
802
+
803
+ if (opts.maximumInputLength !== null) {
804
+ this.search.attr("maxlength", opts.maximumInputLength);
805
+ }
806
+
807
+ var disabled = opts.element.prop("disabled");
808
+ if (disabled === undefined) disabled = false;
809
+ this.enable(!disabled);
810
+
811
+ var readonly = opts.element.prop("readonly");
812
+ if (readonly === undefined) readonly = false;
813
+ this.readonly(readonly);
814
+
815
+ // Calculate size of scrollbar
816
+ scrollBarDimensions = scrollBarDimensions || measureScrollbar();
817
+
818
+ this.autofocus = opts.element.prop("autofocus");
819
+ opts.element.prop("autofocus", false);
820
+ if (this.autofocus) this.focus();
821
+
822
+ this.search.attr("placeholder", opts.searchInputPlaceholder);
823
+ },
824
+
825
+ // abstract
826
+ destroy: function () {
827
+ var element=this.opts.element, select2 = element.data("select2");
828
+
829
+ this.close();
830
+
831
+ if (this.propertyObserver) {
832
+ this.propertyObserver.disconnect();
833
+ this.propertyObserver = null;
834
+ }
835
+
836
+ if (select2 !== undefined) {
837
+ select2.container.remove();
838
+ select2.liveRegion.remove();
839
+ select2.dropdown.remove();
840
+ element
841
+ .removeClass("select2-offscreen")
842
+ .removeData("select2")
843
+ .off(".select2")
844
+ .prop("autofocus", this.autofocus || false);
845
+ if (this.elementTabIndex) {
846
+ element.attr({tabindex: this.elementTabIndex});
847
+ } else {
848
+ element.removeAttr("tabindex");
849
+ }
850
+ element.show();
851
+ }
852
+
853
+ cleanupJQueryElements.call(this,
854
+ "container",
855
+ "liveRegion",
856
+ "dropdown",
857
+ "results",
858
+ "search"
859
+ );
860
+ },
861
+
862
+ // abstract
863
+ optionToData: function(element) {
864
+ if (element.is("option")) {
865
+ return {
866
+ id:element.prop("value"),
867
+ text:element.text(),
868
+ element: element.get(),
869
+ css: element.attr("class"),
870
+ disabled: element.prop("disabled"),
871
+ locked: equal(element.attr("locked"), "locked") || equal(element.data("locked"), true)
872
+ };
873
+ } else if (element.is("optgroup")) {
874
+ return {
875
+ text:element.attr("label"),
876
+ children:[],
877
+ element: element.get(),
878
+ css: element.attr("class")
879
+ };
880
+ }
881
+ },
882
+
883
+ // abstract
884
+ prepareOpts: function (opts) {
885
+ var element, select, idKey, ajaxUrl, self = this;
886
+
887
+ element = opts.element;
888
+
889
+ if (element.get(0).tagName.toLowerCase() === "select") {
890
+ this.select = select = opts.element;
891
+ }
892
+
893
+ if (select) {
894
+ // these options are not allowed when attached to a select because they are picked up off the element itself
895
+ $.each(["id", "multiple", "ajax", "query", "createSearchChoice", "initSelection", "data", "tags"], function () {
896
+ if (this in opts) {
897
+ throw new Error("Option '" + this + "' is not allowed for Select2 when attached to a <select> element.");
898
+ }
899
+ });
900
+ }
901
+
902
+ opts = $.extend({}, {
903
+ populateResults: function(container, results, query) {
904
+ var populate, id=this.opts.id, liveRegion=this.liveRegion;
905
+
906
+ populate=function(results, container, depth) {
907
+
908
+ var i, l, result, selectable, disabled, compound, node, label, innerContainer, formatted;
909
+
910
+ results = opts.sortResults(results, container, query);
911
+
912
+ for (i = 0, l = results.length; i < l; i = i + 1) {
913
+
914
+ result=results[i];
915
+
916
+ disabled = (result.disabled === true);
917
+ selectable = (!disabled) && (id(result) !== undefined);
918
+
919
+ compound=result.children && result.children.length > 0;
920
+
921
+ node=$("<li></li>");
922
+ node.addClass("select2-results-dept-"+depth);
923
+ node.addClass("select2-result");
924
+ node.addClass(selectable ? "select2-result-selectable" : "select2-result-unselectable");
925
+ if (disabled) { node.addClass("select2-disabled"); }
926
+ if (compound) { node.addClass("select2-result-with-children"); }
927
+ node.addClass(self.opts.formatResultCssClass(result));
928
+ node.attr("role", "presentation");
929
+
930
+ label=$(document.createElement("div"));
931
+ label.addClass("select2-result-label");
932
+ label.attr("id", "select2-result-label-" + nextUid());
933
+ label.attr("role", "option");
934
+
935
+ formatted=opts.formatResult(result, label, query, self.opts.escapeMarkup);
936
+ if (formatted!==undefined) {
937
+ label.html(formatted);
938
+ node.append(label);
939
+ }
940
+
941
+
942
+ if (compound) {
943
+
944
+ innerContainer=$("<ul></ul>");
945
+ innerContainer.addClass("select2-result-sub");
946
+ populate(result.children, innerContainer, depth+1);
947
+ node.append(innerContainer);
948
+ }
949
+
950
+ node.data("select2-data", result);
951
+ container.append(node);
952
+ }
953
+
954
+ liveRegion.text(opts.formatMatches(results.length));
955
+ };
956
+
957
+ populate(results, container, 0);
958
+ }
959
+ }, $.fn.select2.defaults, opts);
960
+
961
+ if (typeof(opts.id) !== "function") {
962
+ idKey = opts.id;
963
+ opts.id = function (e) { return e[idKey]; };
964
+ }
965
+
966
+ if ($.isArray(opts.element.data("select2Tags"))) {
967
+ if ("tags" in opts) {
968
+ throw "tags specified as both an attribute 'data-select2-tags' and in options of Select2 " + opts.element.attr("id");
969
+ }
970
+ opts.tags=opts.element.data("select2Tags");
971
+ }
972
+
973
+ if (select) {
974
+ opts.query = this.bind(function (query) {
975
+ var data = { results: [], more: false },
976
+ term = query.term,
977
+ children, placeholderOption, process;
978
+
979
+ process=function(element, collection) {
980
+ var group;
981
+ if (element.is("option")) {
982
+ if (query.matcher(term, element.text(), element)) {
983
+ collection.push(self.optionToData(element));
984
+ }
985
+ } else if (element.is("optgroup")) {
986
+ group=self.optionToData(element);
987
+ element.children().each2(function(i, elm) { process(elm, group.children); });
988
+ if (group.children.length>0) {
989
+ collection.push(group);
990
+ }
991
+ }
992
+ };
993
+
994
+ children=element.children();
995
+
996
+ // ignore the placeholder option if there is one
997
+ if (this.getPlaceholder() !== undefined && children.length > 0) {
998
+ placeholderOption = this.getPlaceholderOption();
999
+ if (placeholderOption) {
1000
+ children=children.not(placeholderOption);
1001
+ }
1002
+ }
1003
+
1004
+ children.each2(function(i, elm) { process(elm, data.results); });
1005
+
1006
+ query.callback(data);
1007
+ });
1008
+ // this is needed because inside val() we construct choices from options and there id is hardcoded
1009
+ opts.id=function(e) { return e.id; };
1010
+ } else {
1011
+ if (!("query" in opts)) {
1012
+
1013
+ if ("ajax" in opts) {
1014
+ ajaxUrl = opts.element.data("ajax-url");
1015
+ if (ajaxUrl && ajaxUrl.length > 0) {
1016
+ opts.ajax.url = ajaxUrl;
1017
+ }
1018
+ opts.query = ajax.call(opts.element, opts.ajax);
1019
+ } else if ("data" in opts) {
1020
+ opts.query = local(opts.data);
1021
+ } else if ("tags" in opts) {
1022
+ opts.query = tags(opts.tags);
1023
+ if (opts.createSearchChoice === undefined) {
1024
+ opts.createSearchChoice = function (term) { return {id: $.trim(term), text: $.trim(term)}; };
1025
+ }
1026
+ if (opts.initSelection === undefined) {
1027
+ opts.initSelection = function (element, callback) {
1028
+ var data = [];
1029
+ $(splitVal(element.val(), opts.separator)).each(function () {
1030
+ var obj = { id: this, text: this },
1031
+ tags = opts.tags;
1032
+ if ($.isFunction(tags)) tags=tags();
1033
+ $(tags).each(function() { if (equal(this.id, obj.id)) { obj = this; return false; } });
1034
+ data.push(obj);
1035
+ });
1036
+
1037
+ callback(data);
1038
+ };
1039
+ }
1040
+ }
1041
+ }
1042
+ }
1043
+ if (typeof(opts.query) !== "function") {
1044
+ throw "query function not defined for Select2 " + opts.element.attr("id");
1045
+ }
1046
+
1047
+ if (opts.createSearchChoicePosition === 'top') {
1048
+ opts.createSearchChoicePosition = function(list, item) { list.unshift(item); };
1049
+ }
1050
+ else if (opts.createSearchChoicePosition === 'bottom') {
1051
+ opts.createSearchChoicePosition = function(list, item) { list.push(item); };
1052
+ }
1053
+ else if (typeof(opts.createSearchChoicePosition) !== "function") {
1054
+ throw "invalid createSearchChoicePosition option must be 'top', 'bottom' or a custom function";
1055
+ }
1056
+
1057
+ return opts;
1058
+ },
1059
+
1060
+ /**
1061
+ * Monitor the original element for changes and update select2 accordingly
1062
+ */
1063
+ // abstract
1064
+ monitorSource: function () {
1065
+ var el = this.opts.element, sync, observer;
1066
+
1067
+ el.on("change.select2", this.bind(function (e) {
1068
+ if (this.opts.element.data("select2-change-triggered") !== true) {
1069
+ this.initSelection();
1070
+ }
1071
+ }));
1072
+
1073
+ sync = this.bind(function () {
1074
+
1075
+ // sync enabled state
1076
+ var disabled = el.prop("disabled");
1077
+ if (disabled === undefined) disabled = false;
1078
+ this.enable(!disabled);
1079
+
1080
+ var readonly = el.prop("readonly");
1081
+ if (readonly === undefined) readonly = false;
1082
+ this.readonly(readonly);
1083
+
1084
+ syncCssClasses(this.container, this.opts.element, this.opts.adaptContainerCssClass);
1085
+ this.container.addClass(evaluate(this.opts.containerCssClass));
1086
+
1087
+ syncCssClasses(this.dropdown, this.opts.element, this.opts.adaptDropdownCssClass);
1088
+ this.dropdown.addClass(evaluate(this.opts.dropdownCssClass));
1089
+
1090
+ });
1091
+
1092
+ // IE8-10 (IE9/10 won't fire propertyChange via attachEventListener)
1093
+ if (el.length && el[0].attachEvent) {
1094
+ el.each(function() {
1095
+ this.attachEvent("onpropertychange", sync);
1096
+ });
1097
+ }
1098
+
1099
+ // safari, chrome, firefox, IE11
1100
+ observer = window.MutationObserver || window.WebKitMutationObserver|| window.MozMutationObserver;
1101
+ if (observer !== undefined) {
1102
+ if (this.propertyObserver) { delete this.propertyObserver; this.propertyObserver = null; }
1103
+ this.propertyObserver = new observer(function (mutations) {
1104
+ mutations.forEach(sync);
1105
+ });
1106
+ this.propertyObserver.observe(el.get(0), { attributes:true, subtree:false });
1107
+ }
1108
+ },
1109
+
1110
+ // abstract
1111
+ triggerSelect: function(data) {
1112
+ var evt = $.Event("select2-selecting", { val: this.id(data), object: data });
1113
+ this.opts.element.trigger(evt);
1114
+ return !evt.isDefaultPrevented();
1115
+ },
1116
+
1117
+ /**
1118
+ * Triggers the change event on the source element
1119
+ */
1120
+ // abstract
1121
+ triggerChange: function (details) {
1122
+
1123
+ details = details || {};
1124
+ details= $.extend({}, details, { type: "change", val: this.val() });
1125
+ // prevents recursive triggering
1126
+ this.opts.element.data("select2-change-triggered", true);
1127
+ this.opts.element.trigger(details);
1128
+ this.opts.element.data("select2-change-triggered", false);
1129
+
1130
+ // some validation frameworks ignore the change event and listen instead to keyup, click for selects
1131
+ // so here we trigger the click event manually
1132
+ this.opts.element.click();
1133
+
1134
+ // ValidationEngine ignores the change event and listens instead to blur
1135
+ // so here we trigger the blur event manually if so desired
1136
+ if (this.opts.blurOnChange)
1137
+ this.opts.element.blur();
1138
+ },
1139
+
1140
+ //abstract
1141
+ isInterfaceEnabled: function()
1142
+ {
1143
+ return this.enabledInterface === true;
1144
+ },
1145
+
1146
+ // abstract
1147
+ enableInterface: function() {
1148
+ var enabled = this._enabled && !this._readonly,
1149
+ disabled = !enabled;
1150
+
1151
+ if (enabled === this.enabledInterface) return false;
1152
+
1153
+ this.container.toggleClass("select2-container-disabled", disabled);
1154
+ this.close();
1155
+ this.enabledInterface = enabled;
1156
+
1157
+ return true;
1158
+ },
1159
+
1160
+ // abstract
1161
+ enable: function(enabled) {
1162
+ if (enabled === undefined) enabled = true;
1163
+ if (this._enabled === enabled) return;
1164
+ this._enabled = enabled;
1165
+
1166
+ this.opts.element.prop("disabled", !enabled);
1167
+ this.enableInterface();
1168
+ },
1169
+
1170
+ // abstract
1171
+ disable: function() {
1172
+ this.enable(false);
1173
+ },
1174
+
1175
+ // abstract
1176
+ readonly: function(enabled) {
1177
+ if (enabled === undefined) enabled = false;
1178
+ if (this._readonly === enabled) return;
1179
+ this._readonly = enabled;
1180
+
1181
+ this.opts.element.prop("readonly", enabled);
1182
+ this.enableInterface();
1183
+ },
1184
+
1185
+ // abstract
1186
+ opened: function () {
1187
+ return this.container.hasClass("select2-dropdown-open");
1188
+ },
1189
+
1190
+ // abstract
1191
+ positionDropdown: function() {
1192
+ var $dropdown = this.dropdown,
1193
+ offset = this.container.offset(),
1194
+ height = this.container.outerHeight(false),
1195
+ width = this.container.outerWidth(false),
1196
+ dropHeight = $dropdown.outerHeight(false),
1197
+ $window = $(window),
1198
+ windowWidth = $window.width(),
1199
+ windowHeight = $window.height(),
1200
+ viewPortRight = $window.scrollLeft() + windowWidth,
1201
+ viewportBottom = $window.scrollTop() + windowHeight,
1202
+ dropTop = offset.top + height,
1203
+ dropLeft = offset.left,
1204
+ enoughRoomBelow = dropTop + dropHeight <= viewportBottom,
1205
+ enoughRoomAbove = (offset.top - dropHeight) >= $window.scrollTop(),
1206
+ dropWidth = $dropdown.outerWidth(false),
1207
+ enoughRoomOnRight = dropLeft + dropWidth <= viewPortRight,
1208
+ aboveNow = $dropdown.hasClass("select2-drop-above"),
1209
+ bodyOffset,
1210
+ above,
1211
+ changeDirection,
1212
+ css,
1213
+ resultsListNode;
1214
+
1215
+ // always prefer the current above/below alignment, unless there is not enough room
1216
+ if (aboveNow) {
1217
+ above = true;
1218
+ if (!enoughRoomAbove && enoughRoomBelow) {
1219
+ changeDirection = true;
1220
+ above = false;
1221
+ }
1222
+ } else {
1223
+ above = false;
1224
+ if (!enoughRoomBelow && enoughRoomAbove) {
1225
+ changeDirection = true;
1226
+ above = true;
1227
+ }
1228
+ }
1229
+
1230
+ //if we are changing direction we need to get positions when dropdown is hidden;
1231
+ if (changeDirection) {
1232
+ $dropdown.hide();
1233
+ offset = this.container.offset();
1234
+ height = this.container.outerHeight(false);
1235
+ width = this.container.outerWidth(false);
1236
+ dropHeight = $dropdown.outerHeight(false);
1237
+ viewPortRight = $window.scrollLeft() + windowWidth;
1238
+ viewportBottom = $window.scrollTop() + windowHeight;
1239
+ dropTop = offset.top + height;
1240
+ dropLeft = offset.left;
1241
+ dropWidth = $dropdown.outerWidth(false);
1242
+ enoughRoomOnRight = dropLeft + dropWidth <= viewPortRight;
1243
+ $dropdown.show();
1244
+
1245
+ // fix so the cursor does not move to the left within the search-textbox in IE
1246
+ this.focusSearch();
1247
+ }
1248
+
1249
+ if (this.opts.dropdownAutoWidth) {
1250
+ resultsListNode = $('.select2-results', $dropdown)[0];
1251
+ $dropdown.addClass('select2-drop-auto-width');
1252
+ $dropdown.css('width', '');
1253
+ // Add scrollbar width to dropdown if vertical scrollbar is present
1254
+ dropWidth = $dropdown.outerWidth(false) + (resultsListNode.scrollHeight === resultsListNode.clientHeight ? 0 : scrollBarDimensions.width);
1255
+ dropWidth > width ? width = dropWidth : dropWidth = width;
1256
+ dropHeight = $dropdown.outerHeight(false);
1257
+ enoughRoomOnRight = dropLeft + dropWidth <= viewPortRight;
1258
+ }
1259
+ else {
1260
+ this.container.removeClass('select2-drop-auto-width');
1261
+ }
1262
+
1263
+ //console.log("below/ droptop:", dropTop, "dropHeight", dropHeight, "sum", (dropTop+dropHeight)+" viewport bottom", viewportBottom, "enough?", enoughRoomBelow);
1264
+ //console.log("above/ offset.top", offset.top, "dropHeight", dropHeight, "top", (offset.top-dropHeight), "scrollTop", this.body.scrollTop(), "enough?", enoughRoomAbove);
1265
+
1266
+ // fix positioning when body has an offset and is not position: static
1267
+ if (this.body.css('position') !== 'static') {
1268
+ bodyOffset = this.body.offset();
1269
+ dropTop -= bodyOffset.top;
1270
+ dropLeft -= bodyOffset.left;
1271
+ }
1272
+
1273
+ if (!enoughRoomOnRight) {
1274
+ dropLeft = offset.left + this.container.outerWidth(false) - dropWidth;
1275
+ }
1276
+
1277
+ css = {
1278
+ left: dropLeft,
1279
+ width: width
1280
+ };
1281
+
1282
+ if (above) {
1283
+ css.top = offset.top - dropHeight;
1284
+ css.bottom = 'auto';
1285
+ this.container.addClass("select2-drop-above");
1286
+ $dropdown.addClass("select2-drop-above");
1287
+ }
1288
+ else {
1289
+ css.top = dropTop;
1290
+ css.bottom = 'auto';
1291
+ this.container.removeClass("select2-drop-above");
1292
+ $dropdown.removeClass("select2-drop-above");
1293
+ }
1294
+ css = $.extend(css, evaluate(this.opts.dropdownCss));
1295
+
1296
+ $dropdown.css(css);
1297
+ },
1298
+
1299
+ // abstract
1300
+ shouldOpen: function() {
1301
+ var event;
1302
+
1303
+ if (this.opened()) return false;
1304
+
1305
+ if (this._enabled === false || this._readonly === true) return false;
1306
+
1307
+ event = $.Event("select2-opening");
1308
+ this.opts.element.trigger(event);
1309
+ return !event.isDefaultPrevented();
1310
+ },
1311
+
1312
+ // abstract
1313
+ clearDropdownAlignmentPreference: function() {
1314
+ // clear the classes used to figure out the preference of where the dropdown should be opened
1315
+ this.container.removeClass("select2-drop-above");
1316
+ this.dropdown.removeClass("select2-drop-above");
1317
+ },
1318
+
1319
+ /**
1320
+ * Opens the dropdown
1321
+ *
1322
+ * @return {Boolean} whether or not dropdown was opened. This method will return false if, for example,
1323
+ * the dropdown is already open, or if the 'open' event listener on the element called preventDefault().
1324
+ */
1325
+ // abstract
1326
+ open: function () {
1327
+
1328
+ if (!this.shouldOpen()) return false;
1329
+
1330
+ this.opening();
1331
+
1332
+ return true;
1333
+ },
1334
+
1335
+ /**
1336
+ * Performs the opening of the dropdown
1337
+ */
1338
+ // abstract
1339
+ opening: function() {
1340
+ var cid = this.containerEventName,
1341
+ scroll = "scroll." + cid,
1342
+ resize = "resize."+cid,
1343
+ orient = "orientationchange."+cid,
1344
+ mask;
1345
+
1346
+ this.container.addClass("select2-dropdown-open").addClass("select2-container-active");
1347
+
1348
+ this.clearDropdownAlignmentPreference();
1349
+
1350
+ if(this.dropdown[0] !== this.body.children().last()[0]) {
1351
+ this.dropdown.detach().appendTo(this.body);
1352
+ }
1353
+
1354
+ // create the dropdown mask if doesn't already exist
1355
+ mask = $("#select2-drop-mask");
1356
+ if (mask.length == 0) {
1357
+ mask = $(document.createElement("div"));
1358
+ mask.attr("id","select2-drop-mask").attr("class","select2-drop-mask");
1359
+ mask.hide();
1360
+ mask.appendTo(this.body);
1361
+ mask.on("mousedown touchstart click", function (e) {
1362
+ // Prevent IE from generating a click event on the body
1363
+ reinsertElement(mask);
1364
+
1365
+ var dropdown = $("#select2-drop"), self;
1366
+ if (dropdown.length > 0) {
1367
+ self=dropdown.data("select2");
1368
+ if (self.opts.selectOnBlur) {
1369
+ self.selectHighlighted({noFocus: true});
1370
+ }
1371
+ self.close();
1372
+ e.preventDefault();
1373
+ e.stopPropagation();
1374
+ }
1375
+ });
1376
+ }
1377
+
1378
+ // ensure the mask is always right before the dropdown
1379
+ if (this.dropdown.prev()[0] !== mask[0]) {
1380
+ this.dropdown.before(mask);
1381
+ }
1382
+
1383
+ // move the global id to the correct dropdown
1384
+ $("#select2-drop").removeAttr("id");
1385
+ this.dropdown.attr("id", "select2-drop");
1386
+
1387
+ // show the elements
1388
+ mask.show();
1389
+
1390
+ this.positionDropdown();
1391
+ this.dropdown.show();
1392
+ this.positionDropdown();
1393
+
1394
+ this.dropdown.addClass("select2-drop-active");
1395
+
1396
+ // attach listeners to events that can change the position of the container and thus require
1397
+ // the position of the dropdown to be updated as well so it does not come unglued from the container
1398
+ var that = this;
1399
+ this.container.parents().add(window).each(function () {
1400
+ $(this).on(resize+" "+scroll+" "+orient, function (e) {
1401
+ if (that.opened()) that.positionDropdown();
1402
+ });
1403
+ });
1404
+
1405
+
1406
+ },
1407
+
1408
+ // abstract
1409
+ close: function () {
1410
+ if (!this.opened()) return;
1411
+
1412
+ var cid = this.containerEventName,
1413
+ scroll = "scroll." + cid,
1414
+ resize = "resize."+cid,
1415
+ orient = "orientationchange."+cid;
1416
+
1417
+ // unbind event listeners
1418
+ this.container.parents().add(window).each(function () { $(this).off(scroll).off(resize).off(orient); });
1419
+
1420
+ this.clearDropdownAlignmentPreference();
1421
+
1422
+ $("#select2-drop-mask").hide();
1423
+ this.dropdown.removeAttr("id"); // only the active dropdown has the select2-drop id
1424
+ this.dropdown.hide();
1425
+ this.container.removeClass("select2-dropdown-open").removeClass("select2-container-active");
1426
+ this.results.empty();
1427
+
1428
+
1429
+ this.clearSearch();
1430
+ this.search.removeClass("select2-active");
1431
+ this.opts.element.trigger($.Event("select2-close"));
1432
+ },
1433
+
1434
+ /**
1435
+ * Opens control, sets input value, and updates results.
1436
+ */
1437
+ // abstract
1438
+ externalSearch: function (term) {
1439
+ this.open();
1440
+ this.search.val(term);
1441
+ this.updateResults(false);
1442
+ },
1443
+
1444
+ // abstract
1445
+ clearSearch: function () {
1446
+
1447
+ },
1448
+
1449
+ //abstract
1450
+ getMaximumSelectionSize: function() {
1451
+ return evaluate(this.opts.maximumSelectionSize);
1452
+ },
1453
+
1454
+ // abstract
1455
+ ensureHighlightVisible: function () {
1456
+ var results = this.results, children, index, child, hb, rb, y, more;
1457
+
1458
+ index = this.highlight();
1459
+
1460
+ if (index < 0) return;
1461
+
1462
+ if (index == 0) {
1463
+
1464
+ // if the first element is highlighted scroll all the way to the top,
1465
+ // that way any unselectable headers above it will also be scrolled
1466
+ // into view
1467
+
1468
+ results.scrollTop(0);
1469
+ return;
1470
+ }
1471
+
1472
+ children = this.findHighlightableChoices().find('.select2-result-label');
1473
+
1474
+ child = $(children[index]);
1475
+
1476
+ hb = child.offset().top + child.outerHeight(true);
1477
+
1478
+ // if this is the last child lets also make sure select2-more-results is visible
1479
+ if (index === children.length - 1) {
1480
+ more = results.find("li.select2-more-results");
1481
+ if (more.length > 0) {
1482
+ hb = more.offset().top + more.outerHeight(true);
1483
+ }
1484
+ }
1485
+
1486
+ rb = results.offset().top + results.outerHeight(true);
1487
+ if (hb > rb) {
1488
+ results.scrollTop(results.scrollTop() + (hb - rb));
1489
+ }
1490
+ y = child.offset().top - results.offset().top;
1491
+
1492
+ // make sure the top of the element is visible
1493
+ if (y < 0 && child.css('display') != 'none' ) {
1494
+ results.scrollTop(results.scrollTop() + y); // y is negative
1495
+ }
1496
+ },
1497
+
1498
+ // abstract
1499
+ findHighlightableChoices: function() {
1500
+ return this.results.find(".select2-result-selectable:not(.select2-disabled):not(.select2-selected)");
1501
+ },
1502
+
1503
+ // abstract
1504
+ moveHighlight: function (delta) {
1505
+ var choices = this.findHighlightableChoices(),
1506
+ index = this.highlight();
1507
+
1508
+ while (index > -1 && index < choices.length) {
1509
+ index += delta;
1510
+ var choice = $(choices[index]);
1511
+ if (choice.hasClass("select2-result-selectable") && !choice.hasClass("select2-disabled") && !choice.hasClass("select2-selected")) {
1512
+ this.highlight(index);
1513
+ break;
1514
+ }
1515
+ }
1516
+ },
1517
+
1518
+ // abstract
1519
+ highlight: function (index) {
1520
+ var choices = this.findHighlightableChoices(),
1521
+ choice,
1522
+ data;
1523
+
1524
+ if (arguments.length === 0) {
1525
+ return indexOf(choices.filter(".select2-highlighted")[0], choices.get());
1526
+ }
1527
+
1528
+ if (index >= choices.length) index = choices.length - 1;
1529
+ if (index < 0) index = 0;
1530
+
1531
+ this.removeHighlight();
1532
+
1533
+ choice = $(choices[index]);
1534
+ choice.addClass("select2-highlighted");
1535
+
1536
+ // ensure assistive technology can determine the active choice
1537
+ this.search.attr("aria-activedescendant", choice.find(".select2-result-label").attr("id"));
1538
+
1539
+ this.ensureHighlightVisible();
1540
+
1541
+ this.liveRegion.text(choice.text());
1542
+
1543
+ data = choice.data("select2-data");
1544
+ if (data) {
1545
+ this.opts.element.trigger({ type: "select2-highlight", val: this.id(data), choice: data });
1546
+ }
1547
+ },
1548
+
1549
+ removeHighlight: function() {
1550
+ this.results.find(".select2-highlighted").removeClass("select2-highlighted");
1551
+ },
1552
+
1553
+ touchMoved: function() {
1554
+ this._touchMoved = true;
1555
+ },
1556
+
1557
+ clearTouchMoved: function() {
1558
+ this._touchMoved = false;
1559
+ },
1560
+
1561
+ // abstract
1562
+ countSelectableResults: function() {
1563
+ return this.findHighlightableChoices().length;
1564
+ },
1565
+
1566
+ // abstract
1567
+ highlightUnderEvent: function (event) {
1568
+ var el = $(event.target).closest(".select2-result-selectable");
1569
+ if (el.length > 0 && !el.is(".select2-highlighted")) {
1570
+ var choices = this.findHighlightableChoices();
1571
+ this.highlight(choices.index(el));
1572
+ } else if (el.length == 0) {
1573
+ // if we are over an unselectable item remove all highlights
1574
+ this.removeHighlight();
1575
+ }
1576
+ },
1577
+
1578
+ // abstract
1579
+ loadMoreIfNeeded: function () {
1580
+ var results = this.results,
1581
+ more = results.find("li.select2-more-results"),
1582
+ below, // pixels the element is below the scroll fold, below==0 is when the element is starting to be visible
1583
+ page = this.resultsPage + 1,
1584
+ self=this,
1585
+ term=this.search.val(),
1586
+ context=this.context;
1587
+
1588
+ if (more.length === 0) return;
1589
+ below = more.offset().top - results.offset().top - results.height();
1590
+
1591
+ if (below <= this.opts.loadMorePadding) {
1592
+ more.addClass("select2-active");
1593
+ this.opts.query({
1594
+ element: this.opts.element,
1595
+ term: term,
1596
+ page: page,
1597
+ context: context,
1598
+ matcher: this.opts.matcher,
1599
+ callback: this.bind(function (data) {
1600
+
1601
+ // ignore a response if the select2 has been closed before it was received
1602
+ if (!self.opened()) return;
1603
+
1604
+
1605
+ self.opts.populateResults.call(this, results, data.results, {term: term, page: page, context:context});
1606
+ self.postprocessResults(data, false, false);
1607
+
1608
+ if (data.more===true) {
1609
+ more.detach().appendTo(results).text(evaluate(self.opts.formatLoadMore, page+1));
1610
+ window.setTimeout(function() { self.loadMoreIfNeeded(); }, 10);
1611
+ } else {
1612
+ more.remove();
1613
+ }
1614
+ self.positionDropdown();
1615
+ self.resultsPage = page;
1616
+ self.context = data.context;
1617
+ this.opts.element.trigger({ type: "select2-loaded", items: data });
1618
+ })});
1619
+ }
1620
+ },
1621
+
1622
+ /**
1623
+ * Default tokenizer function which does nothing
1624
+ */
1625
+ tokenize: function() {
1626
+
1627
+ },
1628
+
1629
+ /**
1630
+ * @param initial whether or not this is the call to this method right after the dropdown has been opened
1631
+ */
1632
+ // abstract
1633
+ updateResults: function (initial) {
1634
+ var search = this.search,
1635
+ results = this.results,
1636
+ opts = this.opts,
1637
+ data,
1638
+ self = this,
1639
+ input,
1640
+ term = search.val(),
1641
+ lastTerm = $.data(this.container, "select2-last-term"),
1642
+ // sequence number used to drop out-of-order responses
1643
+ queryNumber;
1644
+
1645
+ // prevent duplicate queries against the same term
1646
+ if (initial !== true && lastTerm && equal(term, lastTerm)) return;
1647
+
1648
+ $.data(this.container, "select2-last-term", term);
1649
+
1650
+ // if the search is currently hidden we do not alter the results
1651
+ if (initial !== true && (this.showSearchInput === false || !this.opened())) {
1652
+ return;
1653
+ }
1654
+
1655
+ function postRender() {
1656
+ search.removeClass("select2-active");
1657
+ self.positionDropdown();
1658
+ if (results.find('.select2-no-results,.select2-selection-limit,.select2-searching').length) {
1659
+ self.liveRegion.text(results.text());
1660
+ }
1661
+ else {
1662
+ self.liveRegion.text(self.opts.formatMatches(results.find('.select2-result-selectable').length));
1663
+ }
1664
+ }
1665
+
1666
+ function render(html) {
1667
+ results.html(html);
1668
+ postRender();
1669
+ }
1670
+
1671
+ queryNumber = ++this.queryCount;
1672
+
1673
+ var maxSelSize = this.getMaximumSelectionSize();
1674
+ if (maxSelSize >=1) {
1675
+ data = this.data();
1676
+ if ($.isArray(data) && data.length >= maxSelSize && checkFormatter(opts.formatSelectionTooBig, "formatSelectionTooBig")) {
1677
+ render("<li class='select2-selection-limit'>" + evaluate(opts.formatSelectionTooBig, maxSelSize) + "</li>");
1678
+ return;
1679
+ }
1680
+ }
1681
+
1682
+ if (search.val().length < opts.minimumInputLength) {
1683
+ if (checkFormatter(opts.formatInputTooShort, "formatInputTooShort")) {
1684
+ render("<li class='select2-no-results'>" + evaluate(opts.formatInputTooShort, search.val(), opts.minimumInputLength) + "</li>");
1685
+ } else {
1686
+ render("");
1687
+ }
1688
+ if (initial && this.showSearch) this.showSearch(true);
1689
+ return;
1690
+ }
1691
+
1692
+ if (opts.maximumInputLength && search.val().length > opts.maximumInputLength) {
1693
+ if (checkFormatter(opts.formatInputTooLong, "formatInputTooLong")) {
1694
+ render("<li class='select2-no-results'>" + evaluate(opts.formatInputTooLong, search.val(), opts.maximumInputLength) + "</li>");
1695
+ } else {
1696
+ render("");
1697
+ }
1698
+ return;
1699
+ }
1700
+
1701
+ if (opts.formatSearching && this.findHighlightableChoices().length === 0) {
1702
+ render("<li class='select2-searching'>" + evaluate(opts.formatSearching) + "</li>");
1703
+ }
1704
+
1705
+ search.addClass("select2-active");
1706
+
1707
+ this.removeHighlight();
1708
+
1709
+ // give the tokenizer a chance to pre-process the input
1710
+ input = this.tokenize();
1711
+ if (input != undefined && input != null) {
1712
+ search.val(input);
1713
+ }
1714
+
1715
+ this.resultsPage = 1;
1716
+
1717
+ opts.query({
1718
+ element: opts.element,
1719
+ term: search.val(),
1720
+ page: this.resultsPage,
1721
+ context: null,
1722
+ matcher: opts.matcher,
1723
+ callback: this.bind(function (data) {
1724
+ var def; // default choice
1725
+
1726
+ // ignore old responses
1727
+ if (queryNumber != this.queryCount) {
1728
+ return;
1729
+ }
1730
+
1731
+ // ignore a response if the select2 has been closed before it was received
1732
+ if (!this.opened()) {
1733
+ this.search.removeClass("select2-active");
1734
+ return;
1735
+ }
1736
+
1737
+ // save context, if any
1738
+ this.context = (data.context===undefined) ? null : data.context;
1739
+ // create a default choice and prepend it to the list
1740
+ if (this.opts.createSearchChoice && search.val() !== "") {
1741
+ def = this.opts.createSearchChoice.call(self, search.val(), data.results);
1742
+ if (def !== undefined && def !== null && self.id(def) !== undefined && self.id(def) !== null) {
1743
+ if ($(data.results).filter(
1744
+ function () {
1745
+ return equal(self.id(this), self.id(def));
1746
+ }).length === 0) {
1747
+ this.opts.createSearchChoicePosition(data.results, def);
1748
+ }
1749
+ }
1750
+ }
1751
+
1752
+ if (data.results.length === 0 && checkFormatter(opts.formatNoMatches, "formatNoMatches")) {
1753
+ render("<li class='select2-no-results'>" + evaluate(opts.formatNoMatches, search.val()) + "</li>");
1754
+ return;
1755
+ }
1756
+
1757
+ results.empty();
1758
+ self.opts.populateResults.call(this, results, data.results, {term: search.val(), page: this.resultsPage, context:null});
1759
+
1760
+ if (data.more === true && checkFormatter(opts.formatLoadMore, "formatLoadMore")) {
1761
+ results.append("<li class='select2-more-results'>" + self.opts.escapeMarkup(evaluate(opts.formatLoadMore, this.resultsPage)) + "</li>");
1762
+ window.setTimeout(function() { self.loadMoreIfNeeded(); }, 10);
1763
+ }
1764
+
1765
+ this.postprocessResults(data, initial);
1766
+
1767
+ postRender();
1768
+
1769
+ this.opts.element.trigger({ type: "select2-loaded", items: data });
1770
+ })});
1771
+ },
1772
+
1773
+ // abstract
1774
+ cancel: function () {
1775
+ this.close();
1776
+ },
1777
+
1778
+ // abstract
1779
+ blur: function () {
1780
+ // if selectOnBlur == true, select the currently highlighted option
1781
+ if (this.opts.selectOnBlur)
1782
+ this.selectHighlighted({noFocus: true});
1783
+
1784
+ this.close();
1785
+ this.container.removeClass("select2-container-active");
1786
+ // synonymous to .is(':focus'), which is available in jquery >= 1.6
1787
+ if (this.search[0] === document.activeElement) { this.search.blur(); }
1788
+ this.clearSearch();
1789
+ this.selection.find(".select2-search-choice-focus").removeClass("select2-search-choice-focus");
1790
+ },
1791
+
1792
+ // abstract
1793
+ focusSearch: function () {
1794
+ focus(this.search);
1795
+ },
1796
+
1797
+ // abstract
1798
+ selectHighlighted: function (options) {
1799
+ if (this._touchMoved) {
1800
+ this.clearTouchMoved();
1801
+ return;
1802
+ }
1803
+ var index=this.highlight(),
1804
+ highlighted=this.results.find(".select2-highlighted"),
1805
+ data = highlighted.closest('.select2-result').data("select2-data");
1806
+
1807
+ if (data) {
1808
+ this.highlight(index);
1809
+ this.onSelect(data, options);
1810
+ } else if (options && options.noFocus) {
1811
+ this.close();
1812
+ }
1813
+ },
1814
+
1815
+ // abstract
1816
+ getPlaceholder: function () {
1817
+ var placeholderOption;
1818
+ return this.opts.element.attr("placeholder") ||
1819
+ this.opts.element.attr("data-placeholder") || // jquery 1.4 compat
1820
+ this.opts.element.data("placeholder") ||
1821
+ this.opts.placeholder ||
1822
+ ((placeholderOption = this.getPlaceholderOption()) !== undefined ? placeholderOption.text() : undefined);
1823
+ },
1824
+
1825
+ // abstract
1826
+ getPlaceholderOption: function() {
1827
+ if (this.select) {
1828
+ var firstOption = this.select.children('option').first();
1829
+ if (this.opts.placeholderOption !== undefined ) {
1830
+ //Determine the placeholder option based on the specified placeholderOption setting
1831
+ return (this.opts.placeholderOption === "first" && firstOption) ||
1832
+ (typeof this.opts.placeholderOption === "function" && this.opts.placeholderOption(this.select));
1833
+ } else if ($.trim(firstOption.text()) === "" && firstOption.val() === "") {
1834
+ //No explicit placeholder option specified, use the first if it's blank
1835
+ return firstOption;
1836
+ }
1837
+ }
1838
+ },
1839
+
1840
+ /**
1841
+ * Get the desired width for the container element. This is
1842
+ * derived first from option `width` passed to select2, then
1843
+ * the inline 'style' on the original element, and finally
1844
+ * falls back to the jQuery calculated element width.
1845
+ */
1846
+ // abstract
1847
+ initContainerWidth: function () {
1848
+ function resolveContainerWidth() {
1849
+ var style, attrs, matches, i, l, attr;
1850
+
1851
+ if (this.opts.width === "off") {
1852
+ return null;
1853
+ } else if (this.opts.width === "element"){
1854
+ return this.opts.element.outerWidth(false) === 0 ? 'auto' : this.opts.element.outerWidth(false) + 'px';
1855
+ } else if (this.opts.width === "copy" || this.opts.width === "resolve") {
1856
+ // check if there is inline style on the element that contains width
1857
+ style = this.opts.element.attr('style');
1858
+ if (style !== undefined) {
1859
+ attrs = style.split(';');
1860
+ for (i = 0, l = attrs.length; i < l; i = i + 1) {
1861
+ attr = attrs[i].replace(/\s/g, '');
1862
+ matches = attr.match(/^width:(([-+]?([0-9]*\.)?[0-9]+)(px|em|ex|%|in|cm|mm|pt|pc))/i);
1863
+ if (matches !== null && matches.length >= 1)
1864
+ return matches[1];
1865
+ }
1866
+ }
1867
+
1868
+ if (this.opts.width === "resolve") {
1869
+ // next check if css('width') can resolve a width that is percent based, this is sometimes possible
1870
+ // when attached to input type=hidden or elements hidden via css
1871
+ style = this.opts.element.css('width');
1872
+ if (style.indexOf("%") > 0) return style;
1873
+
1874
+ // finally, fallback on the calculated width of the element
1875
+ return (this.opts.element.outerWidth(false) === 0 ? 'auto' : this.opts.element.outerWidth(false) + 'px');
1876
+ }
1877
+
1878
+ return null;
1879
+ } else if ($.isFunction(this.opts.width)) {
1880
+ return this.opts.width();
1881
+ } else {
1882
+ return this.opts.width;
1883
+ }
1884
+ };
1885
+
1886
+ var width = resolveContainerWidth.call(this);
1887
+ if (width !== null) {
1888
+ this.container.css("width", width);
1889
+ }
1890
+ }
1891
+ });
1892
+
1893
+ SingleSelect2 = clazz(AbstractSelect2, {
1894
+
1895
+ // single
1896
+
1897
+ createContainer: function () {
1898
+ var container = $(document.createElement("div")).attr({
1899
+ "class": "select2-container"
1900
+ }).html([
1901
+ "<a href='javascript:void(0)' class='select2-choice' tabindex='-1'>",
1902
+ " <span class='select2-chosen'>&#160;</span><abbr class='select2-search-choice-close'></abbr>",
1903
+ " <span class='select2-arrow' role='presentation'><b role='presentation'></b></span>",
1904
+ "</a>",
1905
+ "<label for='' class='select2-offscreen'></label>",
1906
+ "<input class='select2-focusser select2-offscreen' type='text' aria-haspopup='true' role='button' />",
1907
+ "<div class='select2-drop select2-display-none'>",
1908
+ " <div class='select2-search'>",
1909
+ " <label for='' class='select2-offscreen'></label>",
1910
+ " <input type='text' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' class='select2-input' role='combobox' aria-expanded='true'",
1911
+ " aria-autocomplete='list' />",
1912
+ " </div>",
1913
+ " <ul class='select2-results' role='listbox'>",
1914
+ " </ul>",
1915
+ "</div>"].join(""));
1916
+ return container;
1917
+ },
1918
+
1919
+ // single
1920
+ enableInterface: function() {
1921
+ if (this.parent.enableInterface.apply(this, arguments)) {
1922
+ this.focusser.prop("disabled", !this.isInterfaceEnabled());
1923
+ }
1924
+ },
1925
+
1926
+ // single
1927
+ opening: function () {
1928
+ var el, range, len;
1929
+
1930
+ if (this.opts.minimumResultsForSearch >= 0) {
1931
+ this.showSearch(true);
1932
+ }
1933
+
1934
+ this.parent.opening.apply(this, arguments);
1935
+
1936
+ if (this.showSearchInput !== false) {
1937
+ // IE appends focusser.val() at the end of field :/ so we manually insert it at the beginning using a range
1938
+ // all other browsers handle this just fine
1939
+
1940
+ this.search.val(this.focusser.val());
1941
+ }
1942
+ if (this.opts.shouldFocusInput(this)) {
1943
+ this.search.focus();
1944
+ // move the cursor to the end after focussing, otherwise it will be at the beginning and
1945
+ // new text will appear *before* focusser.val()
1946
+ el = this.search.get(0);
1947
+ if (el.createTextRange) {
1948
+ range = el.createTextRange();
1949
+ range.collapse(false);
1950
+ range.select();
1951
+ } else if (el.setSelectionRange) {
1952
+ len = this.search.val().length;
1953
+ el.setSelectionRange(len, len);
1954
+ }
1955
+ }
1956
+
1957
+ // initializes search's value with nextSearchTerm (if defined by user)
1958
+ // ignore nextSearchTerm if the dropdown is opened by the user pressing a letter
1959
+ if(this.search.val() === "") {
1960
+ if(this.nextSearchTerm != undefined){
1961
+ this.search.val(this.nextSearchTerm);
1962
+ this.search.select();
1963
+ }
1964
+ }
1965
+
1966
+ this.focusser.prop("disabled", true).val("");
1967
+ this.updateResults(true);
1968
+ this.opts.element.trigger($.Event("select2-open"));
1969
+ },
1970
+
1971
+ // single
1972
+ close: function () {
1973
+ if (!this.opened()) return;
1974
+ this.parent.close.apply(this, arguments);
1975
+
1976
+ this.focusser.prop("disabled", false);
1977
+
1978
+ if (this.opts.shouldFocusInput(this)) {
1979
+ this.focusser.focus();
1980
+ }
1981
+ },
1982
+
1983
+ // single
1984
+ focus: function () {
1985
+ if (this.opened()) {
1986
+ this.close();
1987
+ } else {
1988
+ this.focusser.prop("disabled", false);
1989
+ if (this.opts.shouldFocusInput(this)) {
1990
+ this.focusser.focus();
1991
+ }
1992
+ }
1993
+ },
1994
+
1995
+ // single
1996
+ isFocused: function () {
1997
+ return this.container.hasClass("select2-container-active");
1998
+ },
1999
+
2000
+ // single
2001
+ cancel: function () {
2002
+ this.parent.cancel.apply(this, arguments);
2003
+ this.focusser.prop("disabled", false);
2004
+
2005
+ if (this.opts.shouldFocusInput(this)) {
2006
+ this.focusser.focus();
2007
+ }
2008
+ },
2009
+
2010
+ // single
2011
+ destroy: function() {
2012
+ $("label[for='" + this.focusser.attr('id') + "']")
2013
+ .attr('for', this.opts.element.attr("id"));
2014
+ this.parent.destroy.apply(this, arguments);
2015
+
2016
+ cleanupJQueryElements.call(this,
2017
+ "selection",
2018
+ "focusser"
2019
+ );
2020
+ },
2021
+
2022
+ // single
2023
+ initContainer: function () {
2024
+
2025
+ var selection,
2026
+ container = this.container,
2027
+ dropdown = this.dropdown,
2028
+ idSuffix = nextUid(),
2029
+ elementLabel;
2030
+
2031
+ if (this.opts.minimumResultsForSearch < 0) {
2032
+ this.showSearch(false);
2033
+ } else {
2034
+ this.showSearch(true);
2035
+ }
2036
+
2037
+ this.selection = selection = container.find(".select2-choice");
2038
+
2039
+ this.focusser = container.find(".select2-focusser");
2040
+
2041
+ // add aria associations
2042
+ selection.find(".select2-chosen").attr("id", "select2-chosen-"+idSuffix);
2043
+ this.focusser.attr("aria-labelledby", "select2-chosen-"+idSuffix);
2044
+ this.results.attr("id", "select2-results-"+idSuffix);
2045
+ this.search.attr("aria-owns", "select2-results-"+idSuffix);
2046
+
2047
+ // rewrite labels from original element to focusser
2048
+ this.focusser.attr("id", "s2id_autogen"+idSuffix);
2049
+
2050
+ elementLabel = $("label[for='" + this.opts.element.attr("id") + "']");
2051
+
2052
+ this.focusser.prev()
2053
+ .text(elementLabel.text())
2054
+ .attr('for', this.focusser.attr('id'));
2055
+
2056
+ // Ensure the original element retains an accessible name
2057
+ var originalTitle = this.opts.element.attr("title");
2058
+ this.opts.element.attr("title", (originalTitle || elementLabel.text()));
2059
+
2060
+ this.focusser.attr("tabindex", this.elementTabIndex);
2061
+
2062
+ // write label for search field using the label from the focusser element
2063
+ this.search.attr("id", this.focusser.attr('id') + '_search');
2064
+
2065
+ this.search.prev()
2066
+ .text($("label[for='" + this.focusser.attr('id') + "']").text())
2067
+ .attr('for', this.search.attr('id'));
2068
+
2069
+ this.search.on("keydown", this.bind(function (e) {
2070
+ if (!this.isInterfaceEnabled()) return;
2071
+
2072
+ if (e.which === KEY.PAGE_UP || e.which === KEY.PAGE_DOWN) {
2073
+ // prevent the page from scrolling
2074
+ killEvent(e);
2075
+ return;
2076
+ }
2077
+
2078
+ switch (e.which) {
2079
+ case KEY.UP:
2080
+ case KEY.DOWN:
2081
+ this.moveHighlight((e.which === KEY.UP) ? -1 : 1);
2082
+ killEvent(e);
2083
+ return;
2084
+ case KEY.ENTER:
2085
+ this.selectHighlighted();
2086
+ killEvent(e);
2087
+ return;
2088
+ case KEY.TAB:
2089
+ this.selectHighlighted({noFocus: true});
2090
+ return;
2091
+ case KEY.ESC:
2092
+ this.cancel(e);
2093
+ killEvent(e);
2094
+ return;
2095
+ }
2096
+ }));
2097
+
2098
+ this.search.on("blur", this.bind(function(e) {
2099
+ // a workaround for chrome to keep the search field focussed when the scroll bar is used to scroll the dropdown.
2100
+ // without this the search field loses focus which is annoying
2101
+ if (document.activeElement === this.body.get(0)) {
2102
+ window.setTimeout(this.bind(function() {
2103
+ if (this.opened()) {
2104
+ this.search.focus();
2105
+ }
2106
+ }), 0);
2107
+ }
2108
+ }));
2109
+
2110
+ this.focusser.on("keydown", this.bind(function (e) {
2111
+ if (!this.isInterfaceEnabled()) return;
2112
+
2113
+ if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) {
2114
+ return;
2115
+ }
2116
+
2117
+ if (this.opts.openOnEnter === false && e.which === KEY.ENTER) {
2118
+ killEvent(e);
2119
+ return;
2120
+ }
2121
+
2122
+ if (e.which == KEY.DOWN || e.which == KEY.UP
2123
+ || (e.which == KEY.ENTER && this.opts.openOnEnter)) {
2124
+
2125
+ if (e.altKey || e.ctrlKey || e.shiftKey || e.metaKey) return;
2126
+
2127
+ this.open();
2128
+ killEvent(e);
2129
+ return;
2130
+ }
2131
+
2132
+ if (e.which == KEY.DELETE || e.which == KEY.BACKSPACE) {
2133
+ if (this.opts.allowClear) {
2134
+ this.clear();
2135
+ }
2136
+ killEvent(e);
2137
+ return;
2138
+ }
2139
+ }));
2140
+
2141
+
2142
+ installKeyUpChangeEvent(this.focusser);
2143
+ this.focusser.on("keyup-change input", this.bind(function(e) {
2144
+ if (this.opts.minimumResultsForSearch >= 0) {
2145
+ e.stopPropagation();
2146
+ if (this.opened()) return;
2147
+ this.open();
2148
+ }
2149
+ }));
2150
+
2151
+ selection.on("mousedown touchstart", "abbr", this.bind(function (e) {
2152
+ if (!this.isInterfaceEnabled()) return;
2153
+ this.clear();
2154
+ killEventImmediately(e);
2155
+ this.close();
2156
+ this.selection.focus();
2157
+ }));
2158
+
2159
+ selection.on("mousedown touchstart", this.bind(function (e) {
2160
+ // Prevent IE from generating a click event on the body
2161
+ reinsertElement(selection);
2162
+
2163
+ if (!this.container.hasClass("select2-container-active")) {
2164
+ this.opts.element.trigger($.Event("select2-focus"));
2165
+ }
2166
+
2167
+ if (this.opened()) {
2168
+ this.close();
2169
+ } else if (this.isInterfaceEnabled()) {
2170
+ this.open();
2171
+ }
2172
+
2173
+ killEvent(e);
2174
+ }));
2175
+
2176
+ dropdown.on("mousedown touchstart", this.bind(function() {
2177
+ if (this.opts.shouldFocusInput(this)) {
2178
+ this.search.focus();
2179
+ }
2180
+ }));
2181
+
2182
+ selection.on("focus", this.bind(function(e) {
2183
+ killEvent(e);
2184
+ }));
2185
+
2186
+ this.focusser.on("focus", this.bind(function(){
2187
+ if (!this.container.hasClass("select2-container-active")) {
2188
+ this.opts.element.trigger($.Event("select2-focus"));
2189
+ }
2190
+ this.container.addClass("select2-container-active");
2191
+ })).on("blur", this.bind(function() {
2192
+ if (!this.opened()) {
2193
+ this.container.removeClass("select2-container-active");
2194
+ this.opts.element.trigger($.Event("select2-blur"));
2195
+ }
2196
+ }));
2197
+ this.search.on("focus", this.bind(function(){
2198
+ if (!this.container.hasClass("select2-container-active")) {
2199
+ this.opts.element.trigger($.Event("select2-focus"));
2200
+ }
2201
+ this.container.addClass("select2-container-active");
2202
+ }));
2203
+
2204
+ this.initContainerWidth();
2205
+ this.opts.element.addClass("select2-offscreen");
2206
+ this.setPlaceholder();
2207
+
2208
+ },
2209
+
2210
+ // single
2211
+ clear: function(triggerChange) {
2212
+ var data=this.selection.data("select2-data");
2213
+ if (data) { // guard against queued quick consecutive clicks
2214
+ var evt = $.Event("select2-clearing");
2215
+ this.opts.element.trigger(evt);
2216
+ if (evt.isDefaultPrevented()) {
2217
+ return;
2218
+ }
2219
+ var placeholderOption = this.getPlaceholderOption();
2220
+ this.opts.element.val(placeholderOption ? placeholderOption.val() : "");
2221
+ this.selection.find(".select2-chosen").empty();
2222
+ this.selection.removeData("select2-data");
2223
+ this.setPlaceholder();
2224
+
2225
+ if (triggerChange !== false){
2226
+ this.opts.element.trigger({ type: "select2-removed", val: this.id(data), choice: data });
2227
+ this.triggerChange({removed:data});
2228
+ }
2229
+ }
2230
+ },
2231
+
2232
+ /**
2233
+ * Sets selection based on source element's value
2234
+ */
2235
+ // single
2236
+ initSelection: function () {
2237
+ var selected;
2238
+ if (this.isPlaceholderOptionSelected()) {
2239
+ this.updateSelection(null);
2240
+ this.close();
2241
+ this.setPlaceholder();
2242
+ } else {
2243
+ var self = this;
2244
+ this.opts.initSelection.call(null, this.opts.element, function(selected){
2245
+ if (selected !== undefined && selected !== null) {
2246
+ self.updateSelection(selected);
2247
+ self.close();
2248
+ self.setPlaceholder();
2249
+ self.nextSearchTerm = self.opts.nextSearchTerm(selected, self.search.val());
2250
+ }
2251
+ });
2252
+ }
2253
+ },
2254
+
2255
+ isPlaceholderOptionSelected: function() {
2256
+ var placeholderOption;
2257
+ if (this.getPlaceholder() === undefined) return false; // no placeholder specified so no option should be considered
2258
+ return ((placeholderOption = this.getPlaceholderOption()) !== undefined && placeholderOption.prop("selected"))
2259
+ || (this.opts.element.val() === "")
2260
+ || (this.opts.element.val() === undefined)
2261
+ || (this.opts.element.val() === null);
2262
+ },
2263
+
2264
+ // single
2265
+ prepareOpts: function () {
2266
+ var opts = this.parent.prepareOpts.apply(this, arguments),
2267
+ self=this;
2268
+
2269
+ if (opts.element.get(0).tagName.toLowerCase() === "select") {
2270
+ // install the selection initializer
2271
+ opts.initSelection = function (element, callback) {
2272
+ var selected = element.find("option").filter(function() { return this.selected && !this.disabled });
2273
+ // a single select box always has a value, no need to null check 'selected'
2274
+ callback(self.optionToData(selected));
2275
+ };
2276
+ } else if ("data" in opts) {
2277
+ // install default initSelection when applied to hidden input and data is local
2278
+ opts.initSelection = opts.initSelection || function (element, callback) {
2279
+ var id = element.val();
2280
+ //search in data by id, storing the actual matching item
2281
+ var match = null;
2282
+ opts.query({
2283
+ matcher: function(term, text, el){
2284
+ var is_match = equal(id, opts.id(el));
2285
+ if (is_match) {
2286
+ match = el;
2287
+ }
2288
+ return is_match;
2289
+ },
2290
+ callback: !$.isFunction(callback) ? $.noop : function() {
2291
+ callback(match);
2292
+ }
2293
+ });
2294
+ };
2295
+ }
2296
+
2297
+ return opts;
2298
+ },
2299
+
2300
+ // single
2301
+ getPlaceholder: function() {
2302
+ // if a placeholder is specified on a single select without a valid placeholder option ignore it
2303
+ if (this.select) {
2304
+ if (this.getPlaceholderOption() === undefined) {
2305
+ return undefined;
2306
+ }
2307
+ }
2308
+
2309
+ return this.parent.getPlaceholder.apply(this, arguments);
2310
+ },
2311
+
2312
+ // single
2313
+ setPlaceholder: function () {
2314
+ var placeholder = this.getPlaceholder();
2315
+
2316
+ if (this.isPlaceholderOptionSelected() && placeholder !== undefined) {
2317
+
2318
+ // check for a placeholder option if attached to a select
2319
+ if (this.select && this.getPlaceholderOption() === undefined) return;
2320
+
2321
+ this.selection.find(".select2-chosen").html(this.opts.escapeMarkup(placeholder));
2322
+
2323
+ this.selection.addClass("select2-default");
2324
+
2325
+ this.container.removeClass("select2-allowclear");
2326
+ }
2327
+ },
2328
+
2329
+ // single
2330
+ postprocessResults: function (data, initial, noHighlightUpdate) {
2331
+ var selected = 0, self = this, showSearchInput = true;
2332
+
2333
+ // find the selected element in the result list
2334
+
2335
+ this.findHighlightableChoices().each2(function (i, elm) {
2336
+ if (equal(self.id(elm.data("select2-data")), self.opts.element.val())) {
2337
+ selected = i;
2338
+ return false;
2339
+ }
2340
+ });
2341
+
2342
+ // and highlight it
2343
+ if (noHighlightUpdate !== false) {
2344
+ if (initial === true && selected >= 0) {
2345
+ this.highlight(selected);
2346
+ } else {
2347
+ this.highlight(0);
2348
+ }
2349
+ }
2350
+
2351
+ // hide the search box if this is the first we got the results and there are enough of them for search
2352
+
2353
+ if (initial === true) {
2354
+ var min = this.opts.minimumResultsForSearch;
2355
+ if (min >= 0) {
2356
+ this.showSearch(countResults(data.results) >= min);
2357
+ }
2358
+ }
2359
+ },
2360
+
2361
+ // single
2362
+ showSearch: function(showSearchInput) {
2363
+ if (this.showSearchInput === showSearchInput) return;
2364
+
2365
+ this.showSearchInput = showSearchInput;
2366
+
2367
+ this.dropdown.find(".select2-search").toggleClass("select2-search-hidden", !showSearchInput);
2368
+ this.dropdown.find(".select2-search").toggleClass("select2-offscreen", !showSearchInput);
2369
+ //add "select2-with-searchbox" to the container if search box is shown
2370
+ $(this.dropdown, this.container).toggleClass("select2-with-searchbox", showSearchInput);
2371
+ },
2372
+
2373
+ // single
2374
+ onSelect: function (data, options) {
2375
+
2376
+ if (!this.triggerSelect(data)) { return; }
2377
+
2378
+ var old = this.opts.element.val(),
2379
+ oldData = this.data();
2380
+
2381
+ this.opts.element.val(this.id(data));
2382
+ this.updateSelection(data);
2383
+
2384
+ this.opts.element.trigger({ type: "select2-selected", val: this.id(data), choice: data });
2385
+
2386
+ this.nextSearchTerm = this.opts.nextSearchTerm(data, this.search.val());
2387
+ this.close();
2388
+
2389
+ if ((!options || !options.noFocus) && this.opts.shouldFocusInput(this)) {
2390
+ this.focusser.focus();
2391
+ }
2392
+
2393
+ if (!equal(old, this.id(data))) {
2394
+ this.triggerChange({ added: data, removed: oldData });
2395
+ }
2396
+ },
2397
+
2398
+ // single
2399
+ updateSelection: function (data) {
2400
+
2401
+ var container=this.selection.find(".select2-chosen"), formatted, cssClass;
2402
+
2403
+ this.selection.data("select2-data", data);
2404
+
2405
+ container.empty();
2406
+ if (data !== null) {
2407
+ formatted=this.opts.formatSelection(data, container, this.opts.escapeMarkup);
2408
+ }
2409
+ if (formatted !== undefined) {
2410
+ container.append(formatted);
2411
+ }
2412
+ cssClass=this.opts.formatSelectionCssClass(data, container);
2413
+ if (cssClass !== undefined) {
2414
+ container.addClass(cssClass);
2415
+ }
2416
+
2417
+ this.selection.removeClass("select2-default");
2418
+
2419
+ if (this.opts.allowClear && this.getPlaceholder() !== undefined) {
2420
+ this.container.addClass("select2-allowclear");
2421
+ }
2422
+ },
2423
+
2424
+ // single
2425
+ val: function () {
2426
+ var val,
2427
+ triggerChange = false,
2428
+ data = null,
2429
+ self = this,
2430
+ oldData = this.data();
2431
+
2432
+ if (arguments.length === 0) {
2433
+ return this.opts.element.val();
2434
+ }
2435
+
2436
+ val = arguments[0];
2437
+
2438
+ if (arguments.length > 1) {
2439
+ triggerChange = arguments[1];
2440
+ }
2441
+
2442
+ if (this.select) {
2443
+ this.select
2444
+ .val(val)
2445
+ .find("option").filter(function() { return this.selected }).each2(function (i, elm) {
2446
+ data = self.optionToData(elm);
2447
+ return false;
2448
+ });
2449
+ this.updateSelection(data);
2450
+ this.setPlaceholder();
2451
+ if (triggerChange) {
2452
+ this.triggerChange({added: data, removed:oldData});
2453
+ }
2454
+ } else {
2455
+ // val is an id. !val is true for [undefined,null,'',0] - 0 is legal
2456
+ if (!val && val !== 0) {
2457
+ this.clear(triggerChange);
2458
+ return;
2459
+ }
2460
+ if (this.opts.initSelection === undefined) {
2461
+ throw new Error("cannot call val() if initSelection() is not defined");
2462
+ }
2463
+ this.opts.element.val(val);
2464
+ this.opts.initSelection(this.opts.element, function(data){
2465
+ self.opts.element.val(!data ? "" : self.id(data));
2466
+ self.updateSelection(data);
2467
+ self.setPlaceholder();
2468
+ if (triggerChange) {
2469
+ self.triggerChange({added: data, removed:oldData});
2470
+ }
2471
+ });
2472
+ }
2473
+ },
2474
+
2475
+ // single
2476
+ clearSearch: function () {
2477
+ this.search.val("");
2478
+ this.focusser.val("");
2479
+ },
2480
+
2481
+ // single
2482
+ data: function(value) {
2483
+ var data,
2484
+ triggerChange = false;
2485
+
2486
+ if (arguments.length === 0) {
2487
+ data = this.selection.data("select2-data");
2488
+ if (data == undefined) data = null;
2489
+ return data;
2490
+ } else {
2491
+ if (arguments.length > 1) {
2492
+ triggerChange = arguments[1];
2493
+ }
2494
+ if (!value) {
2495
+ this.clear(triggerChange);
2496
+ } else {
2497
+ data = this.data();
2498
+ this.opts.element.val(!value ? "" : this.id(value));
2499
+ this.updateSelection(value);
2500
+ if (triggerChange) {
2501
+ this.triggerChange({added: value, removed:data});
2502
+ }
2503
+ }
2504
+ }
2505
+ }
2506
+ });
2507
+
2508
+ MultiSelect2 = clazz(AbstractSelect2, {
2509
+
2510
+ // multi
2511
+ createContainer: function () {
2512
+ var container = $(document.createElement("div")).attr({
2513
+ "class": "select2-container select2-container-multi"
2514
+ }).html([
2515
+ "<ul class='select2-choices'>",
2516
+ " <li class='select2-search-field'>",
2517
+ " <label for='' class='select2-offscreen'></label>",
2518
+ " <input type='text' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' class='select2-input'>",
2519
+ " </li>",
2520
+ "</ul>",
2521
+ "<div class='select2-drop select2-drop-multi select2-display-none'>",
2522
+ " <ul class='select2-results'>",
2523
+ " </ul>",
2524
+ "</div>"].join(""));
2525
+ return container;
2526
+ },
2527
+
2528
+ // multi
2529
+ prepareOpts: function () {
2530
+ var opts = this.parent.prepareOpts.apply(this, arguments),
2531
+ self=this;
2532
+
2533
+ // TODO validate placeholder is a string if specified
2534
+
2535
+ if (opts.element.get(0).tagName.toLowerCase() === "select") {
2536
+ // install the selection initializer
2537
+ opts.initSelection = function (element, callback) {
2538
+
2539
+ var data = [];
2540
+
2541
+ element.find("option").filter(function() { return this.selected && !this.disabled }).each2(function (i, elm) {
2542
+ data.push(self.optionToData(elm));
2543
+ });
2544
+ callback(data);
2545
+ };
2546
+ } else if ("data" in opts) {
2547
+ // install default initSelection when applied to hidden input and data is local
2548
+ opts.initSelection = opts.initSelection || function (element, callback) {
2549
+ var ids = splitVal(element.val(), opts.separator);
2550
+ //search in data by array of ids, storing matching items in a list
2551
+ var matches = [];
2552
+ opts.query({
2553
+ matcher: function(term, text, el){
2554
+ var is_match = $.grep(ids, function(id) {
2555
+ return equal(id, opts.id(el));
2556
+ }).length;
2557
+ if (is_match) {
2558
+ matches.push(el);
2559
+ }
2560
+ return is_match;
2561
+ },
2562
+ callback: !$.isFunction(callback) ? $.noop : function() {
2563
+ // reorder matches based on the order they appear in the ids array because right now
2564
+ // they are in the order in which they appear in data array
2565
+ var ordered = [];
2566
+ for (var i = 0; i < ids.length; i++) {
2567
+ var id = ids[i];
2568
+ for (var j = 0; j < matches.length; j++) {
2569
+ var match = matches[j];
2570
+ if (equal(id, opts.id(match))) {
2571
+ ordered.push(match);
2572
+ matches.splice(j, 1);
2573
+ break;
2574
+ }
2575
+ }
2576
+ }
2577
+ callback(ordered);
2578
+ }
2579
+ });
2580
+ };
2581
+ }
2582
+
2583
+ return opts;
2584
+ },
2585
+
2586
+ // multi
2587
+ selectChoice: function (choice) {
2588
+
2589
+ var selected = this.container.find(".select2-search-choice-focus");
2590
+ if (selected.length && choice && choice[0] == selected[0]) {
2591
+
2592
+ } else {
2593
+ if (selected.length) {
2594
+ this.opts.element.trigger("choice-deselected", selected);
2595
+ }
2596
+ selected.removeClass("select2-search-choice-focus");
2597
+ if (choice && choice.length) {
2598
+ this.close();
2599
+ choice.addClass("select2-search-choice-focus");
2600
+ this.opts.element.trigger("choice-selected", choice);
2601
+ }
2602
+ }
2603
+ },
2604
+
2605
+ // multi
2606
+ destroy: function() {
2607
+ $("label[for='" + this.search.attr('id') + "']")
2608
+ .attr('for', this.opts.element.attr("id"));
2609
+ this.parent.destroy.apply(this, arguments);
2610
+
2611
+ cleanupJQueryElements.call(this,
2612
+ "searchContainer",
2613
+ "selection"
2614
+ );
2615
+ },
2616
+
2617
+ // multi
2618
+ initContainer: function () {
2619
+
2620
+ var selector = ".select2-choices", selection;
2621
+
2622
+ this.searchContainer = this.container.find(".select2-search-field");
2623
+ this.selection = selection = this.container.find(selector);
2624
+
2625
+ var _this = this;
2626
+ this.selection.on("click", ".select2-search-choice:not(.select2-locked)", function (e) {
2627
+ //killEvent(e);
2628
+ _this.search[0].focus();
2629
+ _this.selectChoice($(this));
2630
+ });
2631
+
2632
+ // rewrite labels from original element to focusser
2633
+ this.search.attr("id", "s2id_autogen"+nextUid());
2634
+
2635
+ this.search.prev()
2636
+ .text($("label[for='" + this.opts.element.attr("id") + "']").text())
2637
+ .attr('for', this.search.attr('id'));
2638
+
2639
+ this.search.on("input paste", this.bind(function() {
2640
+ if (!this.isInterfaceEnabled()) return;
2641
+ if (!this.opened()) {
2642
+ this.open();
2643
+ }
2644
+ }));
2645
+
2646
+ this.search.attr("tabindex", this.elementTabIndex);
2647
+
2648
+ this.keydowns = 0;
2649
+ this.search.on("keydown", this.bind(function (e) {
2650
+ if (!this.isInterfaceEnabled()) return;
2651
+
2652
+ ++this.keydowns;
2653
+ var selected = selection.find(".select2-search-choice-focus");
2654
+ var prev = selected.prev(".select2-search-choice:not(.select2-locked)");
2655
+ var next = selected.next(".select2-search-choice:not(.select2-locked)");
2656
+ var pos = getCursorInfo(this.search);
2657
+
2658
+ if (selected.length &&
2659
+ (e.which == KEY.LEFT || e.which == KEY.RIGHT || e.which == KEY.BACKSPACE || e.which == KEY.DELETE || e.which == KEY.ENTER)) {
2660
+ var selectedChoice = selected;
2661
+ if (e.which == KEY.LEFT && prev.length) {
2662
+ selectedChoice = prev;
2663
+ }
2664
+ else if (e.which == KEY.RIGHT) {
2665
+ selectedChoice = next.length ? next : null;
2666
+ }
2667
+ else if (e.which === KEY.BACKSPACE) {
2668
+ if (this.unselect(selected.first())) {
2669
+ this.search.width(10);
2670
+ selectedChoice = prev.length ? prev : next;
2671
+ }
2672
+ } else if (e.which == KEY.DELETE) {
2673
+ if (this.unselect(selected.first())) {
2674
+ this.search.width(10);
2675
+ selectedChoice = next.length ? next : null;
2676
+ }
2677
+ } else if (e.which == KEY.ENTER) {
2678
+ selectedChoice = null;
2679
+ }
2680
+
2681
+ this.selectChoice(selectedChoice);
2682
+ killEvent(e);
2683
+ if (!selectedChoice || !selectedChoice.length) {
2684
+ this.open();
2685
+ }
2686
+ return;
2687
+ } else if (((e.which === KEY.BACKSPACE && this.keydowns == 1)
2688
+ || e.which == KEY.LEFT) && (pos.offset == 0 && !pos.length)) {
2689
+
2690
+ this.selectChoice(selection.find(".select2-search-choice:not(.select2-locked)").last());
2691
+ killEvent(e);
2692
+ return;
2693
+ } else {
2694
+ this.selectChoice(null);
2695
+ }
2696
+
2697
+ if (this.opened()) {
2698
+ switch (e.which) {
2699
+ case KEY.UP:
2700
+ case KEY.DOWN:
2701
+ this.moveHighlight((e.which === KEY.UP) ? -1 : 1);
2702
+ killEvent(e);
2703
+ return;
2704
+ case KEY.ENTER:
2705
+ this.selectHighlighted();
2706
+ killEvent(e);
2707
+ return;
2708
+ case KEY.TAB:
2709
+ this.selectHighlighted({noFocus:true});
2710
+ this.close();
2711
+ return;
2712
+ case KEY.ESC:
2713
+ this.cancel(e);
2714
+ killEvent(e);
2715
+ return;
2716
+ }
2717
+ }
2718
+
2719
+ if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e)
2720
+ || e.which === KEY.BACKSPACE || e.which === KEY.ESC) {
2721
+ return;
2722
+ }
2723
+
2724
+ if (e.which === KEY.ENTER) {
2725
+ if (this.opts.openOnEnter === false) {
2726
+ return;
2727
+ } else if (e.altKey || e.ctrlKey || e.shiftKey || e.metaKey) {
2728
+ return;
2729
+ }
2730
+ }
2731
+
2732
+ this.open();
2733
+
2734
+ if (e.which === KEY.PAGE_UP || e.which === KEY.PAGE_DOWN) {
2735
+ // prevent the page from scrolling
2736
+ killEvent(e);
2737
+ }
2738
+
2739
+ if (e.which === KEY.ENTER) {
2740
+ // prevent form from being submitted
2741
+ killEvent(e);
2742
+ }
2743
+
2744
+ }));
2745
+
2746
+ this.search.on("keyup", this.bind(function (e) {
2747
+ this.keydowns = 0;
2748
+ this.resizeSearch();
2749
+ })
2750
+ );
2751
+
2752
+ this.search.on("blur", this.bind(function(e) {
2753
+ this.container.removeClass("select2-container-active");
2754
+ this.search.removeClass("select2-focused");
2755
+ this.selectChoice(null);
2756
+ if (!this.opened()) this.clearSearch();
2757
+ e.stopImmediatePropagation();
2758
+ this.opts.element.trigger($.Event("select2-blur"));
2759
+ }));
2760
+
2761
+ this.container.on("click", selector, this.bind(function (e) {
2762
+ if (!this.isInterfaceEnabled()) return;
2763
+ if ($(e.target).closest(".select2-search-choice").length > 0) {
2764
+ // clicked inside a select2 search choice, do not open
2765
+ return;
2766
+ }
2767
+ this.selectChoice(null);
2768
+ this.clearPlaceholder();
2769
+ if (!this.container.hasClass("select2-container-active")) {
2770
+ this.opts.element.trigger($.Event("select2-focus"));
2771
+ }
2772
+ this.open();
2773
+ this.focusSearch();
2774
+ e.preventDefault();
2775
+ }));
2776
+
2777
+ this.container.on("focus", selector, this.bind(function () {
2778
+ if (!this.isInterfaceEnabled()) return;
2779
+ if (!this.container.hasClass("select2-container-active")) {
2780
+ this.opts.element.trigger($.Event("select2-focus"));
2781
+ }
2782
+ this.container.addClass("select2-container-active");
2783
+ this.dropdown.addClass("select2-drop-active");
2784
+ this.clearPlaceholder();
2785
+ }));
2786
+
2787
+ this.initContainerWidth();
2788
+ this.opts.element.addClass("select2-offscreen");
2789
+
2790
+ // set the placeholder if necessary
2791
+ this.clearSearch();
2792
+ },
2793
+
2794
+ // multi
2795
+ enableInterface: function() {
2796
+ if (this.parent.enableInterface.apply(this, arguments)) {
2797
+ this.search.prop("disabled", !this.isInterfaceEnabled());
2798
+ }
2799
+ },
2800
+
2801
+ // multi
2802
+ initSelection: function () {
2803
+ var data;
2804
+ if (this.opts.element.val() === "" && this.opts.element.text() === "") {
2805
+ this.updateSelection([]);
2806
+ this.close();
2807
+ // set the placeholder if necessary
2808
+ this.clearSearch();
2809
+ }
2810
+ if (this.select || this.opts.element.val() !== "") {
2811
+ var self = this;
2812
+ this.opts.initSelection.call(null, this.opts.element, function(data){
2813
+ if (data !== undefined && data !== null) {
2814
+ self.updateSelection(data);
2815
+ self.close();
2816
+ // set the placeholder if necessary
2817
+ self.clearSearch();
2818
+ }
2819
+ });
2820
+ }
2821
+ },
2822
+
2823
+ // multi
2824
+ clearSearch: function () {
2825
+ var placeholder = this.getPlaceholder(),
2826
+ maxWidth = this.getMaxSearchWidth();
2827
+
2828
+ if (placeholder !== undefined && this.getVal().length === 0 && this.search.hasClass("select2-focused") === false) {
2829
+ this.search.val(placeholder).addClass("select2-default");
2830
+ // stretch the search box to full width of the container so as much of the placeholder is visible as possible
2831
+ // we could call this.resizeSearch(), but we do not because that requires a sizer and we do not want to create one so early because of a firefox bug, see #944
2832
+ this.search.width(maxWidth > 0 ? maxWidth : this.container.css("width"));
2833
+ } else {
2834
+ this.search.val("").width(10);
2835
+ }
2836
+ },
2837
+
2838
+ // multi
2839
+ clearPlaceholder: function () {
2840
+ if (this.search.hasClass("select2-default")) {
2841
+ this.search.val("").removeClass("select2-default");
2842
+ }
2843
+ },
2844
+
2845
+ // multi
2846
+ opening: function () {
2847
+ this.clearPlaceholder(); // should be done before super so placeholder is not used to search
2848
+ this.resizeSearch();
2849
+
2850
+ this.parent.opening.apply(this, arguments);
2851
+
2852
+ this.focusSearch();
2853
+
2854
+ // initializes search's value with nextSearchTerm (if defined by user)
2855
+ // ignore nextSearchTerm if the dropdown is opened by the user pressing a letter
2856
+ if(this.search.val() === "") {
2857
+ if(this.nextSearchTerm != undefined){
2858
+ this.search.val(this.nextSearchTerm);
2859
+ this.search.select();
2860
+ }
2861
+ }
2862
+
2863
+ this.updateResults(true);
2864
+ if (this.opts.shouldFocusInput(this)) {
2865
+ this.search.focus();
2866
+ }
2867
+ this.opts.element.trigger($.Event("select2-open"));
2868
+ },
2869
+
2870
+ // multi
2871
+ close: function () {
2872
+ if (!this.opened()) return;
2873
+ this.parent.close.apply(this, arguments);
2874
+ },
2875
+
2876
+ // multi
2877
+ focus: function () {
2878
+ this.close();
2879
+ this.search.focus();
2880
+ },
2881
+
2882
+ // multi
2883
+ isFocused: function () {
2884
+ return this.search.hasClass("select2-focused");
2885
+ },
2886
+
2887
+ // multi
2888
+ updateSelection: function (data) {
2889
+ var ids = [], filtered = [], self = this;
2890
+
2891
+ // filter out duplicates
2892
+ $(data).each(function () {
2893
+ if (indexOf(self.id(this), ids) < 0) {
2894
+ ids.push(self.id(this));
2895
+ filtered.push(this);
2896
+ }
2897
+ });
2898
+ data = filtered;
2899
+
2900
+ this.selection.find(".select2-search-choice").remove();
2901
+ $(data).each(function () {
2902
+ self.addSelectedChoice(this);
2903
+ });
2904
+ self.postprocessResults();
2905
+ },
2906
+
2907
+ // multi
2908
+ tokenize: function() {
2909
+ var input = this.search.val();
2910
+ input = this.opts.tokenizer.call(this, input, this.data(), this.bind(this.onSelect), this.opts);
2911
+ if (input != null && input != undefined) {
2912
+ this.search.val(input);
2913
+ if (input.length > 0) {
2914
+ this.open();
2915
+ }
2916
+ }
2917
+
2918
+ },
2919
+
2920
+ // multi
2921
+ onSelect: function (data, options) {
2922
+
2923
+ if (!this.triggerSelect(data)) { return; }
2924
+
2925
+ this.addSelectedChoice(data);
2926
+
2927
+ this.opts.element.trigger({ type: "selected", val: this.id(data), choice: data });
2928
+
2929
+ // keep track of the search's value before it gets cleared
2930
+ this.nextSearchTerm = this.opts.nextSearchTerm(data, this.search.val());
2931
+
2932
+ this.clearSearch();
2933
+ this.updateResults();
2934
+
2935
+ if (this.select || !this.opts.closeOnSelect) this.postprocessResults(data, false, this.opts.closeOnSelect===true);
2936
+
2937
+ if (this.opts.closeOnSelect) {
2938
+ this.close();
2939
+ this.search.width(10);
2940
+ } else {
2941
+ if (this.countSelectableResults()>0) {
2942
+ this.search.width(10);
2943
+ this.resizeSearch();
2944
+ if (this.getMaximumSelectionSize() > 0 && this.val().length >= this.getMaximumSelectionSize()) {
2945
+ // if we reached max selection size repaint the results so choices
2946
+ // are replaced with the max selection reached message
2947
+ this.updateResults(true);
2948
+ } else {
2949
+ // initializes search's value with nextSearchTerm and update search result
2950
+ if(this.nextSearchTerm != undefined){
2951
+ this.search.val(this.nextSearchTerm);
2952
+ this.updateResults();
2953
+ this.search.select();
2954
+ }
2955
+ }
2956
+ this.positionDropdown();
2957
+ } else {
2958
+ // if nothing left to select close
2959
+ this.close();
2960
+ this.search.width(10);
2961
+ }
2962
+ }
2963
+
2964
+ // since its not possible to select an element that has already been
2965
+ // added we do not need to check if this is a new element before firing change
2966
+ this.triggerChange({ added: data });
2967
+
2968
+ if (!options || !options.noFocus)
2969
+ this.focusSearch();
2970
+ },
2971
+
2972
+ // multi
2973
+ cancel: function () {
2974
+ this.close();
2975
+ this.focusSearch();
2976
+ },
2977
+
2978
+ addSelectedChoice: function (data) {
2979
+ var enableChoice = !data.locked,
2980
+ enabledItem = $(
2981
+ "<li class='select2-search-choice'>" +
2982
+ " <div></div>" +
2983
+ " <a href='#' class='select2-search-choice-close' tabindex='-1'></a>" +
2984
+ "</li>"),
2985
+ disabledItem = $(
2986
+ "<li class='select2-search-choice select2-locked'>" +
2987
+ "<div></div>" +
2988
+ "</li>");
2989
+ var choice = enableChoice ? enabledItem : disabledItem,
2990
+ id = this.id(data),
2991
+ val = this.getVal(),
2992
+ formatted,
2993
+ cssClass;
2994
+
2995
+ formatted=this.opts.formatSelection(data, choice.find("div"), this.opts.escapeMarkup);
2996
+ if (formatted != undefined) {
2997
+ choice.find("div").replaceWith("<div>"+formatted+"</div>");
2998
+ }
2999
+ cssClass=this.opts.formatSelectionCssClass(data, choice.find("div"));
3000
+ if (cssClass != undefined) {
3001
+ choice.addClass(cssClass);
3002
+ }
3003
+
3004
+ if(enableChoice){
3005
+ choice.find(".select2-search-choice-close")
3006
+ .on("mousedown", killEvent)
3007
+ .on("click dblclick", this.bind(function (e) {
3008
+ if (!this.isInterfaceEnabled()) return;
3009
+
3010
+ this.unselect($(e.target));
3011
+ this.selection.find(".select2-search-choice-focus").removeClass("select2-search-choice-focus");
3012
+ killEvent(e);
3013
+ this.close();
3014
+ this.focusSearch();
3015
+ })).on("focus", this.bind(function () {
3016
+ if (!this.isInterfaceEnabled()) return;
3017
+ this.container.addClass("select2-container-active");
3018
+ this.dropdown.addClass("select2-drop-active");
3019
+ }));
3020
+ }
3021
+
3022
+ choice.data("select2-data", data);
3023
+ choice.insertBefore(this.searchContainer);
3024
+
3025
+ val.push(id);
3026
+ this.setVal(val);
3027
+ },
3028
+
3029
+ // multi
3030
+ unselect: function (selected) {
3031
+ var val = this.getVal(),
3032
+ data,
3033
+ index;
3034
+ selected = selected.closest(".select2-search-choice");
3035
+
3036
+ if (selected.length === 0) {
3037
+ throw "Invalid argument: " + selected + ". Must be .select2-search-choice";
3038
+ }
3039
+
3040
+ data = selected.data("select2-data");
3041
+
3042
+ if (!data) {
3043
+ // prevent a race condition when the 'x' is clicked really fast repeatedly the event can be queued
3044
+ // and invoked on an element already removed
3045
+ return;
3046
+ }
3047
+
3048
+ var evt = $.Event("select2-removing");
3049
+ evt.val = this.id(data);
3050
+ evt.choice = data;
3051
+ this.opts.element.trigger(evt);
3052
+
3053
+ if (evt.isDefaultPrevented()) {
3054
+ return false;
3055
+ }
3056
+
3057
+ while((index = indexOf(this.id(data), val)) >= 0) {
3058
+ val.splice(index, 1);
3059
+ this.setVal(val);
3060
+ if (this.select) this.postprocessResults();
3061
+ }
3062
+
3063
+ selected.remove();
3064
+
3065
+ this.opts.element.trigger({ type: "select2-removed", val: this.id(data), choice: data });
3066
+ this.triggerChange({ removed: data });
3067
+
3068
+ return true;
3069
+ },
3070
+
3071
+ // multi
3072
+ postprocessResults: function (data, initial, noHighlightUpdate) {
3073
+ var val = this.getVal(),
3074
+ choices = this.results.find(".select2-result"),
3075
+ compound = this.results.find(".select2-result-with-children"),
3076
+ self = this;
3077
+
3078
+ choices.each2(function (i, choice) {
3079
+ var id = self.id(choice.data("select2-data"));
3080
+ if (indexOf(id, val) >= 0) {
3081
+ choice.addClass("select2-selected");
3082
+ // mark all children of the selected parent as selected
3083
+ choice.find(".select2-result-selectable").addClass("select2-selected");
3084
+ }
3085
+ });
3086
+
3087
+ compound.each2(function(i, choice) {
3088
+ // hide an optgroup if it doesn't have any selectable children
3089
+ if (!choice.is('.select2-result-selectable')
3090
+ && choice.find(".select2-result-selectable:not(.select2-selected)").length === 0) {
3091
+ choice.addClass("select2-selected");
3092
+ }
3093
+ });
3094
+
3095
+ if (this.highlight() == -1 && noHighlightUpdate !== false){
3096
+ self.highlight(0);
3097
+ }
3098
+
3099
+ //If all results are chosen render formatNoMatches
3100
+ if(!this.opts.createSearchChoice && !choices.filter('.select2-result:not(.select2-selected)').length > 0){
3101
+ if(!data || data && !data.more && this.results.find(".select2-no-results").length === 0) {
3102
+ if (checkFormatter(self.opts.formatNoMatches, "formatNoMatches")) {
3103
+ this.results.append("<li class='select2-no-results'>" + evaluate(self.opts.formatNoMatches, self.search.val()) + "</li>");
3104
+ }
3105
+ }
3106
+ }
3107
+
3108
+ },
3109
+
3110
+ // multi
3111
+ getMaxSearchWidth: function() {
3112
+ return this.selection.width() - getSideBorderPadding(this.search);
3113
+ },
3114
+
3115
+ // multi
3116
+ resizeSearch: function () {
3117
+ var minimumWidth, left, maxWidth, containerLeft, searchWidth,
3118
+ sideBorderPadding = getSideBorderPadding(this.search);
3119
+
3120
+ minimumWidth = measureTextWidth(this.search) + 10;
3121
+
3122
+ left = this.search.offset().left;
3123
+
3124
+ maxWidth = this.selection.width();
3125
+ containerLeft = this.selection.offset().left;
3126
+
3127
+ searchWidth = maxWidth - (left - containerLeft) - sideBorderPadding;
3128
+
3129
+ if (searchWidth < minimumWidth) {
3130
+ searchWidth = maxWidth - sideBorderPadding;
3131
+ }
3132
+
3133
+ if (searchWidth < 40) {
3134
+ searchWidth = maxWidth - sideBorderPadding;
3135
+ }
3136
+
3137
+ if (searchWidth <= 0) {
3138
+ searchWidth = minimumWidth;
3139
+ }
3140
+
3141
+ this.search.width(Math.floor(searchWidth));
3142
+ },
3143
+
3144
+ // multi
3145
+ getVal: function () {
3146
+ var val;
3147
+ if (this.select) {
3148
+ val = this.select.val();
3149
+ return val === null ? [] : val;
3150
+ } else {
3151
+ val = this.opts.element.val();
3152
+ return splitVal(val, this.opts.separator);
3153
+ }
3154
+ },
3155
+
3156
+ // multi
3157
+ setVal: function (val) {
3158
+ var unique;
3159
+ if (this.select) {
3160
+ this.select.val(val);
3161
+ } else {
3162
+ unique = [];
3163
+ // filter out duplicates
3164
+ $(val).each(function () {
3165
+ if (indexOf(this, unique) < 0) unique.push(this);
3166
+ });
3167
+ this.opts.element.val(unique.length === 0 ? "" : unique.join(this.opts.separator));
3168
+ }
3169
+ },
3170
+
3171
+ // multi
3172
+ buildChangeDetails: function (old, current) {
3173
+ var current = current.slice(0),
3174
+ old = old.slice(0);
3175
+
3176
+ // remove intersection from each array
3177
+ for (var i = 0; i < current.length; i++) {
3178
+ for (var j = 0; j < old.length; j++) {
3179
+ if (equal(this.opts.id(current[i]), this.opts.id(old[j]))) {
3180
+ current.splice(i, 1);
3181
+ if(i>0){
3182
+ i--;
3183
+ }
3184
+ old.splice(j, 1);
3185
+ j--;
3186
+ }
3187
+ }
3188
+ }
3189
+
3190
+ return {added: current, removed: old};
3191
+ },
3192
+
3193
+
3194
+ // multi
3195
+ val: function (val, triggerChange) {
3196
+ var oldData, self=this;
3197
+
3198
+ if (arguments.length === 0) {
3199
+ return this.getVal();
3200
+ }
3201
+
3202
+ oldData=this.data();
3203
+ if (!oldData.length) oldData=[];
3204
+
3205
+ // val is an id. !val is true for [undefined,null,'',0] - 0 is legal
3206
+ if (!val && val !== 0) {
3207
+ this.opts.element.val("");
3208
+ this.updateSelection([]);
3209
+ this.clearSearch();
3210
+ if (triggerChange) {
3211
+ this.triggerChange({added: this.data(), removed: oldData});
3212
+ }
3213
+ return;
3214
+ }
3215
+
3216
+ // val is a list of ids
3217
+ this.setVal(val);
3218
+
3219
+ if (this.select) {
3220
+ this.opts.initSelection(this.select, this.bind(this.updateSelection));
3221
+ if (triggerChange) {
3222
+ this.triggerChange(this.buildChangeDetails(oldData, this.data()));
3223
+ }
3224
+ } else {
3225
+ if (this.opts.initSelection === undefined) {
3226
+ throw new Error("val() cannot be called if initSelection() is not defined");
3227
+ }
3228
+
3229
+ this.opts.initSelection(this.opts.element, function(data){
3230
+ var ids=$.map(data, self.id);
3231
+ self.setVal(ids);
3232
+ self.updateSelection(data);
3233
+ self.clearSearch();
3234
+ if (triggerChange) {
3235
+ self.triggerChange(self.buildChangeDetails(oldData, self.data()));
3236
+ }
3237
+ });
3238
+ }
3239
+ this.clearSearch();
3240
+ },
3241
+
3242
+ // multi
3243
+ onSortStart: function() {
3244
+ if (this.select) {
3245
+ throw new Error("Sorting of elements is not supported when attached to <select>. Attach to <input type='hidden'/> instead.");
3246
+ }
3247
+
3248
+ // collapse search field into 0 width so its container can be collapsed as well
3249
+ this.search.width(0);
3250
+ // hide the container
3251
+ this.searchContainer.hide();
3252
+ },
3253
+
3254
+ // multi
3255
+ onSortEnd:function() {
3256
+
3257
+ var val=[], self=this;
3258
+
3259
+ // show search and move it to the end of the list
3260
+ this.searchContainer.show();
3261
+ // make sure the search container is the last item in the list
3262
+ this.searchContainer.appendTo(this.searchContainer.parent());
3263
+ // since we collapsed the width in dragStarted, we resize it here
3264
+ this.resizeSearch();
3265
+
3266
+ // update selection
3267
+ this.selection.find(".select2-search-choice").each(function() {
3268
+ val.push(self.opts.id($(this).data("select2-data")));
3269
+ });
3270
+ this.setVal(val);
3271
+ this.triggerChange();
3272
+ },
3273
+
3274
+ // multi
3275
+ data: function(values, triggerChange) {
3276
+ var self=this, ids, old;
3277
+ if (arguments.length === 0) {
3278
+ return this.selection
3279
+ .children(".select2-search-choice")
3280
+ .map(function() { return $(this).data("select2-data"); })
3281
+ .get();
3282
+ } else {
3283
+ old = this.data();
3284
+ if (!values) { values = []; }
3285
+ ids = $.map(values, function(e) { return self.opts.id(e); });
3286
+ this.setVal(ids);
3287
+ this.updateSelection(values);
3288
+ this.clearSearch();
3289
+ if (triggerChange) {
3290
+ this.triggerChange(this.buildChangeDetails(old, this.data()));
3291
+ }
3292
+ }
3293
+ }
3294
+ });
3295
+
3296
+ $.fn.select2 = function () {
3297
+
3298
+ var args = Array.prototype.slice.call(arguments, 0),
3299
+ opts,
3300
+ select2,
3301
+ method, value, multiple,
3302
+ allowedMethods = ["val", "destroy", "opened", "open", "close", "focus", "isFocused", "container", "dropdown", "onSortStart", "onSortEnd", "enable", "disable", "readonly", "positionDropdown", "data", "search"],
3303
+ valueMethods = ["opened", "isFocused", "container", "dropdown"],
3304
+ propertyMethods = ["val", "data"],
3305
+ methodsMap = { search: "externalSearch" };
3306
+
3307
+ this.each(function () {
3308
+ if (args.length === 0 || typeof(args[0]) === "object") {
3309
+ opts = args.length === 0 ? {} : $.extend({}, args[0]);
3310
+ opts.element = $(this);
3311
+
3312
+ if (opts.element.get(0).tagName.toLowerCase() === "select") {
3313
+ multiple = opts.element.prop("multiple");
3314
+ } else {
3315
+ multiple = opts.multiple || false;
3316
+ if ("tags" in opts) {opts.multiple = multiple = true;}
3317
+ }
3318
+
3319
+ select2 = multiple ? new window.Select2["class"].multi() : new window.Select2["class"].single();
3320
+ select2.init(opts);
3321
+ } else if (typeof(args[0]) === "string") {
3322
+
3323
+ if (indexOf(args[0], allowedMethods) < 0) {
3324
+ throw "Unknown method: " + args[0];
3325
+ }
3326
+
3327
+ value = undefined;
3328
+ select2 = $(this).data("select2");
3329
+ if (select2 === undefined) return;
3330
+
3331
+ method=args[0];
3332
+
3333
+ if (method === "container") {
3334
+ value = select2.container;
3335
+ } else if (method === "dropdown") {
3336
+ value = select2.dropdown;
3337
+ } else {
3338
+ if (methodsMap[method]) method = methodsMap[method];
3339
+
3340
+ value = select2[method].apply(select2, args.slice(1));
3341
+ }
3342
+ if (indexOf(args[0], valueMethods) >= 0
3343
+ || (indexOf(args[0], propertyMethods) >= 0 && args.length == 1)) {
3344
+ return false; // abort the iteration, ready to return first matched value
3345
+ }
3346
+ } else {
3347
+ throw "Invalid arguments to select2 plugin: " + args;
3348
+ }
3349
+ });
3350
+ return (value === undefined) ? this : value;
3351
+ };
3352
+
3353
+ // plugin defaults, accessible to users
3354
+ $.fn.select2.defaults = {
3355
+ width: "copy",
3356
+ loadMorePadding: 0,
3357
+ closeOnSelect: true,
3358
+ openOnEnter: true,
3359
+ containerCss: {},
3360
+ dropdownCss: {},
3361
+ containerCssClass: "",
3362
+ dropdownCssClass: "",
3363
+ formatResult: function(result, container, query, escapeMarkup) {
3364
+ var markup=[];
3365
+ markMatch(result.text, query.term, markup, escapeMarkup);
3366
+ return markup.join("");
3367
+ },
3368
+ formatSelection: function (data, container, escapeMarkup) {
3369
+ return data ? escapeMarkup(data.text) : undefined;
3370
+ },
3371
+ sortResults: function (results, container, query) {
3372
+ return results;
3373
+ },
3374
+ formatResultCssClass: function(data) {return data.css;},
3375
+ formatSelectionCssClass: function(data, container) {return undefined;},
3376
+ formatMatches: function (matches) { return matches + " results are available, use up and down arrow keys to navigate."; },
3377
+ formatNoMatches: function () { return "No matches found"; },
3378
+ formatInputTooShort: function (input, min) { var n = min - input.length; return "Please enter " + n + " or more character" + (n == 1? "" : "s"); },
3379
+ formatInputTooLong: function (input, max) { var n = input.length - max; return "Please delete " + n + " character" + (n == 1? "" : "s"); },
3380
+ formatSelectionTooBig: function (limit) { return "You can only select " + limit + " item" + (limit == 1 ? "" : "s"); },
3381
+ formatLoadMore: function (pageNumber) { return "Loading more results…"; },
3382
+ formatSearching: function () { return "Searching…"; },
3383
+ minimumResultsForSearch: 0,
3384
+ minimumInputLength: 0,
3385
+ maximumInputLength: null,
3386
+ maximumSelectionSize: 0,
3387
+ id: function (e) { return e == undefined ? null : e.id; },
3388
+ matcher: function(term, text) {
3389
+ return stripDiacritics(''+text).toUpperCase().indexOf(stripDiacritics(''+term).toUpperCase()) >= 0;
3390
+ },
3391
+ separator: ",",
3392
+ tokenSeparators: [],
3393
+ tokenizer: defaultTokenizer,
3394
+ escapeMarkup: defaultEscapeMarkup,
3395
+ blurOnChange: false,
3396
+ selectOnBlur: false,
3397
+ adaptContainerCssClass: function(c) { return c; },
3398
+ adaptDropdownCssClass: function(c) { return null; },
3399
+ nextSearchTerm: function(selectedObject, currentSearchTerm) { return undefined; },
3400
+ searchInputPlaceholder: '',
3401
+ createSearchChoicePosition: 'top',
3402
+ shouldFocusInput: function (instance) {
3403
+ // Attempt to detect touch devices
3404
+ var supportsTouchEvents = (('ontouchstart' in window) ||
3405
+ (navigator.msMaxTouchPoints > 0));
3406
+
3407
+ // Only devices which support touch events should be special cased
3408
+ if (!supportsTouchEvents) {
3409
+ return true;
3410
+ }
3411
+
3412
+ // Never focus the input if search is disabled
3413
+ if (instance.opts.minimumResultsForSearch < 0) {
3414
+ return false;
3415
+ }
3416
+
3417
+ return true;
3418
+ }
3419
+ };
3420
+
3421
+ $.fn.select2.ajaxDefaults = {
3422
+ transport: $.ajax,
3423
+ params: {
3424
+ type: "GET",
3425
+ cache: false,
3426
+ dataType: "json"
3427
+ }
3428
+ };
3429
+
3430
+ // exports
3431
+ window.Select2 = {
3432
+ query: {
3433
+ ajax: ajax,
3434
+ local: local,
3435
+ tags: tags
3436
+ }, util: {
3437
+ debounce: debounce,
3438
+ markMatch: markMatch,
3439
+ escapeMarkup: defaultEscapeMarkup,
3440
+ stripDiacritics: stripDiacritics
3441
+ }, "class": {
3442
+ "abstract": AbstractSelect2,
3443
+ "single": SingleSelect2,
3444
+ "multi": MultiSelect2
3445
+ }
3446
+ };
3447
+
3448
+ }(jQuery));