select2.amd.full.js 120 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139
  1. define(['jquery'], function ($) {define('select2/utils',[
  2. 'jquery'
  3. ], function ($) {
  4. var Utils = {};
  5. Utils.Extend = function (ChildClass, SuperClass) {
  6. var __hasProp = {}.hasOwnProperty;
  7. function BaseConstructor () {
  8. this.constructor = ChildClass;
  9. }
  10. for (var key in SuperClass) {
  11. if (__hasProp.call(SuperClass, key)) {
  12. ChildClass[key] = SuperClass[key];
  13. }
  14. }
  15. BaseConstructor.prototype = SuperClass.prototype;
  16. ChildClass.prototype = new BaseConstructor();
  17. ChildClass.__super__ = SuperClass.prototype;
  18. return ChildClass;
  19. };
  20. function getMethods (theClass) {
  21. var proto = theClass.prototype;
  22. var methods = [];
  23. for (var methodName in proto) {
  24. var m = proto[methodName];
  25. if (typeof m !== 'function') {
  26. continue;
  27. }
  28. if (methodName === 'constructor') {
  29. continue;
  30. }
  31. methods.push(methodName);
  32. }
  33. return methods;
  34. }
  35. Utils.Decorate = function (SuperClass, DecoratorClass) {
  36. var decoratedMethods = getMethods(DecoratorClass);
  37. var superMethods = getMethods(SuperClass);
  38. function DecoratedClass () {
  39. var unshift = Array.prototype.unshift;
  40. var argCount = DecoratorClass.prototype.constructor.length;
  41. var calledConstructor = SuperClass.prototype.constructor;
  42. if (argCount > 0) {
  43. unshift.call(arguments, SuperClass.prototype.constructor);
  44. calledConstructor = DecoratorClass.prototype.constructor;
  45. }
  46. calledConstructor.apply(this, arguments);
  47. }
  48. DecoratorClass.displayName = SuperClass.displayName;
  49. function ctr () {
  50. this.constructor = DecoratedClass;
  51. }
  52. DecoratedClass.prototype = new ctr();
  53. for (var m = 0; m < superMethods.length; m++) {
  54. var superMethod = superMethods[m];
  55. DecoratedClass.prototype[superMethod] =
  56. SuperClass.prototype[superMethod];
  57. }
  58. var calledMethod = function (methodName) {
  59. // Stub out the original method if it's not decorating an actual method
  60. var originalMethod = function () {};
  61. if (methodName in DecoratedClass.prototype) {
  62. originalMethod = DecoratedClass.prototype[methodName];
  63. }
  64. var decoratedMethod = DecoratorClass.prototype[methodName];
  65. return function () {
  66. var unshift = Array.prototype.unshift;
  67. unshift.call(arguments, originalMethod);
  68. return decoratedMethod.apply(this, arguments);
  69. };
  70. };
  71. for (var d = 0; d < decoratedMethods.length; d++) {
  72. var decoratedMethod = decoratedMethods[d];
  73. DecoratedClass.prototype[decoratedMethod] = calledMethod(decoratedMethod);
  74. }
  75. return DecoratedClass;
  76. };
  77. var Observable = function () {
  78. this.listeners = {};
  79. };
  80. Observable.prototype.on = function (event, callback) {
  81. this.listeners = this.listeners || {};
  82. if (event in this.listeners) {
  83. this.listeners[event].push(callback);
  84. } else {
  85. this.listeners[event] = [callback];
  86. }
  87. };
  88. Observable.prototype.trigger = function (event) {
  89. var slice = Array.prototype.slice;
  90. this.listeners = this.listeners || {};
  91. if (event in this.listeners) {
  92. this.invoke(this.listeners[event], slice.call(arguments, 1));
  93. }
  94. if ('*' in this.listeners) {
  95. this.invoke(this.listeners['*'], arguments);
  96. }
  97. };
  98. Observable.prototype.invoke = function (listeners, params) {
  99. for (var i = 0, len = listeners.length; i < len; i++) {
  100. listeners[i].apply(this, params);
  101. }
  102. };
  103. Utils.Observable = Observable;
  104. Utils.generateChars = function (length) {
  105. var chars = '';
  106. for (var i = 0; i < length; i++) {
  107. var randomChar = Math.floor(Math.random() * 36);
  108. chars += randomChar.toString(36);
  109. }
  110. return chars;
  111. };
  112. Utils.bind = function (func, context) {
  113. return function () {
  114. func.apply(context, arguments);
  115. };
  116. };
  117. Utils._convertData = function (data) {
  118. for (var originalKey in data) {
  119. var keys = originalKey.split('-');
  120. var dataLevel = data;
  121. if (keys.length === 1) {
  122. continue;
  123. }
  124. for (var k = 0; k < keys.length; k++) {
  125. var key = keys[k];
  126. // Lowercase the first letter
  127. // By default, dash-separated becomes camelCase
  128. key = key.substring(0, 1).toLowerCase() + key.substring(1);
  129. if (!(key in dataLevel)) {
  130. dataLevel[key] = {};
  131. }
  132. if (k == keys.length - 1) {
  133. dataLevel[key] = data[originalKey];
  134. }
  135. dataLevel = dataLevel[key];
  136. }
  137. delete data[originalKey];
  138. }
  139. return data;
  140. };
  141. Utils.hasScroll = function (index, el) {
  142. // Adapted from the function created by @ShadowScripter
  143. // and adapted by @BillBarry on the Stack Exchange Code Review website.
  144. // The original code can be found at
  145. // http://codereview.stackexchange.com/q/13338
  146. // and was designed to be used with the Sizzle selector engine.
  147. var $el = $(el);
  148. var overflowX = el.style.overflowX;
  149. var overflowY = el.style.overflowY;
  150. //Check both x and y declarations
  151. if (overflowX === overflowY &&
  152. (overflowY === 'hidden' || overflowY === 'visible')) {
  153. return false;
  154. }
  155. if (overflowX === 'scroll' || overflowY === 'scroll') {
  156. return true;
  157. }
  158. return ($el.innerHeight() < el.scrollHeight ||
  159. $el.innerWidth() < el.scrollWidth);
  160. };
  161. Utils.escapeMarkup = function (markup) {
  162. var replaceMap = {
  163. '\\': '&#92;',
  164. '&': '&amp;',
  165. '<': '&lt;',
  166. '>': '&gt;',
  167. '"': '&quot;',
  168. '\'': '&#39;',
  169. '/': '&#47;'
  170. };
  171. // Do not try to escape the markup if it's not a string
  172. if (typeof markup !== 'string') {
  173. return markup;
  174. }
  175. return String(markup).replace(/[&<>"'\/\\]/g, function (match) {
  176. return replaceMap[match];
  177. });
  178. };
  179. return Utils;
  180. });
  181. define('select2/results',[
  182. 'jquery',
  183. './utils'
  184. ], function ($, Utils) {
  185. function Results ($element, options, dataAdapter) {
  186. this.$element = $element;
  187. this.data = dataAdapter;
  188. this.options = options;
  189. Results.__super__.constructor.call(this);
  190. }
  191. Utils.Extend(Results, Utils.Observable);
  192. Results.prototype.render = function () {
  193. var $results = $(
  194. '<ul class="select2-results__options" role="tree"></ul>'
  195. );
  196. if (this.options.get('multiple')) {
  197. $results.attr('aria-multiselectable', 'true');
  198. }
  199. this.$results = $results;
  200. return $results;
  201. };
  202. Results.prototype.clear = function () {
  203. this.$results.empty();
  204. };
  205. Results.prototype.displayMessage = function (params) {
  206. var escapeMarkup = this.options.get('escapeMarkup');
  207. this.clear();
  208. this.hideLoading();
  209. var $message = $(
  210. '<li role="treeitem" class="select2-results__option"></li>'
  211. );
  212. var message = this.options.get('translations').get(params.message);
  213. $message.append(
  214. escapeMarkup(
  215. message(params.args)
  216. )
  217. );
  218. this.$results.append($message);
  219. };
  220. Results.prototype.append = function (data) {
  221. this.hideLoading();
  222. var $options = [];
  223. if (data.results == null || data.results.length === 0) {
  224. if (this.$results.children().length === 0) {
  225. this.trigger('results:message', {
  226. message: 'noResults'
  227. });
  228. }
  229. return;
  230. }
  231. data.results = this.sort(data.results);
  232. for (var d = 0; d < data.results.length; d++) {
  233. var item = data.results[d];
  234. var $option = this.option(item);
  235. $options.push($option);
  236. }
  237. this.$results.append($options);
  238. };
  239. Results.prototype.position = function ($results, $dropdown) {
  240. var $resultsContainer = $dropdown.find('.select2-results');
  241. $resultsContainer.append($results);
  242. };
  243. Results.prototype.sort = function (data) {
  244. var sorter = this.options.get('sorter');
  245. return sorter(data);
  246. };
  247. Results.prototype.setClasses = function () {
  248. var self = this;
  249. this.data.current(function (selected) {
  250. var selectedIds = $.map(selected, function (s) {
  251. return s.id.toString();
  252. });
  253. var $options = self.$results
  254. .find('.select2-results__option[aria-selected]');
  255. $options.each(function () {
  256. var $option = $(this);
  257. var item = $.data(this, 'data');
  258. if ($.inArray(item.id, selectedIds) > -1) {
  259. $option.attr('aria-selected', 'true');
  260. } else {
  261. $option.attr('aria-selected', 'false');
  262. }
  263. });
  264. var $selected = $options.filter('[aria-selected=true]');
  265. // Check if there are any selected options
  266. if ($selected.length > 0) {
  267. // If there are selected options, highlight the first
  268. $selected.first().trigger('mouseenter');
  269. } else {
  270. // If there are no selected options, highlight the first option
  271. // in the dropdown
  272. $options.first().trigger('mouseenter');
  273. }
  274. });
  275. };
  276. Results.prototype.showLoading = function (params) {
  277. this.hideLoading();
  278. var loadingMore = this.options.get('translations').get('searching');
  279. var loading = {
  280. disabled: true,
  281. loading: true,
  282. text: loadingMore(params)
  283. };
  284. var $loading = this.option(loading);
  285. $loading.className += ' loading-results';
  286. this.$results.prepend($loading);
  287. };
  288. Results.prototype.hideLoading = function () {
  289. this.$results.find('.loading-results').remove();
  290. };
  291. Results.prototype.option = function (data) {
  292. var option = document.createElement('li');
  293. option.className = 'select2-results__option';
  294. var attrs = {
  295. 'role': 'treeitem',
  296. 'aria-selected': 'false'
  297. };
  298. if (data.disabled) {
  299. delete attrs['aria-selected'];
  300. attrs['aria-disabled'] = 'true';
  301. }
  302. if (data.id == null) {
  303. delete attrs['aria-selected'];
  304. }
  305. if (data._resultId != null) {
  306. option.id = data._resultId;
  307. }
  308. if (data.title) {
  309. option.title = data.title;
  310. }
  311. if (data.children) {
  312. attrs.role = 'group';
  313. attrs['aria-label'] = data.text;
  314. delete attrs['aria-selected'];
  315. }
  316. for (var attr in attrs) {
  317. var val = attrs[attr];
  318. option.setAttribute(attr, val);
  319. }
  320. if (data.children) {
  321. var $option = $(option);
  322. var label = document.createElement('strong');
  323. label.className = 'select2-results__group';
  324. var $label = $(label);
  325. this.template(data, label);
  326. var $children = [];
  327. for (var c = 0; c < data.children.length; c++) {
  328. var child = data.children[c];
  329. var $child = this.option(child);
  330. $children.push($child);
  331. }
  332. var $childrenContainer = $('<ul></ul>', {
  333. 'class': 'select2-results__options select2-results__options--nested'
  334. });
  335. $childrenContainer.append($children);
  336. $option.append(label);
  337. $option.append($childrenContainer);
  338. } else {
  339. this.template(data, option);
  340. }
  341. $.data(option, 'data', data);
  342. return option;
  343. };
  344. Results.prototype.bind = function (container, $container) {
  345. var self = this;
  346. var id = container.id + '-results';
  347. this.$results.attr('id', id);
  348. container.on('results:all', function (params) {
  349. self.clear();
  350. self.append(params.data);
  351. if (container.isOpen()) {
  352. self.setClasses();
  353. }
  354. });
  355. container.on('results:append', function (params) {
  356. self.append(params.data);
  357. if (container.isOpen()) {
  358. self.setClasses();
  359. }
  360. });
  361. container.on('query', function (params) {
  362. self.showLoading(params);
  363. });
  364. container.on('select', function () {
  365. if (!container.isOpen()) {
  366. return;
  367. }
  368. self.setClasses();
  369. });
  370. container.on('unselect', function () {
  371. if (!container.isOpen()) {
  372. return;
  373. }
  374. self.setClasses();
  375. });
  376. container.on('open', function () {
  377. // When the dropdown is open, aria-expended="true"
  378. self.$results.attr('aria-expanded', 'true');
  379. self.$results.attr('aria-hidden', 'false');
  380. self.setClasses();
  381. self.ensureHighlightVisible();
  382. });
  383. container.on('close', function () {
  384. // When the dropdown is closed, aria-expended="false"
  385. self.$results.attr('aria-expanded', 'false');
  386. self.$results.attr('aria-hidden', 'true');
  387. self.$results.removeAttr('aria-activedescendant');
  388. });
  389. container.on('results:select', function () {
  390. var $highlighted = self.getHighlightedResults();
  391. if ($highlighted.length === 0) {
  392. return;
  393. }
  394. var data = $highlighted.data('data');
  395. if ($highlighted.attr('aria-selected') == 'true') {
  396. if (self.options.get('multiple')) {
  397. self.trigger('unselect', {
  398. data: data
  399. });
  400. } else {
  401. self.trigger('close');
  402. }
  403. } else {
  404. self.trigger('select', {
  405. data: data
  406. });
  407. }
  408. });
  409. container.on('results:previous', function () {
  410. var $highlighted = self.getHighlightedResults();
  411. var $options = self.$results.find('[aria-selected]');
  412. var currentIndex = $options.index($highlighted);
  413. // If we are already at te top, don't move further
  414. if (currentIndex === 0) {
  415. return;
  416. }
  417. var nextIndex = currentIndex - 1;
  418. // If none are highlighted, highlight the first
  419. if ($highlighted.length === 0) {
  420. nextIndex = 0;
  421. }
  422. var $next = $options.eq(nextIndex);
  423. $next.trigger('mouseenter');
  424. var currentOffset = self.$results.offset().top;
  425. var nextTop = $next.offset().top;
  426. var nextOffset = self.$results.scrollTop() + (nextTop - currentOffset);
  427. if (nextIndex === 0) {
  428. self.$results.scrollTop(0);
  429. } else if (nextTop - currentOffset < 0) {
  430. self.$results.scrollTop(nextOffset);
  431. }
  432. });
  433. container.on('results:next', function () {
  434. var $highlighted = self.getHighlightedResults();
  435. var $options = self.$results.find('[aria-selected]');
  436. var currentIndex = $options.index($highlighted);
  437. var nextIndex = currentIndex + 1;
  438. // If we are at the last option, stay there
  439. if (nextIndex >= $options.length) {
  440. return;
  441. }
  442. var $next = $options.eq(nextIndex);
  443. $next.trigger('mouseenter');
  444. var currentOffset = self.$results.offset().top +
  445. self.$results.outerHeight(false);
  446. var nextBottom = $next.offset().top + $next.outerHeight(false);
  447. var nextOffset = self.$results.scrollTop() + nextBottom - currentOffset;
  448. if (nextIndex === 0) {
  449. self.$results.scrollTop(0);
  450. } else if (nextBottom > currentOffset) {
  451. self.$results.scrollTop(nextOffset);
  452. }
  453. });
  454. container.on('results:focus', function (params) {
  455. params.element.addClass('select2-results__option--highlighted');
  456. });
  457. container.on('results:message', function (params) {
  458. self.displayMessage(params);
  459. });
  460. if ($.fn.mousewheel) {
  461. this.$results.on('mousewheel', function (e) {
  462. var top = self.$results.scrollTop();
  463. var bottom = (
  464. self.$results.get(0).scrollHeight -
  465. self.$results.scrollTop() +
  466. e.deltaY
  467. );
  468. var isAtTop = e.deltaY > 0 && top - e.deltaY <= 0;
  469. var isAtBottom = e.deltaY < 0 && bottom <= self.$results.height();
  470. if (isAtTop) {
  471. self.$results.scrollTop(0);
  472. e.preventDefault();
  473. e.stopPropagation();
  474. } else if (isAtBottom) {
  475. self.$results.scrollTop(
  476. self.$results.get(0).scrollHeight - self.$results.height()
  477. );
  478. e.preventDefault();
  479. e.stopPropagation();
  480. }
  481. });
  482. }
  483. this.$results.on('mouseup', '.select2-results__option[aria-selected]',
  484. function (evt) {
  485. var $this = $(this);
  486. var data = $this.data('data');
  487. if ($this.attr('aria-selected') === 'true') {
  488. if (self.options.get('multiple')) {
  489. self.trigger('unselect', {
  490. originalEvent: evt,
  491. data: data
  492. });
  493. } else {
  494. self.trigger('close');
  495. }
  496. return;
  497. }
  498. self.trigger('select', {
  499. originalEvent: evt,
  500. data: data
  501. });
  502. });
  503. this.$results.on('mouseenter', '.select2-results__option[aria-selected]',
  504. function (evt) {
  505. var data = $(this).data('data');
  506. self.getHighlightedResults()
  507. .removeClass('select2-results__option--highlighted');
  508. self.trigger('results:focus', {
  509. data: data,
  510. element: $(this)
  511. });
  512. });
  513. };
  514. Results.prototype.getHighlightedResults = function () {
  515. var $highlighted = this.$results
  516. .find('.select2-results__option--highlighted');
  517. return $highlighted;
  518. };
  519. Results.prototype.destroy = function () {
  520. this.$results.remove();
  521. };
  522. Results.prototype.ensureHighlightVisible = function () {
  523. var $highlighted = this.getHighlightedResults();
  524. if ($highlighted.length === 0) {
  525. return;
  526. }
  527. var $options = this.$results.find('[aria-selected]');
  528. var currentIndex = $options.index($highlighted);
  529. var currentOffset = this.$results.offset().top;
  530. var nextTop = $highlighted.offset().top;
  531. var nextOffset = this.$results.scrollTop() + (nextTop - currentOffset);
  532. var offsetDelta = nextTop - currentOffset;
  533. nextOffset -= $highlighted.outerHeight(false) * 2;
  534. if (currentIndex <= 2) {
  535. this.$results.scrollTop(0);
  536. } else if (offsetDelta > this.$results.outerHeight() || offsetDelta < 0) {
  537. this.$results.scrollTop(nextOffset);
  538. }
  539. };
  540. Results.prototype.template = function (result, container) {
  541. var template = this.options.get('templateResult');
  542. var escapeMarkup = this.options.get('escapeMarkup');
  543. var content = template(result);
  544. if (content == null) {
  545. container.style.display = 'none';
  546. } else if (typeof content === 'string') {
  547. container.innerHTML = escapeMarkup(content);
  548. } else {
  549. $(container).append(content);
  550. }
  551. };
  552. return Results;
  553. });
  554. define('select2/keys',[
  555. ], function () {
  556. var KEYS = {
  557. BACKSPACE: 8,
  558. TAB: 9,
  559. ENTER: 13,
  560. SHIFT: 16,
  561. CTRL: 17,
  562. ALT: 18,
  563. ESC: 27,
  564. SPACE: 32,
  565. PAGE_UP: 33,
  566. PAGE_DOWN: 34,
  567. END: 35,
  568. HOME: 36,
  569. LEFT: 37,
  570. UP: 38,
  571. RIGHT: 39,
  572. DOWN: 40,
  573. DELETE: 46
  574. };
  575. return KEYS;
  576. });
  577. define('select2/selection/base',[
  578. 'jquery',
  579. '../utils',
  580. '../keys'
  581. ], function ($, Utils, KEYS) {
  582. function BaseSelection ($element, options) {
  583. this.$element = $element;
  584. this.options = options;
  585. BaseSelection.__super__.constructor.call(this);
  586. }
  587. Utils.Extend(BaseSelection, Utils.Observable);
  588. BaseSelection.prototype.render = function () {
  589. var $selection = $(
  590. '<span class="select2-selection" role="combobox" ' +
  591. 'aria-autocomplete="list" aria-haspopup="true" aria-expanded="false">' +
  592. '</span>'
  593. );
  594. this._tabindex = 0;
  595. if (this.$element.data('old-tabindex') != null) {
  596. this._tabindex = this.$element.data('old-tabindex');
  597. } else if (this.$element.attr('tabindex') != null) {
  598. this._tabindex = this.$element.attr('tabindex');
  599. }
  600. $selection.attr('title', this.$element.attr('title'));
  601. $selection.attr('tabindex', this._tabindex);
  602. this.$selection = $selection;
  603. return $selection;
  604. };
  605. BaseSelection.prototype.bind = function (container, $container) {
  606. var self = this;
  607. var id = container.id + '-container';
  608. var resultsId = container.id + '-results';
  609. this.container = container;
  610. this.$selection.attr('aria-owns', resultsId);
  611. this.$selection.on('focus', function (evt) {
  612. self.trigger('focus', evt);
  613. });
  614. this.$selection.on('blur', function (evt) {
  615. self.trigger('blur', evt);
  616. });
  617. this.$selection.on('keydown', function (evt) {
  618. self.trigger('keypress', evt);
  619. if (evt.which === KEYS.SPACE) {
  620. evt.preventDefault();
  621. }
  622. });
  623. container.on('results:focus', function (params) {
  624. self.$selection.attr('aria-activedescendant', params.data._resultId);
  625. });
  626. container.on('selection:update', function (params) {
  627. self.update(params.data);
  628. });
  629. container.on('open', function () {
  630. // When the dropdown is open, aria-expanded="true"
  631. self.$selection.attr('aria-expanded', 'true');
  632. self._attachCloseHandler(container);
  633. });
  634. container.on('close', function () {
  635. // When the dropdown is closed, aria-expanded="false"
  636. self.$selection.attr('aria-expanded', 'false');
  637. self.$selection.removeAttr('aria-activedescendant');
  638. self.$selection.focus();
  639. self._detachCloseHandler(container);
  640. });
  641. container.on('enable', function () {
  642. self.$selection.attr('tabindex', self._tabindex);
  643. });
  644. container.on('disable', function () {
  645. self.$selection.attr('tabindex', '-1');
  646. });
  647. };
  648. BaseSelection.prototype._attachCloseHandler = function (container) {
  649. var self = this;
  650. $(document.body).on('mousedown.select2.' + container.id, function (e) {
  651. var $target = $(e.target);
  652. var $select = $target.closest('.select2');
  653. var $all = $('.select2.select2-container--open');
  654. $all.each(function () {
  655. var $this = $(this);
  656. if (this == $select[0]) {
  657. return;
  658. }
  659. var $element = $this.data('element');
  660. $element.select2('close');
  661. });
  662. });
  663. };
  664. BaseSelection.prototype._detachCloseHandler = function (container) {
  665. $(document.body).off('mousedown.select2.' + container.id);
  666. };
  667. BaseSelection.prototype.position = function ($selection, $container) {
  668. var $selectionContainer = $container.find('.selection');
  669. $selectionContainer.append($selection);
  670. };
  671. BaseSelection.prototype.destroy = function () {
  672. this._detachCloseHandler(this.container);
  673. };
  674. BaseSelection.prototype.update = function (data) {
  675. throw new Error('The `update` method must be defined in child classes.');
  676. };
  677. return BaseSelection;
  678. });
  679. define('select2/selection/single',[
  680. 'jquery',
  681. './base',
  682. '../utils',
  683. '../keys'
  684. ], function ($, BaseSelection, Utils, KEYS) {
  685. function SingleSelection () {
  686. SingleSelection.__super__.constructor.apply(this, arguments);
  687. }
  688. Utils.Extend(SingleSelection, BaseSelection);
  689. SingleSelection.prototype.render = function () {
  690. var $selection = SingleSelection.__super__.render.call(this);
  691. $selection.addClass('select2-selection--single');
  692. $selection.html(
  693. '<span class="select2-selection__rendered"></span>' +
  694. '<span class="select2-selection__arrow" role="presentation">' +
  695. '<b role="presentation"></b>' +
  696. '</span>'
  697. );
  698. return $selection;
  699. };
  700. SingleSelection.prototype.bind = function (container, $container) {
  701. var self = this;
  702. SingleSelection.__super__.bind.apply(this, arguments);
  703. var id = container.id + '-container';
  704. this.$selection.find('.select2-selection__rendered').attr('id', id);
  705. this.$selection.attr('aria-labelledby', id);
  706. this.$selection.on('mousedown', function (evt) {
  707. // Only respond to left clicks
  708. if (evt.which !== 1) {
  709. return;
  710. }
  711. self.trigger('toggle', {
  712. originalEvent: evt
  713. });
  714. });
  715. this.$selection.on('focus', function (evt) {
  716. // User focuses on the container
  717. });
  718. this.$selection.on('blur', function (evt) {
  719. // User exits the container
  720. });
  721. container.on('selection:update', function (params) {
  722. self.update(params.data);
  723. });
  724. };
  725. SingleSelection.prototype.clear = function () {
  726. this.$selection.find('.select2-selection__rendered').empty();
  727. };
  728. SingleSelection.prototype.display = function (data) {
  729. var template = this.options.get('templateSelection');
  730. var escapeMarkup = this.options.get('escapeMarkup');
  731. return escapeMarkup(template(data));
  732. };
  733. SingleSelection.prototype.selectionContainer = function () {
  734. return $('<span></span>');
  735. };
  736. SingleSelection.prototype.update = function (data) {
  737. if (data.length === 0) {
  738. this.clear();
  739. return;
  740. }
  741. var selection = data[0];
  742. var formatted = this.display(selection);
  743. var $rendered = this.$selection.find('.select2-selection__rendered');
  744. $rendered.empty().append(formatted);
  745. $rendered.prop('title', selection.title || selection.text);
  746. };
  747. return SingleSelection;
  748. });
  749. define('select2/selection/multiple',[
  750. 'jquery',
  751. './base',
  752. '../utils'
  753. ], function ($, BaseSelection, Utils) {
  754. function MultipleSelection ($element, options) {
  755. MultipleSelection.__super__.constructor.apply(this, arguments);
  756. }
  757. Utils.Extend(MultipleSelection, BaseSelection);
  758. MultipleSelection.prototype.render = function () {
  759. var $selection = MultipleSelection.__super__.render.call(this);
  760. $selection.addClass('select2-selection--multiple');
  761. $selection.html(
  762. '<ul class="select2-selection__rendered"></ul>'
  763. );
  764. return $selection;
  765. };
  766. MultipleSelection.prototype.bind = function (container, $container) {
  767. var self = this;
  768. MultipleSelection.__super__.bind.apply(this, arguments);
  769. this.$selection.on('click', function (evt) {
  770. self.trigger('toggle', {
  771. originalEvent: evt
  772. });
  773. });
  774. this.$selection.on('click', '.select2-selection__choice__remove',
  775. function (evt) {
  776. var $remove = $(this);
  777. var $selection = $remove.parent();
  778. var data = $selection.data('data');
  779. self.trigger('unselect', {
  780. originalEvent: evt,
  781. data: data
  782. });
  783. });
  784. };
  785. MultipleSelection.prototype.clear = function () {
  786. this.$selection.find('.select2-selection__rendered').empty();
  787. };
  788. MultipleSelection.prototype.display = function (data) {
  789. var template = this.options.get('templateSelection');
  790. var escapeMarkup = this.options.get('escapeMarkup');
  791. return escapeMarkup(template(data));
  792. };
  793. MultipleSelection.prototype.selectionContainer = function () {
  794. var $container = $(
  795. '<li class="select2-selection__choice">' +
  796. '<span class="select2-selection__choice__remove" role="presentation">' +
  797. '&times;' +
  798. '</span>' +
  799. '</li>'
  800. );
  801. return $container;
  802. };
  803. MultipleSelection.prototype.update = function (data) {
  804. this.clear();
  805. if (data.length === 0) {
  806. return;
  807. }
  808. var $selections = [];
  809. for (var d = 0; d < data.length; d++) {
  810. var selection = data[d];
  811. var formatted = this.display(selection);
  812. var $selection = this.selectionContainer();
  813. $selection.append(formatted);
  814. $selection.prop('title', selection.title);
  815. $selection.data('data', selection);
  816. $selections.push($selection);
  817. }
  818. this.$selection.find('.select2-selection__rendered').append($selections);
  819. };
  820. return MultipleSelection;
  821. });
  822. define('select2/selection/placeholder',[
  823. '../utils'
  824. ], function (Utils) {
  825. function Placeholder (decorated, $element, options) {
  826. this.placeholder = this.normalizePlaceholder(options.get('placeholder'));
  827. decorated.call(this, $element, options);
  828. }
  829. Placeholder.prototype.normalizePlaceholder = function (_, placeholder) {
  830. if (typeof placeholder === 'string') {
  831. placeholder = {
  832. id: '',
  833. text: placeholder
  834. };
  835. }
  836. return placeholder;
  837. };
  838. Placeholder.prototype.createPlaceholder = function (decorated, placeholder) {
  839. var $placeholder = this.selectionContainer();
  840. $placeholder.html(this.display(placeholder));
  841. $placeholder.addClass('select2-selection__placeholder')
  842. .removeClass('select2-selection__choice');
  843. return $placeholder;
  844. };
  845. Placeholder.prototype.update = function (decorated, data) {
  846. var singlePlaceholder = (
  847. data.length == 1 && data[0].id != this.placeholder.id
  848. );
  849. var multipleSelections = data.length > 1;
  850. if (multipleSelections || singlePlaceholder) {
  851. return decorated.call(this, data);
  852. }
  853. this.clear();
  854. var $placeholder = this.createPlaceholder(this.placeholder);
  855. this.$selection.find('.select2-selection__rendered').append($placeholder);
  856. };
  857. return Placeholder;
  858. });
  859. define('select2/selection/allowClear',[
  860. 'jquery'
  861. ], function ($) {
  862. function AllowClear () { }
  863. AllowClear.prototype.bind = function (decorated, container, $container) {
  864. var self = this;
  865. decorated.call(this, container, $container);
  866. if (self.placeholder == null) {
  867. if (window.console && console.error) {
  868. console.error(
  869. 'Select2: The `allowClear` option should be used in combination ' +
  870. 'with the `placeholder` option.'
  871. );
  872. }
  873. }
  874. this.$selection.on('mousedown', '.select2-selection__clear',
  875. function (evt) {
  876. // Ignore the event if it is disabled
  877. if (self.options.get('disabled')) {
  878. return;
  879. }
  880. evt.stopPropagation();
  881. var data = $(this).data('data');
  882. for (var d = 0; d < data.length; d++) {
  883. var unselectData = {
  884. data: data[d]
  885. };
  886. // Trigger the `unselect` event, so people can prevent it from being
  887. // cleared.
  888. self.trigger('unselect', unselectData);
  889. // If the event was prevented, don't clear it out.
  890. if (unselectData.prevented) {
  891. return;
  892. }
  893. }
  894. self.$element.val(self.placeholder.id).trigger('change');
  895. self.trigger('toggle');
  896. });
  897. };
  898. AllowClear.prototype.update = function (decorated, data) {
  899. decorated.call(this, data);
  900. if (this.$selection.find('.select2-selection__placeholder').length > 0 ||
  901. data.length === 0) {
  902. return;
  903. }
  904. var $remove = $(
  905. '<span class="select2-selection__clear">' +
  906. '&times;' +
  907. '</span>'
  908. );
  909. $remove.data('data', data);
  910. this.$selection.find('.select2-selection__rendered').append($remove);
  911. };
  912. return AllowClear;
  913. });
  914. define('select2/selection/search',[
  915. 'jquery',
  916. '../utils',
  917. '../keys'
  918. ], function ($, Utils, KEYS) {
  919. function Search (decorated, $element, options) {
  920. decorated.call(this, $element, options);
  921. }
  922. Search.prototype.render = function (decorated) {
  923. var $search = $(
  924. '<li class="select2-search select2-search--inline">' +
  925. '<input class="select2-search__field" type="search" tabindex="-1"' +
  926. ' autocomplete="off" autocorrect="off" autocapitalize="off"' +
  927. ' spellcheck="false" role="textbox" />' +
  928. '</li>'
  929. );
  930. this.$searchContainer = $search;
  931. this.$search = $search.find('input');
  932. var $rendered = decorated.call(this);
  933. return $rendered;
  934. };
  935. Search.prototype.bind = function (decorated, container, $container) {
  936. var self = this;
  937. decorated.call(this, container, $container);
  938. container.on('open', function () {
  939. self.$search.attr('tabindex', 0);
  940. self.$search.focus();
  941. });
  942. container.on('close', function () {
  943. self.$search.attr('tabindex', -1);
  944. self.$search.val('');
  945. self.$search.focus();
  946. });
  947. container.on('enable', function () {
  948. self.$search.prop('disabled', false);
  949. });
  950. container.on('disable', function () {
  951. self.$search.prop('disabled', true);
  952. });
  953. this.$selection.on('focusin', '.select2-search--inline', function (evt) {
  954. self.trigger('focus', evt);
  955. });
  956. this.$selection.on('focusout', '.select2-search--inline', function (evt) {
  957. self.trigger('blur', evt);
  958. });
  959. this.$selection.on('keydown', '.select2-search--inline', function (evt) {
  960. evt.stopPropagation();
  961. self.trigger('keypress', evt);
  962. self._keyUpPrevented = evt.isDefaultPrevented();
  963. var key = evt.which;
  964. if (key === KEYS.BACKSPACE && self.$search.val() === '') {
  965. var $previousChoice = self.$searchContainer
  966. .prev('.select2-selection__choice');
  967. if ($previousChoice.length > 0) {
  968. var item = $previousChoice.data('data');
  969. self.searchRemoveChoice(item);
  970. }
  971. }
  972. });
  973. this.$selection.on('keyup', '.select2-search--inline', function (evt) {
  974. self.handleSearch(evt);
  975. });
  976. };
  977. Search.prototype.createPlaceholder = function (decorated, placeholder) {
  978. this.$search.attr('placeholder', placeholder.text);
  979. };
  980. Search.prototype.update = function (decorated, data) {
  981. this.$search.attr('placeholder', '');
  982. decorated.call(this, data);
  983. this.$selection.find('.select2-selection__rendered')
  984. .append(this.$searchContainer);
  985. this.resizeSearch();
  986. };
  987. Search.prototype.handleSearch = function () {
  988. this.resizeSearch();
  989. if (!this._keyUpPrevented) {
  990. var input = this.$search.val();
  991. this.trigger('query', {
  992. term: input
  993. });
  994. }
  995. this._keyUpPrevented = false;
  996. };
  997. Search.prototype.searchRemoveChoice = function (decorated, item) {
  998. this.trigger('unselect', {
  999. data: item
  1000. });
  1001. this.trigger('open');
  1002. this.$search.val(item.text + ' ');
  1003. };
  1004. Search.prototype.resizeSearch = function () {
  1005. this.$search.css('width', '25px');
  1006. var width = '';
  1007. if (this.$search.attr('placeholder') !== '') {
  1008. width = this.$selection.find('.select2-selection__rendered').innerWidth();
  1009. } else {
  1010. var minimumWidth = this.$search.val().length + 1;
  1011. width = (minimumWidth * 0.75) + 'em';
  1012. }
  1013. this.$search.css('width', width);
  1014. };
  1015. return Search;
  1016. });
  1017. define('select2/selection/eventRelay',[
  1018. 'jquery'
  1019. ], function ($) {
  1020. function EventRelay () { }
  1021. EventRelay.prototype.bind = function (decorated, container, $container) {
  1022. var self = this;
  1023. var relayEvents = [
  1024. 'open', 'opening',
  1025. 'close', 'closing',
  1026. 'select', 'selecting',
  1027. 'unselect', 'unselecting'
  1028. ];
  1029. var preventableEvents = ['opening', 'closing', 'selecting', 'unselecting'];
  1030. decorated.call(this, container, $container);
  1031. container.on('*', function (name, params) {
  1032. // Ignore events that should not be relayed
  1033. if ($.inArray(name, relayEvents) === -1) {
  1034. return;
  1035. }
  1036. // The parameters should always be an object
  1037. params = params || {};
  1038. // Generate the jQuery event for the Select2 event
  1039. var evt = $.Event('select2:' + name, {
  1040. params: params
  1041. });
  1042. self.$element.trigger(evt);
  1043. // Only handle preventable events if it was one
  1044. if ($.inArray(name, preventableEvents) === -1) {
  1045. return;
  1046. }
  1047. params.prevented = evt.isDefaultPrevented();
  1048. });
  1049. };
  1050. return EventRelay;
  1051. });
  1052. define('select2/translation',[
  1053. 'jquery'
  1054. ], function ($) {
  1055. function Translation (dict) {
  1056. this.dict = dict || {};
  1057. }
  1058. Translation.prototype.all = function () {
  1059. return this.dict;
  1060. };
  1061. Translation.prototype.get = function (key) {
  1062. return this.dict[key];
  1063. };
  1064. Translation.prototype.extend = function (translation) {
  1065. this.dict = $.extend({}, translation.all(), this.dict);
  1066. };
  1067. // Static functions
  1068. Translation._cache = {};
  1069. Translation.loadPath = function (path) {
  1070. if (!(path in Translation._cache)) {
  1071. var translations = require(path);
  1072. Translation._cache[path] = translations;
  1073. }
  1074. return new Translation(Translation._cache[path]);
  1075. };
  1076. return Translation;
  1077. });
  1078. define('select2/diacritics',[
  1079. ], function () {
  1080. var diacritics = {
  1081. '\u24B6': 'A',
  1082. '\uFF21': 'A',
  1083. '\u00C0': 'A',
  1084. '\u00C1': 'A',
  1085. '\u00C2': 'A',
  1086. '\u1EA6': 'A',
  1087. '\u1EA4': 'A',
  1088. '\u1EAA': 'A',
  1089. '\u1EA8': 'A',
  1090. '\u00C3': 'A',
  1091. '\u0100': 'A',
  1092. '\u0102': 'A',
  1093. '\u1EB0': 'A',
  1094. '\u1EAE': 'A',
  1095. '\u1EB4': 'A',
  1096. '\u1EB2': 'A',
  1097. '\u0226': 'A',
  1098. '\u01E0': 'A',
  1099. '\u00C4': 'A',
  1100. '\u01DE': 'A',
  1101. '\u1EA2': 'A',
  1102. '\u00C5': 'A',
  1103. '\u01FA': 'A',
  1104. '\u01CD': 'A',
  1105. '\u0200': 'A',
  1106. '\u0202': 'A',
  1107. '\u1EA0': 'A',
  1108. '\u1EAC': 'A',
  1109. '\u1EB6': 'A',
  1110. '\u1E00': 'A',
  1111. '\u0104': 'A',
  1112. '\u023A': 'A',
  1113. '\u2C6F': 'A',
  1114. '\uA732': 'AA',
  1115. '\u00C6': 'AE',
  1116. '\u01FC': 'AE',
  1117. '\u01E2': 'AE',
  1118. '\uA734': 'AO',
  1119. '\uA736': 'AU',
  1120. '\uA738': 'AV',
  1121. '\uA73A': 'AV',
  1122. '\uA73C': 'AY',
  1123. '\u24B7': 'B',
  1124. '\uFF22': 'B',
  1125. '\u1E02': 'B',
  1126. '\u1E04': 'B',
  1127. '\u1E06': 'B',
  1128. '\u0243': 'B',
  1129. '\u0182': 'B',
  1130. '\u0181': 'B',
  1131. '\u24B8': 'C',
  1132. '\uFF23': 'C',
  1133. '\u0106': 'C',
  1134. '\u0108': 'C',
  1135. '\u010A': 'C',
  1136. '\u010C': 'C',
  1137. '\u00C7': 'C',
  1138. '\u1E08': 'C',
  1139. '\u0187': 'C',
  1140. '\u023B': 'C',
  1141. '\uA73E': 'C',
  1142. '\u24B9': 'D',
  1143. '\uFF24': 'D',
  1144. '\u1E0A': 'D',
  1145. '\u010E': 'D',
  1146. '\u1E0C': 'D',
  1147. '\u1E10': 'D',
  1148. '\u1E12': 'D',
  1149. '\u1E0E': 'D',
  1150. '\u0110': 'D',
  1151. '\u018B': 'D',
  1152. '\u018A': 'D',
  1153. '\u0189': 'D',
  1154. '\uA779': 'D',
  1155. '\u01F1': 'DZ',
  1156. '\u01C4': 'DZ',
  1157. '\u01F2': 'Dz',
  1158. '\u01C5': 'Dz',
  1159. '\u24BA': 'E',
  1160. '\uFF25': 'E',
  1161. '\u00C8': 'E',
  1162. '\u00C9': 'E',
  1163. '\u00CA': 'E',
  1164. '\u1EC0': 'E',
  1165. '\u1EBE': 'E',
  1166. '\u1EC4': 'E',
  1167. '\u1EC2': 'E',
  1168. '\u1EBC': 'E',
  1169. '\u0112': 'E',
  1170. '\u1E14': 'E',
  1171. '\u1E16': 'E',
  1172. '\u0114': 'E',
  1173. '\u0116': 'E',
  1174. '\u00CB': 'E',
  1175. '\u1EBA': 'E',
  1176. '\u011A': 'E',
  1177. '\u0204': 'E',
  1178. '\u0206': 'E',
  1179. '\u1EB8': 'E',
  1180. '\u1EC6': 'E',
  1181. '\u0228': 'E',
  1182. '\u1E1C': 'E',
  1183. '\u0118': 'E',
  1184. '\u1E18': 'E',
  1185. '\u1E1A': 'E',
  1186. '\u0190': 'E',
  1187. '\u018E': 'E',
  1188. '\u24BB': 'F',
  1189. '\uFF26': 'F',
  1190. '\u1E1E': 'F',
  1191. '\u0191': 'F',
  1192. '\uA77B': 'F',
  1193. '\u24BC': 'G',
  1194. '\uFF27': 'G',
  1195. '\u01F4': 'G',
  1196. '\u011C': 'G',
  1197. '\u1E20': 'G',
  1198. '\u011E': 'G',
  1199. '\u0120': 'G',
  1200. '\u01E6': 'G',
  1201. '\u0122': 'G',
  1202. '\u01E4': 'G',
  1203. '\u0193': 'G',
  1204. '\uA7A0': 'G',
  1205. '\uA77D': 'G',
  1206. '\uA77E': 'G',
  1207. '\u24BD': 'H',
  1208. '\uFF28': 'H',
  1209. '\u0124': 'H',
  1210. '\u1E22': 'H',
  1211. '\u1E26': 'H',
  1212. '\u021E': 'H',
  1213. '\u1E24': 'H',
  1214. '\u1E28': 'H',
  1215. '\u1E2A': 'H',
  1216. '\u0126': 'H',
  1217. '\u2C67': 'H',
  1218. '\u2C75': 'H',
  1219. '\uA78D': 'H',
  1220. '\u24BE': 'I',
  1221. '\uFF29': 'I',
  1222. '\u00CC': 'I',
  1223. '\u00CD': 'I',
  1224. '\u00CE': 'I',
  1225. '\u0128': 'I',
  1226. '\u012A': 'I',
  1227. '\u012C': 'I',
  1228. '\u0130': 'I',
  1229. '\u00CF': 'I',
  1230. '\u1E2E': 'I',
  1231. '\u1EC8': 'I',
  1232. '\u01CF': 'I',
  1233. '\u0208': 'I',
  1234. '\u020A': 'I',
  1235. '\u1ECA': 'I',
  1236. '\u012E': 'I',
  1237. '\u1E2C': 'I',
  1238. '\u0197': 'I',
  1239. '\u24BF': 'J',
  1240. '\uFF2A': 'J',
  1241. '\u0134': 'J',
  1242. '\u0248': 'J',
  1243. '\u24C0': 'K',
  1244. '\uFF2B': 'K',
  1245. '\u1E30': 'K',
  1246. '\u01E8': 'K',
  1247. '\u1E32': 'K',
  1248. '\u0136': 'K',
  1249. '\u1E34': 'K',
  1250. '\u0198': 'K',
  1251. '\u2C69': 'K',
  1252. '\uA740': 'K',
  1253. '\uA742': 'K',
  1254. '\uA744': 'K',
  1255. '\uA7A2': 'K',
  1256. '\u24C1': 'L',
  1257. '\uFF2C': 'L',
  1258. '\u013F': 'L',
  1259. '\u0139': 'L',
  1260. '\u013D': 'L',
  1261. '\u1E36': 'L',
  1262. '\u1E38': 'L',
  1263. '\u013B': 'L',
  1264. '\u1E3C': 'L',
  1265. '\u1E3A': 'L',
  1266. '\u0141': 'L',
  1267. '\u023D': 'L',
  1268. '\u2C62': 'L',
  1269. '\u2C60': 'L',
  1270. '\uA748': 'L',
  1271. '\uA746': 'L',
  1272. '\uA780': 'L',
  1273. '\u01C7': 'LJ',
  1274. '\u01C8': 'Lj',
  1275. '\u24C2': 'M',
  1276. '\uFF2D': 'M',
  1277. '\u1E3E': 'M',
  1278. '\u1E40': 'M',
  1279. '\u1E42': 'M',
  1280. '\u2C6E': 'M',
  1281. '\u019C': 'M',
  1282. '\u24C3': 'N',
  1283. '\uFF2E': 'N',
  1284. '\u01F8': 'N',
  1285. '\u0143': 'N',
  1286. '\u00D1': 'N',
  1287. '\u1E44': 'N',
  1288. '\u0147': 'N',
  1289. '\u1E46': 'N',
  1290. '\u0145': 'N',
  1291. '\u1E4A': 'N',
  1292. '\u1E48': 'N',
  1293. '\u0220': 'N',
  1294. '\u019D': 'N',
  1295. '\uA790': 'N',
  1296. '\uA7A4': 'N',
  1297. '\u01CA': 'NJ',
  1298. '\u01CB': 'Nj',
  1299. '\u24C4': 'O',
  1300. '\uFF2F': 'O',
  1301. '\u00D2': 'O',
  1302. '\u00D3': 'O',
  1303. '\u00D4': 'O',
  1304. '\u1ED2': 'O',
  1305. '\u1ED0': 'O',
  1306. '\u1ED6': 'O',
  1307. '\u1ED4': 'O',
  1308. '\u00D5': 'O',
  1309. '\u1E4C': 'O',
  1310. '\u022C': 'O',
  1311. '\u1E4E': 'O',
  1312. '\u014C': 'O',
  1313. '\u1E50': 'O',
  1314. '\u1E52': 'O',
  1315. '\u014E': 'O',
  1316. '\u022E': 'O',
  1317. '\u0230': 'O',
  1318. '\u00D6': 'O',
  1319. '\u022A': 'O',
  1320. '\u1ECE': 'O',
  1321. '\u0150': 'O',
  1322. '\u01D1': 'O',
  1323. '\u020C': 'O',
  1324. '\u020E': 'O',
  1325. '\u01A0': 'O',
  1326. '\u1EDC': 'O',
  1327. '\u1EDA': 'O',
  1328. '\u1EE0': 'O',
  1329. '\u1EDE': 'O',
  1330. '\u1EE2': 'O',
  1331. '\u1ECC': 'O',
  1332. '\u1ED8': 'O',
  1333. '\u01EA': 'O',
  1334. '\u01EC': 'O',
  1335. '\u00D8': 'O',
  1336. '\u01FE': 'O',
  1337. '\u0186': 'O',
  1338. '\u019F': 'O',
  1339. '\uA74A': 'O',
  1340. '\uA74C': 'O',
  1341. '\u01A2': 'OI',
  1342. '\uA74E': 'OO',
  1343. '\u0222': 'OU',
  1344. '\u24C5': 'P',
  1345. '\uFF30': 'P',
  1346. '\u1E54': 'P',
  1347. '\u1E56': 'P',
  1348. '\u01A4': 'P',
  1349. '\u2C63': 'P',
  1350. '\uA750': 'P',
  1351. '\uA752': 'P',
  1352. '\uA754': 'P',
  1353. '\u24C6': 'Q',
  1354. '\uFF31': 'Q',
  1355. '\uA756': 'Q',
  1356. '\uA758': 'Q',
  1357. '\u024A': 'Q',
  1358. '\u24C7': 'R',
  1359. '\uFF32': 'R',
  1360. '\u0154': 'R',
  1361. '\u1E58': 'R',
  1362. '\u0158': 'R',
  1363. '\u0210': 'R',
  1364. '\u0212': 'R',
  1365. '\u1E5A': 'R',
  1366. '\u1E5C': 'R',
  1367. '\u0156': 'R',
  1368. '\u1E5E': 'R',
  1369. '\u024C': 'R',
  1370. '\u2C64': 'R',
  1371. '\uA75A': 'R',
  1372. '\uA7A6': 'R',
  1373. '\uA782': 'R',
  1374. '\u24C8': 'S',
  1375. '\uFF33': 'S',
  1376. '\u1E9E': 'S',
  1377. '\u015A': 'S',
  1378. '\u1E64': 'S',
  1379. '\u015C': 'S',
  1380. '\u1E60': 'S',
  1381. '\u0160': 'S',
  1382. '\u1E66': 'S',
  1383. '\u1E62': 'S',
  1384. '\u1E68': 'S',
  1385. '\u0218': 'S',
  1386. '\u015E': 'S',
  1387. '\u2C7E': 'S',
  1388. '\uA7A8': 'S',
  1389. '\uA784': 'S',
  1390. '\u24C9': 'T',
  1391. '\uFF34': 'T',
  1392. '\u1E6A': 'T',
  1393. '\u0164': 'T',
  1394. '\u1E6C': 'T',
  1395. '\u021A': 'T',
  1396. '\u0162': 'T',
  1397. '\u1E70': 'T',
  1398. '\u1E6E': 'T',
  1399. '\u0166': 'T',
  1400. '\u01AC': 'T',
  1401. '\u01AE': 'T',
  1402. '\u023E': 'T',
  1403. '\uA786': 'T',
  1404. '\uA728': 'TZ',
  1405. '\u24CA': 'U',
  1406. '\uFF35': 'U',
  1407. '\u00D9': 'U',
  1408. '\u00DA': 'U',
  1409. '\u00DB': 'U',
  1410. '\u0168': 'U',
  1411. '\u1E78': 'U',
  1412. '\u016A': 'U',
  1413. '\u1E7A': 'U',
  1414. '\u016C': 'U',
  1415. '\u00DC': 'U',
  1416. '\u01DB': 'U',
  1417. '\u01D7': 'U',
  1418. '\u01D5': 'U',
  1419. '\u01D9': 'U',
  1420. '\u1EE6': 'U',
  1421. '\u016E': 'U',
  1422. '\u0170': 'U',
  1423. '\u01D3': 'U',
  1424. '\u0214': 'U',
  1425. '\u0216': 'U',
  1426. '\u01AF': 'U',
  1427. '\u1EEA': 'U',
  1428. '\u1EE8': 'U',
  1429. '\u1EEE': 'U',
  1430. '\u1EEC': 'U',
  1431. '\u1EF0': 'U',
  1432. '\u1EE4': 'U',
  1433. '\u1E72': 'U',
  1434. '\u0172': 'U',
  1435. '\u1E76': 'U',
  1436. '\u1E74': 'U',
  1437. '\u0244': 'U',
  1438. '\u24CB': 'V',
  1439. '\uFF36': 'V',
  1440. '\u1E7C': 'V',
  1441. '\u1E7E': 'V',
  1442. '\u01B2': 'V',
  1443. '\uA75E': 'V',
  1444. '\u0245': 'V',
  1445. '\uA760': 'VY',
  1446. '\u24CC': 'W',
  1447. '\uFF37': 'W',
  1448. '\u1E80': 'W',
  1449. '\u1E82': 'W',
  1450. '\u0174': 'W',
  1451. '\u1E86': 'W',
  1452. '\u1E84': 'W',
  1453. '\u1E88': 'W',
  1454. '\u2C72': 'W',
  1455. '\u24CD': 'X',
  1456. '\uFF38': 'X',
  1457. '\u1E8A': 'X',
  1458. '\u1E8C': 'X',
  1459. '\u24CE': 'Y',
  1460. '\uFF39': 'Y',
  1461. '\u1EF2': 'Y',
  1462. '\u00DD': 'Y',
  1463. '\u0176': 'Y',
  1464. '\u1EF8': 'Y',
  1465. '\u0232': 'Y',
  1466. '\u1E8E': 'Y',
  1467. '\u0178': 'Y',
  1468. '\u1EF6': 'Y',
  1469. '\u1EF4': 'Y',
  1470. '\u01B3': 'Y',
  1471. '\u024E': 'Y',
  1472. '\u1EFE': 'Y',
  1473. '\u24CF': 'Z',
  1474. '\uFF3A': 'Z',
  1475. '\u0179': 'Z',
  1476. '\u1E90': 'Z',
  1477. '\u017B': 'Z',
  1478. '\u017D': 'Z',
  1479. '\u1E92': 'Z',
  1480. '\u1E94': 'Z',
  1481. '\u01B5': 'Z',
  1482. '\u0224': 'Z',
  1483. '\u2C7F': 'Z',
  1484. '\u2C6B': 'Z',
  1485. '\uA762': 'Z',
  1486. '\u24D0': 'a',
  1487. '\uFF41': 'a',
  1488. '\u1E9A': 'a',
  1489. '\u00E0': 'a',
  1490. '\u00E1': 'a',
  1491. '\u00E2': 'a',
  1492. '\u1EA7': 'a',
  1493. '\u1EA5': 'a',
  1494. '\u1EAB': 'a',
  1495. '\u1EA9': 'a',
  1496. '\u00E3': 'a',
  1497. '\u0101': 'a',
  1498. '\u0103': 'a',
  1499. '\u1EB1': 'a',
  1500. '\u1EAF': 'a',
  1501. '\u1EB5': 'a',
  1502. '\u1EB3': 'a',
  1503. '\u0227': 'a',
  1504. '\u01E1': 'a',
  1505. '\u00E4': 'a',
  1506. '\u01DF': 'a',
  1507. '\u1EA3': 'a',
  1508. '\u00E5': 'a',
  1509. '\u01FB': 'a',
  1510. '\u01CE': 'a',
  1511. '\u0201': 'a',
  1512. '\u0203': 'a',
  1513. '\u1EA1': 'a',
  1514. '\u1EAD': 'a',
  1515. '\u1EB7': 'a',
  1516. '\u1E01': 'a',
  1517. '\u0105': 'a',
  1518. '\u2C65': 'a',
  1519. '\u0250': 'a',
  1520. '\uA733': 'aa',
  1521. '\u00E6': 'ae',
  1522. '\u01FD': 'ae',
  1523. '\u01E3': 'ae',
  1524. '\uA735': 'ao',
  1525. '\uA737': 'au',
  1526. '\uA739': 'av',
  1527. '\uA73B': 'av',
  1528. '\uA73D': 'ay',
  1529. '\u24D1': 'b',
  1530. '\uFF42': 'b',
  1531. '\u1E03': 'b',
  1532. '\u1E05': 'b',
  1533. '\u1E07': 'b',
  1534. '\u0180': 'b',
  1535. '\u0183': 'b',
  1536. '\u0253': 'b',
  1537. '\u24D2': 'c',
  1538. '\uFF43': 'c',
  1539. '\u0107': 'c',
  1540. '\u0109': 'c',
  1541. '\u010B': 'c',
  1542. '\u010D': 'c',
  1543. '\u00E7': 'c',
  1544. '\u1E09': 'c',
  1545. '\u0188': 'c',
  1546. '\u023C': 'c',
  1547. '\uA73F': 'c',
  1548. '\u2184': 'c',
  1549. '\u24D3': 'd',
  1550. '\uFF44': 'd',
  1551. '\u1E0B': 'd',
  1552. '\u010F': 'd',
  1553. '\u1E0D': 'd',
  1554. '\u1E11': 'd',
  1555. '\u1E13': 'd',
  1556. '\u1E0F': 'd',
  1557. '\u0111': 'd',
  1558. '\u018C': 'd',
  1559. '\u0256': 'd',
  1560. '\u0257': 'd',
  1561. '\uA77A': 'd',
  1562. '\u01F3': 'dz',
  1563. '\u01C6': 'dz',
  1564. '\u24D4': 'e',
  1565. '\uFF45': 'e',
  1566. '\u00E8': 'e',
  1567. '\u00E9': 'e',
  1568. '\u00EA': 'e',
  1569. '\u1EC1': 'e',
  1570. '\u1EBF': 'e',
  1571. '\u1EC5': 'e',
  1572. '\u1EC3': 'e',
  1573. '\u1EBD': 'e',
  1574. '\u0113': 'e',
  1575. '\u1E15': 'e',
  1576. '\u1E17': 'e',
  1577. '\u0115': 'e',
  1578. '\u0117': 'e',
  1579. '\u00EB': 'e',
  1580. '\u1EBB': 'e',
  1581. '\u011B': 'e',
  1582. '\u0205': 'e',
  1583. '\u0207': 'e',
  1584. '\u1EB9': 'e',
  1585. '\u1EC7': 'e',
  1586. '\u0229': 'e',
  1587. '\u1E1D': 'e',
  1588. '\u0119': 'e',
  1589. '\u1E19': 'e',
  1590. '\u1E1B': 'e',
  1591. '\u0247': 'e',
  1592. '\u025B': 'e',
  1593. '\u01DD': 'e',
  1594. '\u24D5': 'f',
  1595. '\uFF46': 'f',
  1596. '\u1E1F': 'f',
  1597. '\u0192': 'f',
  1598. '\uA77C': 'f',
  1599. '\u24D6': 'g',
  1600. '\uFF47': 'g',
  1601. '\u01F5': 'g',
  1602. '\u011D': 'g',
  1603. '\u1E21': 'g',
  1604. '\u011F': 'g',
  1605. '\u0121': 'g',
  1606. '\u01E7': 'g',
  1607. '\u0123': 'g',
  1608. '\u01E5': 'g',
  1609. '\u0260': 'g',
  1610. '\uA7A1': 'g',
  1611. '\u1D79': 'g',
  1612. '\uA77F': 'g',
  1613. '\u24D7': 'h',
  1614. '\uFF48': 'h',
  1615. '\u0125': 'h',
  1616. '\u1E23': 'h',
  1617. '\u1E27': 'h',
  1618. '\u021F': 'h',
  1619. '\u1E25': 'h',
  1620. '\u1E29': 'h',
  1621. '\u1E2B': 'h',
  1622. '\u1E96': 'h',
  1623. '\u0127': 'h',
  1624. '\u2C68': 'h',
  1625. '\u2C76': 'h',
  1626. '\u0265': 'h',
  1627. '\u0195': 'hv',
  1628. '\u24D8': 'i',
  1629. '\uFF49': 'i',
  1630. '\u00EC': 'i',
  1631. '\u00ED': 'i',
  1632. '\u00EE': 'i',
  1633. '\u0129': 'i',
  1634. '\u012B': 'i',
  1635. '\u012D': 'i',
  1636. '\u00EF': 'i',
  1637. '\u1E2F': 'i',
  1638. '\u1EC9': 'i',
  1639. '\u01D0': 'i',
  1640. '\u0209': 'i',
  1641. '\u020B': 'i',
  1642. '\u1ECB': 'i',
  1643. '\u012F': 'i',
  1644. '\u1E2D': 'i',
  1645. '\u0268': 'i',
  1646. '\u0131': 'i',
  1647. '\u24D9': 'j',
  1648. '\uFF4A': 'j',
  1649. '\u0135': 'j',
  1650. '\u01F0': 'j',
  1651. '\u0249': 'j',
  1652. '\u24DA': 'k',
  1653. '\uFF4B': 'k',
  1654. '\u1E31': 'k',
  1655. '\u01E9': 'k',
  1656. '\u1E33': 'k',
  1657. '\u0137': 'k',
  1658. '\u1E35': 'k',
  1659. '\u0199': 'k',
  1660. '\u2C6A': 'k',
  1661. '\uA741': 'k',
  1662. '\uA743': 'k',
  1663. '\uA745': 'k',
  1664. '\uA7A3': 'k',
  1665. '\u24DB': 'l',
  1666. '\uFF4C': 'l',
  1667. '\u0140': 'l',
  1668. '\u013A': 'l',
  1669. '\u013E': 'l',
  1670. '\u1E37': 'l',
  1671. '\u1E39': 'l',
  1672. '\u013C': 'l',
  1673. '\u1E3D': 'l',
  1674. '\u1E3B': 'l',
  1675. '\u017F': 'l',
  1676. '\u0142': 'l',
  1677. '\u019A': 'l',
  1678. '\u026B': 'l',
  1679. '\u2C61': 'l',
  1680. '\uA749': 'l',
  1681. '\uA781': 'l',
  1682. '\uA747': 'l',
  1683. '\u01C9': 'lj',
  1684. '\u24DC': 'm',
  1685. '\uFF4D': 'm',
  1686. '\u1E3F': 'm',
  1687. '\u1E41': 'm',
  1688. '\u1E43': 'm',
  1689. '\u0271': 'm',
  1690. '\u026F': 'm',
  1691. '\u24DD': 'n',
  1692. '\uFF4E': 'n',
  1693. '\u01F9': 'n',
  1694. '\u0144': 'n',
  1695. '\u00F1': 'n',
  1696. '\u1E45': 'n',
  1697. '\u0148': 'n',
  1698. '\u1E47': 'n',
  1699. '\u0146': 'n',
  1700. '\u1E4B': 'n',
  1701. '\u1E49': 'n',
  1702. '\u019E': 'n',
  1703. '\u0272': 'n',
  1704. '\u0149': 'n',
  1705. '\uA791': 'n',
  1706. '\uA7A5': 'n',
  1707. '\u01CC': 'nj',
  1708. '\u24DE': 'o',
  1709. '\uFF4F': 'o',
  1710. '\u00F2': 'o',
  1711. '\u00F3': 'o',
  1712. '\u00F4': 'o',
  1713. '\u1ED3': 'o',
  1714. '\u1ED1': 'o',
  1715. '\u1ED7': 'o',
  1716. '\u1ED5': 'o',
  1717. '\u00F5': 'o',
  1718. '\u1E4D': 'o',
  1719. '\u022D': 'o',
  1720. '\u1E4F': 'o',
  1721. '\u014D': 'o',
  1722. '\u1E51': 'o',
  1723. '\u1E53': 'o',
  1724. '\u014F': 'o',
  1725. '\u022F': 'o',
  1726. '\u0231': 'o',
  1727. '\u00F6': 'o',
  1728. '\u022B': 'o',
  1729. '\u1ECF': 'o',
  1730. '\u0151': 'o',
  1731. '\u01D2': 'o',
  1732. '\u020D': 'o',
  1733. '\u020F': 'o',
  1734. '\u01A1': 'o',
  1735. '\u1EDD': 'o',
  1736. '\u1EDB': 'o',
  1737. '\u1EE1': 'o',
  1738. '\u1EDF': 'o',
  1739. '\u1EE3': 'o',
  1740. '\u1ECD': 'o',
  1741. '\u1ED9': 'o',
  1742. '\u01EB': 'o',
  1743. '\u01ED': 'o',
  1744. '\u00F8': 'o',
  1745. '\u01FF': 'o',
  1746. '\u0254': 'o',
  1747. '\uA74B': 'o',
  1748. '\uA74D': 'o',
  1749. '\u0275': 'o',
  1750. '\u01A3': 'oi',
  1751. '\u0223': 'ou',
  1752. '\uA74F': 'oo',
  1753. '\u24DF': 'p',
  1754. '\uFF50': 'p',
  1755. '\u1E55': 'p',
  1756. '\u1E57': 'p',
  1757. '\u01A5': 'p',
  1758. '\u1D7D': 'p',
  1759. '\uA751': 'p',
  1760. '\uA753': 'p',
  1761. '\uA755': 'p',
  1762. '\u24E0': 'q',
  1763. '\uFF51': 'q',
  1764. '\u024B': 'q',
  1765. '\uA757': 'q',
  1766. '\uA759': 'q',
  1767. '\u24E1': 'r',
  1768. '\uFF52': 'r',
  1769. '\u0155': 'r',
  1770. '\u1E59': 'r',
  1771. '\u0159': 'r',
  1772. '\u0211': 'r',
  1773. '\u0213': 'r',
  1774. '\u1E5B': 'r',
  1775. '\u1E5D': 'r',
  1776. '\u0157': 'r',
  1777. '\u1E5F': 'r',
  1778. '\u024D': 'r',
  1779. '\u027D': 'r',
  1780. '\uA75B': 'r',
  1781. '\uA7A7': 'r',
  1782. '\uA783': 'r',
  1783. '\u24E2': 's',
  1784. '\uFF53': 's',
  1785. '\u00DF': 's',
  1786. '\u015B': 's',
  1787. '\u1E65': 's',
  1788. '\u015D': 's',
  1789. '\u1E61': 's',
  1790. '\u0161': 's',
  1791. '\u1E67': 's',
  1792. '\u1E63': 's',
  1793. '\u1E69': 's',
  1794. '\u0219': 's',
  1795. '\u015F': 's',
  1796. '\u023F': 's',
  1797. '\uA7A9': 's',
  1798. '\uA785': 's',
  1799. '\u1E9B': 's',
  1800. '\u24E3': 't',
  1801. '\uFF54': 't',
  1802. '\u1E6B': 't',
  1803. '\u1E97': 't',
  1804. '\u0165': 't',
  1805. '\u1E6D': 't',
  1806. '\u021B': 't',
  1807. '\u0163': 't',
  1808. '\u1E71': 't',
  1809. '\u1E6F': 't',
  1810. '\u0167': 't',
  1811. '\u01AD': 't',
  1812. '\u0288': 't',
  1813. '\u2C66': 't',
  1814. '\uA787': 't',
  1815. '\uA729': 'tz',
  1816. '\u24E4': 'u',
  1817. '\uFF55': 'u',
  1818. '\u00F9': 'u',
  1819. '\u00FA': 'u',
  1820. '\u00FB': 'u',
  1821. '\u0169': 'u',
  1822. '\u1E79': 'u',
  1823. '\u016B': 'u',
  1824. '\u1E7B': 'u',
  1825. '\u016D': 'u',
  1826. '\u00FC': 'u',
  1827. '\u01DC': 'u',
  1828. '\u01D8': 'u',
  1829. '\u01D6': 'u',
  1830. '\u01DA': 'u',
  1831. '\u1EE7': 'u',
  1832. '\u016F': 'u',
  1833. '\u0171': 'u',
  1834. '\u01D4': 'u',
  1835. '\u0215': 'u',
  1836. '\u0217': 'u',
  1837. '\u01B0': 'u',
  1838. '\u1EEB': 'u',
  1839. '\u1EE9': 'u',
  1840. '\u1EEF': 'u',
  1841. '\u1EED': 'u',
  1842. '\u1EF1': 'u',
  1843. '\u1EE5': 'u',
  1844. '\u1E73': 'u',
  1845. '\u0173': 'u',
  1846. '\u1E77': 'u',
  1847. '\u1E75': 'u',
  1848. '\u0289': 'u',
  1849. '\u24E5': 'v',
  1850. '\uFF56': 'v',
  1851. '\u1E7D': 'v',
  1852. '\u1E7F': 'v',
  1853. '\u028B': 'v',
  1854. '\uA75F': 'v',
  1855. '\u028C': 'v',
  1856. '\uA761': 'vy',
  1857. '\u24E6': 'w',
  1858. '\uFF57': 'w',
  1859. '\u1E81': 'w',
  1860. '\u1E83': 'w',
  1861. '\u0175': 'w',
  1862. '\u1E87': 'w',
  1863. '\u1E85': 'w',
  1864. '\u1E98': 'w',
  1865. '\u1E89': 'w',
  1866. '\u2C73': 'w',
  1867. '\u24E7': 'x',
  1868. '\uFF58': 'x',
  1869. '\u1E8B': 'x',
  1870. '\u1E8D': 'x',
  1871. '\u24E8': 'y',
  1872. '\uFF59': 'y',
  1873. '\u1EF3': 'y',
  1874. '\u00FD': 'y',
  1875. '\u0177': 'y',
  1876. '\u1EF9': 'y',
  1877. '\u0233': 'y',
  1878. '\u1E8F': 'y',
  1879. '\u00FF': 'y',
  1880. '\u1EF7': 'y',
  1881. '\u1E99': 'y',
  1882. '\u1EF5': 'y',
  1883. '\u01B4': 'y',
  1884. '\u024F': 'y',
  1885. '\u1EFF': 'y',
  1886. '\u24E9': 'z',
  1887. '\uFF5A': 'z',
  1888. '\u017A': 'z',
  1889. '\u1E91': 'z',
  1890. '\u017C': 'z',
  1891. '\u017E': 'z',
  1892. '\u1E93': 'z',
  1893. '\u1E95': 'z',
  1894. '\u01B6': 'z',
  1895. '\u0225': 'z',
  1896. '\u0240': 'z',
  1897. '\u2C6C': 'z',
  1898. '\uA763': 'z',
  1899. '\u0386': '\u0391',
  1900. '\u0388': '\u0395',
  1901. '\u0389': '\u0397',
  1902. '\u038A': '\u0399',
  1903. '\u03AA': '\u0399',
  1904. '\u038C': '\u039F',
  1905. '\u038E': '\u03A5',
  1906. '\u03AB': '\u03A5',
  1907. '\u038F': '\u03A9',
  1908. '\u03AC': '\u03B1',
  1909. '\u03AD': '\u03B5',
  1910. '\u03AE': '\u03B7',
  1911. '\u03AF': '\u03B9',
  1912. '\u03CA': '\u03B9',
  1913. '\u0390': '\u03B9',
  1914. '\u03CC': '\u03BF',
  1915. '\u03CD': '\u03C5',
  1916. '\u03CB': '\u03C5',
  1917. '\u03B0': '\u03C5',
  1918. '\u03C9': '\u03C9',
  1919. '\u03C2': '\u03C3'
  1920. };
  1921. return diacritics;
  1922. });
  1923. define('select2/data/base',[
  1924. '../utils'
  1925. ], function (Utils) {
  1926. function BaseAdapter ($element, options) {
  1927. BaseAdapter.__super__.constructor.call(this);
  1928. }
  1929. Utils.Extend(BaseAdapter, Utils.Observable);
  1930. BaseAdapter.prototype.current = function (callback) {
  1931. throw new Error('The `current` method must be defined in child classes.');
  1932. };
  1933. BaseAdapter.prototype.query = function (params, callback) {
  1934. throw new Error('The `query` method must be defined in child classes.');
  1935. };
  1936. BaseAdapter.prototype.bind = function (container, $container) {
  1937. // Can be implemented in subclasses
  1938. };
  1939. BaseAdapter.prototype.destroy = function () {
  1940. // Can be implemented in subclasses
  1941. };
  1942. BaseAdapter.prototype.generateResultId = function (container, data) {
  1943. var id = container.id + '-result-';
  1944. id += Utils.generateChars(4);
  1945. if (data.id != null) {
  1946. id += '-' + data.id.toString();
  1947. } else {
  1948. id += '-' + Utils.generateChars(4);
  1949. }
  1950. return id;
  1951. };
  1952. return BaseAdapter;
  1953. });
  1954. define('select2/data/select',[
  1955. './base',
  1956. '../utils',
  1957. 'jquery'
  1958. ], function (BaseAdapter, Utils, $) {
  1959. function SelectAdapter ($element, options) {
  1960. this.$element = $element;
  1961. this.options = options;
  1962. SelectAdapter.__super__.constructor.call(this);
  1963. }
  1964. Utils.Extend(SelectAdapter, BaseAdapter);
  1965. SelectAdapter.prototype.current = function (callback) {
  1966. var data = [];
  1967. var self = this;
  1968. this.$element.find(':selected').each(function () {
  1969. var $option = $(this);
  1970. var option = self.item($option);
  1971. data.push(option);
  1972. });
  1973. callback(data);
  1974. };
  1975. SelectAdapter.prototype.select = function (data) {
  1976. var self = this;
  1977. // If data.element is a DOM nose, use it instead
  1978. if ($(data.element).is('option')) {
  1979. data.element.selected = true;
  1980. this.$element.trigger('change');
  1981. return;
  1982. }
  1983. if (this.$element.prop('multiple')) {
  1984. this.current(function (currentData) {
  1985. var val = [];
  1986. data = [data];
  1987. data.push.apply(data, currentData);
  1988. for (var d = 0; d < data.length; d++) {
  1989. var id = data[d].id;
  1990. if ($.inArray(id, val) === -1) {
  1991. val.push(id);
  1992. }
  1993. }
  1994. self.$element.val(val);
  1995. self.$element.trigger('change');
  1996. });
  1997. } else {
  1998. var val = data.id;
  1999. this.$element.val(val);
  2000. this.$element.trigger('change');
  2001. }
  2002. };
  2003. SelectAdapter.prototype.unselect = function (data) {
  2004. var self = this;
  2005. if (!this.$element.prop('multiple')) {
  2006. return;
  2007. }
  2008. if ($(data.element).is('option')) {
  2009. data.element.selected = false;
  2010. this.$element.trigger('change');
  2011. return;
  2012. }
  2013. this.current(function (currentData) {
  2014. var val = [];
  2015. for (var d = 0; d < currentData.length; d++) {
  2016. var id = currentData[d].id;
  2017. if (id !== data.id && $.inArray(id, val) === -1) {
  2018. val.push(id);
  2019. }
  2020. }
  2021. self.$element.val(val);
  2022. self.$element.trigger('change');
  2023. });
  2024. };
  2025. SelectAdapter.prototype.bind = function (container, $container) {
  2026. var self = this;
  2027. this.container = container;
  2028. container.on('select', function (params) {
  2029. self.select(params.data);
  2030. });
  2031. container.on('unselect', function (params) {
  2032. self.unselect(params.data);
  2033. });
  2034. };
  2035. SelectAdapter.prototype.destroy = function () {
  2036. // Remove anything added to child elements
  2037. this.$element.find('*').each(function () {
  2038. // Remove any custom data set by Select2
  2039. $.removeData(this, 'data');
  2040. });
  2041. };
  2042. SelectAdapter.prototype.query = function (params, callback) {
  2043. var data = [];
  2044. var self = this;
  2045. var $options = this.$element.children();
  2046. $options.each(function () {
  2047. var $option = $(this);
  2048. if (!$option.is('option') && !$option.is('optgroup')) {
  2049. return;
  2050. }
  2051. var option = self.item($option);
  2052. var matches = self.matches(params, option);
  2053. if (matches !== null) {
  2054. data.push(matches);
  2055. }
  2056. });
  2057. callback({
  2058. results: data
  2059. });
  2060. };
  2061. SelectAdapter.prototype.option = function (data) {
  2062. var option;
  2063. if (data.children) {
  2064. option = document.createElement('optgroup');
  2065. option.label = data.text;
  2066. } else {
  2067. option = document.createElement('option');
  2068. if (option.textContent !== undefined) {
  2069. option.textContent = data.text;
  2070. } else {
  2071. option.innerText = data.text;
  2072. }
  2073. }
  2074. if (data.id) {
  2075. option.value = data.id;
  2076. }
  2077. if (data.disabled) {
  2078. option.disabled = true;
  2079. }
  2080. if (data.selected) {
  2081. option.selected = true;
  2082. }
  2083. if (data.title) {
  2084. option.title = data.title;
  2085. }
  2086. var $option = $(option);
  2087. var normalizedData = this._normalizeItem(data);
  2088. normalizedData.element = option;
  2089. // Override the option's data with the combined data
  2090. $.data(option, 'data', normalizedData);
  2091. return $option;
  2092. };
  2093. SelectAdapter.prototype.item = function ($option) {
  2094. var data = {};
  2095. data = $.data($option[0], 'data');
  2096. if (data != null) {
  2097. return data;
  2098. }
  2099. if ($option.is('option')) {
  2100. data = {
  2101. id: $option.val(),
  2102. text: $option.html(),
  2103. disabled: $option.prop('disabled'),
  2104. selected: $option.prop('selected'),
  2105. title: $option.prop('title')
  2106. };
  2107. } else if ($option.is('optgroup')) {
  2108. data = {
  2109. text: $option.prop('label'),
  2110. children: [],
  2111. title: $option.prop('title')
  2112. };
  2113. var $children = $option.children('option');
  2114. var children = [];
  2115. for (var c = 0; c < $children.length; c++) {
  2116. var $child = $($children[c]);
  2117. var child = this.item($child);
  2118. children.push(child);
  2119. }
  2120. data.children = children;
  2121. }
  2122. data = this._normalizeItem(data);
  2123. data.element = $option[0];
  2124. $.data($option[0], 'data', data);
  2125. return data;
  2126. };
  2127. SelectAdapter.prototype._normalizeItem = function (item) {
  2128. if (!$.isPlainObject(item)) {
  2129. item = {
  2130. id: item,
  2131. text: item
  2132. };
  2133. }
  2134. item = $.extend({}, {
  2135. text: ''
  2136. }, item);
  2137. var defaults = {
  2138. selected: false,
  2139. disabled: false
  2140. };
  2141. if (item.id != null) {
  2142. item.id = item.id.toString();
  2143. }
  2144. if (item.text != null) {
  2145. item.text = item.text.toString();
  2146. }
  2147. if (item._resultId == null && item.id && this.container != null) {
  2148. item._resultId = this.generateResultId(this.container, item);
  2149. }
  2150. return $.extend({}, defaults, item);
  2151. };
  2152. SelectAdapter.prototype.matches = function (params, data) {
  2153. var matcher = this.options.get('matcher');
  2154. return matcher(params, data);
  2155. };
  2156. return SelectAdapter;
  2157. });
  2158. define('select2/data/array',[
  2159. './select',
  2160. '../utils',
  2161. 'jquery'
  2162. ], function (SelectAdapter, Utils, $) {
  2163. function ArrayAdapter ($element, options) {
  2164. var data = options.get('data') || [];
  2165. ArrayAdapter.__super__.constructor.call(this, $element, options);
  2166. $element.append(this.convertToOptions(data));
  2167. }
  2168. Utils.Extend(ArrayAdapter, SelectAdapter);
  2169. ArrayAdapter.prototype.select = function (data) {
  2170. var $option = this.$element.find('option[value="' + data.id + '"]');
  2171. if ($option.length === 0) {
  2172. $option = this.option(data);
  2173. this.$element.append($option);
  2174. }
  2175. ArrayAdapter.__super__.select.call(this, data);
  2176. };
  2177. ArrayAdapter.prototype.convertToOptions = function (data) {
  2178. var self = this;
  2179. var $existing = this.$element.find('option');
  2180. var existingIds = $existing.map(function () {
  2181. return self.item($(this)).id;
  2182. }).get();
  2183. var $options = [];
  2184. // Filter out all items except for the one passed in the argument
  2185. function onlyItem (item) {
  2186. return function () {
  2187. return $(this).val() == item.id;
  2188. };
  2189. }
  2190. for (var d = 0; d < data.length; d++) {
  2191. var item = this._normalizeItem(data[d]);
  2192. // Skip items which were pre-loaded, only merge the data
  2193. if ($.inArray(item.id, existingIds) >= 0) {
  2194. var $existingOption = $existing.filter(onlyItem(item));
  2195. var existingData = this.item($existingOption);
  2196. var newData = $.extend(true, {}, existingData, item);
  2197. var $newOption = this.option(existingData);
  2198. $existingOption.replaceWith($newOption);
  2199. continue;
  2200. }
  2201. var $option = this.option(item);
  2202. if (item.children) {
  2203. var $children = this.convertToOptions(item.children);
  2204. $option.append($children);
  2205. }
  2206. $options.push($option);
  2207. }
  2208. return $options;
  2209. };
  2210. return ArrayAdapter;
  2211. });
  2212. define('select2/data/ajax',[
  2213. './array',
  2214. '../utils',
  2215. 'jquery'
  2216. ], function (ArrayAdapter, Utils, $) {
  2217. function AjaxAdapter ($element, options) {
  2218. this.ajaxOptions = this._applyDefaults(options.get('ajax'));
  2219. if (this.ajaxOptions.processResults != null) {
  2220. this.processResults = this.ajaxOptions.processResults;
  2221. }
  2222. ArrayAdapter.__super__.constructor.call(this, $element, options);
  2223. }
  2224. Utils.Extend(AjaxAdapter, ArrayAdapter);
  2225. AjaxAdapter.prototype._applyDefaults = function (options) {
  2226. var defaults = {
  2227. data: function (params) {
  2228. return {
  2229. q: params.term
  2230. };
  2231. },
  2232. transport: function (params, success, failure) {
  2233. var $request = $.ajax(params);
  2234. $request.then(success);
  2235. $request.fail(failure);
  2236. return $request;
  2237. }
  2238. };
  2239. return $.extend({}, defaults, options, true);
  2240. };
  2241. AjaxAdapter.prototype.processResults = function (results) {
  2242. return results;
  2243. };
  2244. AjaxAdapter.prototype.query = function (params, callback) {
  2245. var matches = [];
  2246. var self = this;
  2247. if (this._request) {
  2248. this._request.abort();
  2249. this._request = null;
  2250. }
  2251. var options = $.extend({
  2252. type: 'GET'
  2253. }, this.ajaxOptions);
  2254. if (typeof options.url === 'function') {
  2255. options.url = options.url(params);
  2256. }
  2257. if (typeof options.data === 'function') {
  2258. options.data = options.data(params);
  2259. }
  2260. function request () {
  2261. var $request = options.transport(options, function (data) {
  2262. var results = self.processResults(data, params);
  2263. if (window.console && console.error) {
  2264. // Check to make sure that the response included a `results` key.
  2265. if (!results || !results.results || !$.isArray(results.results)) {
  2266. console.error(
  2267. 'Select2: The AJAX results did not return an array in the ' +
  2268. '`results` key of the response.'
  2269. );
  2270. }
  2271. }
  2272. callback(results);
  2273. }, function () {
  2274. // TODO: Handle AJAX errors
  2275. });
  2276. self._request = $request;
  2277. }
  2278. if (this.ajaxOptions.delay && params.term !== '') {
  2279. if (this._queryTimeout) {
  2280. window.clearTimeout(this._queryTimeout);
  2281. }
  2282. this._queryTimeout = window.setTimeout(request, this.ajaxOptions.delay);
  2283. } else {
  2284. request();
  2285. }
  2286. };
  2287. return AjaxAdapter;
  2288. });
  2289. define('select2/data/tags',[
  2290. 'jquery'
  2291. ], function ($) {
  2292. function Tags (decorated, $element, options) {
  2293. var tags = options.get('tags');
  2294. var createTag = options.get('createTag');
  2295. if (createTag !== undefined) {
  2296. this.createTag = createTag;
  2297. }
  2298. decorated.call(this, $element, options);
  2299. if ($.isArray(tags)) {
  2300. for (var t = 0; t < tags.length; t++) {
  2301. var tag = tags[t];
  2302. var item = this._normalizeItem(tag);
  2303. var $option = this.option(item);
  2304. this.$element.append($option);
  2305. }
  2306. }
  2307. }
  2308. Tags.prototype.query = function (decorated, params, callback) {
  2309. var self = this;
  2310. this._removeOldTags();
  2311. if (params.term == null || params.term === '' || params.page != null) {
  2312. decorated.call(this, params, callback);
  2313. return;
  2314. }
  2315. function wrapper (obj, child) {
  2316. var data = obj.results;
  2317. for (var i = 0; i < data.length; i++) {
  2318. var option = data[i];
  2319. var checkChildren = (
  2320. option.children != null &&
  2321. !wrapper({
  2322. results: option.children
  2323. }, true)
  2324. );
  2325. var checkText = option.text === params.term;
  2326. if (checkText || checkChildren) {
  2327. if (child) {
  2328. return false;
  2329. }
  2330. obj.data = data;
  2331. callback(obj);
  2332. return;
  2333. }
  2334. }
  2335. if (child) {
  2336. return true;
  2337. }
  2338. var tag = self.createTag(params);
  2339. if (tag != null) {
  2340. var $option = self.option(tag);
  2341. $option.attr('data-select2-tag', true);
  2342. self.$element.append($option);
  2343. self.insertTag(data, tag);
  2344. }
  2345. obj.results = data;
  2346. callback(obj);
  2347. }
  2348. decorated.call(this, params, wrapper);
  2349. };
  2350. Tags.prototype.createTag = function (decorated, params) {
  2351. return {
  2352. id: params.term,
  2353. text: params.term
  2354. };
  2355. };
  2356. Tags.prototype.insertTag = function (_, data, tag) {
  2357. data.unshift(tag);
  2358. };
  2359. Tags.prototype._removeOldTags = function (_) {
  2360. var tag = this._lastTag;
  2361. var $options = this.$element.find('option[data-select2-tag]');
  2362. $options.each(function () {
  2363. if (this.selected) {
  2364. return;
  2365. }
  2366. $(this).remove();
  2367. });
  2368. };
  2369. return Tags;
  2370. });
  2371. define('select2/data/tokenizer',[
  2372. 'jquery'
  2373. ], function ($) {
  2374. function Tokenizer (decorated, $element, options) {
  2375. var tokenizer = options.get('tokenizer');
  2376. if (tokenizer !== undefined) {
  2377. this.tokenizer = tokenizer;
  2378. }
  2379. decorated.call(this, $element, options);
  2380. }
  2381. Tokenizer.prototype.bind = function (decorated, container, $container) {
  2382. decorated.call(this, container, $container);
  2383. this.$search = container.dropdown.$search || container.selection.$search ||
  2384. $container.find('.select2-search__field');
  2385. };
  2386. Tokenizer.prototype.query = function (decorated, params, callback) {
  2387. var self = this;
  2388. function select (data) {
  2389. self.select(data);
  2390. }
  2391. params.term = params.term || '';
  2392. var tokenData = this.tokenizer(params, this.options, select);
  2393. if (tokenData.term !== params.term) {
  2394. // Replace the search term if we have the search box
  2395. if (this.$search.length) {
  2396. this.$search.val(tokenData.term);
  2397. this.$search.focus();
  2398. }
  2399. params.term = tokenData.term;
  2400. }
  2401. decorated.call(this, params, callback);
  2402. };
  2403. Tokenizer.prototype.tokenizer = function (_, params, options, callback) {
  2404. var separators = options.get('tokenSeparators') || [];
  2405. var term = params.term;
  2406. var i = 0;
  2407. var createTag = this.createTag || function (params) {
  2408. return {
  2409. id: params.term,
  2410. text: params.term
  2411. };
  2412. };
  2413. while (i < term.length) {
  2414. var termChar = term[i];
  2415. if ($.inArray(termChar, separators) === -1) {
  2416. i++;
  2417. continue;
  2418. }
  2419. var part = term.substr(0, i);
  2420. var partParams = $.extend({}, params, {
  2421. term: part
  2422. });
  2423. var data = createTag(partParams);
  2424. callback(data);
  2425. // Reset the term to not include the tokenized portion
  2426. term = term.substr(i + 1) || '';
  2427. i = 0;
  2428. }
  2429. return {
  2430. term: term
  2431. };
  2432. };
  2433. return Tokenizer;
  2434. });
  2435. define('select2/data/minimumInputLength',[
  2436. ], function () {
  2437. function MinimumInputLength (decorated, $e, options) {
  2438. this.minimumInputLength = options.get('minimumInputLength');
  2439. decorated.call(this, $e, options);
  2440. }
  2441. MinimumInputLength.prototype.query = function (decorated, params, callback) {
  2442. params.term = params.term || '';
  2443. if (params.term.length < this.minimumInputLength) {
  2444. this.trigger('results:message', {
  2445. message: 'inputTooShort',
  2446. args: {
  2447. minimum: this.minimumInputLength,
  2448. input: params.term,
  2449. params: params
  2450. }
  2451. });
  2452. return;
  2453. }
  2454. decorated.call(this, params, callback);
  2455. };
  2456. return MinimumInputLength;
  2457. });
  2458. define('select2/data/maximumInputLength',[
  2459. ], function () {
  2460. function MaximumInputLength (decorated, $e, options) {
  2461. this.maximumInputLength = options.get('maximumInputLength');
  2462. decorated.call(this, $e, options);
  2463. }
  2464. MaximumInputLength.prototype.query = function (decorated, params, callback) {
  2465. params.term = params.term || '';
  2466. if (this.maximumInputLength > 0 &&
  2467. params.term.length > this.maximumInputLength) {
  2468. this.trigger('results:message', {
  2469. message: 'inputTooLong',
  2470. args: {
  2471. maximum: this.maximumInputLength,
  2472. input: params.term,
  2473. params: params
  2474. }
  2475. });
  2476. return;
  2477. }
  2478. decorated.call(this, params, callback);
  2479. };
  2480. return MaximumInputLength;
  2481. });
  2482. define('select2/data/maximumSelectionLength',[
  2483. ], function (){
  2484. function MaximumSelectionLength (decorated, $e, options) {
  2485. this.maximumSelectionLength = options.get('maximumSelectionLength');
  2486. decorated.call(this, $e, options);
  2487. }
  2488. MaximumSelectionLength.prototype.query =
  2489. function (decorated, params, callback) {
  2490. var self = this;
  2491. this.current(function (currentData) {
  2492. var count = currentData != null ? currentData.length : 0;
  2493. if (self.maximumSelectionLength > 0 &&
  2494. count >= self.maximumSelectionLength) {
  2495. self.trigger('results:message', {
  2496. message: 'maximumSelected',
  2497. args: {
  2498. maximum: self.maximumSelectionLength
  2499. }
  2500. });
  2501. return;
  2502. }
  2503. decorated.call(self, params, callback);
  2504. });
  2505. };
  2506. return MaximumSelectionLength;
  2507. });
  2508. define('select2/dropdown',[
  2509. 'jquery',
  2510. './utils'
  2511. ], function ($, Utils) {
  2512. function Dropdown ($element, options) {
  2513. this.$element = $element;
  2514. this.options = options;
  2515. Dropdown.__super__.constructor.call(this);
  2516. }
  2517. Utils.Extend(Dropdown, Utils.Observable);
  2518. Dropdown.prototype.render = function () {
  2519. var $dropdown = $(
  2520. '<span class="select2-dropdown">' +
  2521. '<span class="select2-results"></span>' +
  2522. '</span>'
  2523. );
  2524. $dropdown.attr('dir', this.options.get('dir'));
  2525. this.$dropdown = $dropdown;
  2526. return $dropdown;
  2527. };
  2528. Dropdown.prototype.position = function ($dropdown, $container) {
  2529. // Should be implmented in subclasses
  2530. };
  2531. Dropdown.prototype.destroy = function () {
  2532. // Remove the dropdown from the DOM
  2533. this.$dropdown.remove();
  2534. };
  2535. return Dropdown;
  2536. });
  2537. define('select2/dropdown/search',[
  2538. 'jquery',
  2539. '../utils'
  2540. ], function ($, Utils) {
  2541. function Search () { }
  2542. Search.prototype.render = function (decorated) {
  2543. var $rendered = decorated.call(this);
  2544. var $search = $(
  2545. '<span class="select2-search select2-search--dropdown">' +
  2546. '<input class="select2-search__field" type="search" tabindex="-1"' +
  2547. ' autocomplete="off" autocorrect="off" autocapitalize="off"' +
  2548. ' spellcheck="false" role="textbox" />' +
  2549. '</span>'
  2550. );
  2551. this.$searchContainer = $search;
  2552. this.$search = $search.find('input');
  2553. $rendered.prepend($search);
  2554. return $rendered;
  2555. };
  2556. Search.prototype.bind = function (decorated, container, $container) {
  2557. var self = this;
  2558. decorated.call(this, container, $container);
  2559. this.$search.on('keydown', function (evt) {
  2560. self.trigger('keypress', evt);
  2561. self._keyUpPrevented = evt.isDefaultPrevented();
  2562. });
  2563. this.$search.on('keyup', function (evt) {
  2564. self.handleSearch(evt);
  2565. });
  2566. container.on('open', function () {
  2567. self.$search.attr('tabindex', 0);
  2568. self.$search.focus();
  2569. window.setTimeout(function () {
  2570. self.$search.focus();
  2571. }, 0);
  2572. });
  2573. container.on('close', function () {
  2574. self.$search.attr('tabindex', -1);
  2575. self.$search.val('');
  2576. });
  2577. container.on('results:all', function (params) {
  2578. if (params.query.term == null || params.query.term === '') {
  2579. var showSearch = self.showSearch(params);
  2580. if (showSearch) {
  2581. self.$searchContainer.removeClass('select2-search--hide');
  2582. } else {
  2583. self.$searchContainer.addClass('select2-search--hide');
  2584. }
  2585. }
  2586. });
  2587. };
  2588. Search.prototype.handleSearch = function (evt) {
  2589. if (!this._keyUpPrevented) {
  2590. var input = this.$search.val();
  2591. this.trigger('query', {
  2592. term: input
  2593. });
  2594. }
  2595. this._keyUpPrevented = false;
  2596. };
  2597. Search.prototype.showSearch = function (_, params) {
  2598. return true;
  2599. };
  2600. return Search;
  2601. });
  2602. define('select2/dropdown/hidePlaceholder',[
  2603. ], function () {
  2604. function HidePlaceholder (decorated, $element, options, dataAdapter) {
  2605. this.placeholder = this.normalizePlaceholder(options.get('placeholder'));
  2606. decorated.call(this, $element, options, dataAdapter);
  2607. }
  2608. HidePlaceholder.prototype.append = function (decorated, data) {
  2609. data.results = this.removePlaceholder(data.results);
  2610. decorated.call(this, data);
  2611. };
  2612. HidePlaceholder.prototype.normalizePlaceholder = function (_, placeholder) {
  2613. if (typeof placeholder === 'string') {
  2614. placeholder = {
  2615. id: '',
  2616. text: placeholder
  2617. };
  2618. }
  2619. return placeholder;
  2620. };
  2621. HidePlaceholder.prototype.removePlaceholder = function (_, data) {
  2622. var modifiedData = data.slice(0);
  2623. for (var d = data.length - 1; d >= 0; d--) {
  2624. var item = data[d];
  2625. if (this.placeholder.id === item.id) {
  2626. modifiedData.splice(d, 1);
  2627. }
  2628. }
  2629. return modifiedData;
  2630. };
  2631. return HidePlaceholder;
  2632. });
  2633. define('select2/dropdown/infiniteScroll',[
  2634. 'jquery'
  2635. ], function ($) {
  2636. function InfiniteScroll (decorated, $element, options, dataAdapter) {
  2637. this.lastParams = {};
  2638. decorated.call(this, $element, options, dataAdapter);
  2639. this.$loadingMore = this.createLoadingMore();
  2640. this.loading = false;
  2641. }
  2642. InfiniteScroll.prototype.append = function (decorated, data) {
  2643. this.$loadingMore.remove();
  2644. this.loading = false;
  2645. decorated.call(this, data);
  2646. if (this.showLoadingMore(data)) {
  2647. this.$results.append(this.$loadingMore);
  2648. }
  2649. };
  2650. InfiniteScroll.prototype.bind = function (decorated, container, $container) {
  2651. var self = this;
  2652. decorated.call(this, container, $container);
  2653. container.on('query', function (params) {
  2654. self.lastParams = params;
  2655. self.loading = true;
  2656. });
  2657. container.on('query:append', function (params) {
  2658. self.lastParams = params;
  2659. self.loading = true;
  2660. });
  2661. this.$results.on('scroll', function () {
  2662. var isLoadMoreVisible = $.contains(
  2663. document.documentElement,
  2664. self.$loadingMore[0]
  2665. );
  2666. if (self.loading || !isLoadMoreVisible) {
  2667. return;
  2668. }
  2669. var currentOffset = self.$results.offset().top +
  2670. self.$results.outerHeight(false);
  2671. var loadingMoreOffset = self.$loadingMore.offset().top +
  2672. self.$loadingMore.outerHeight(false);
  2673. if (currentOffset + 50 >= loadingMoreOffset) {
  2674. self.loadMore();
  2675. }
  2676. });
  2677. };
  2678. InfiniteScroll.prototype.loadMore = function () {
  2679. this.loading = true;
  2680. var params = $.extend({}, {page: 1}, this.lastParams);
  2681. params.page++;
  2682. this.trigger('query:append', params);
  2683. };
  2684. InfiniteScroll.prototype.showLoadingMore = function (_, data) {
  2685. return data.pagination && data.pagination.more;
  2686. };
  2687. InfiniteScroll.prototype.createLoadingMore = function () {
  2688. var $option = $(
  2689. '<li class="option load-more" role="treeitem"></li>'
  2690. );
  2691. var message = this.options.get('translations').get('loadingMore');
  2692. $option.html(message(this.lastParams));
  2693. return $option;
  2694. };
  2695. return InfiniteScroll;
  2696. });
  2697. define('select2/dropdown/attachBody',[
  2698. 'jquery',
  2699. '../utils'
  2700. ], function ($, Utils) {
  2701. function AttachBody (decorated, $element, options) {
  2702. this.$dropdownParent = options.get('dropdownParent') || document.body;
  2703. decorated.call(this, $element, options);
  2704. }
  2705. AttachBody.prototype.bind = function (decorated, container, $container) {
  2706. var self = this;
  2707. var setupResultsEvents = false;
  2708. decorated.call(this, container, $container);
  2709. container.on('open', function () {
  2710. self._showDropdown();
  2711. self._attachPositioningHandler(container);
  2712. if (!setupResultsEvents) {
  2713. setupResultsEvents = true;
  2714. container.on('results:all', function () {
  2715. self._positionDropdown();
  2716. self._resizeDropdown();
  2717. });
  2718. container.on('results:append', function () {
  2719. self._positionDropdown();
  2720. self._resizeDropdown();
  2721. });
  2722. }
  2723. });
  2724. container.on('close', function () {
  2725. self._hideDropdown();
  2726. self._detachPositioningHandler(container);
  2727. });
  2728. this.$dropdownContainer.on('mousedown', function (evt) {
  2729. evt.stopPropagation();
  2730. });
  2731. };
  2732. AttachBody.prototype.position = function (decorated, $dropdown, $container) {
  2733. // Clone all of the container classes
  2734. $dropdown.attr('class', $container.attr('class'));
  2735. $dropdown.removeClass('select2');
  2736. $dropdown.addClass('select2-container--open');
  2737. $dropdown.css({
  2738. position: 'absolute',
  2739. top: -999999
  2740. });
  2741. this.$container = $container;
  2742. };
  2743. AttachBody.prototype.render = function (decorated) {
  2744. var $container = $('<span></span>');
  2745. var $dropdown = decorated.call(this);
  2746. $container.append($dropdown);
  2747. this.$dropdownContainer = $container;
  2748. return $container;
  2749. };
  2750. AttachBody.prototype._hideDropdown = function (decorated) {
  2751. this.$dropdownContainer.detach();
  2752. };
  2753. AttachBody.prototype._attachPositioningHandler = function (container) {
  2754. var self = this;
  2755. var scrollEvent = 'scroll.select2.' + container.id;
  2756. var resizeEvent = 'resize.select2.' + container.id;
  2757. var orientationEvent = 'orientationchange.select2.' + container.id;
  2758. var $watchers = this.$container.parents().filter(Utils.hasScroll);
  2759. $watchers.each(function () {
  2760. $(this).data('select2-scroll-position', {
  2761. x: $(this).scrollLeft(),
  2762. y: $(this).scrollTop()
  2763. });
  2764. });
  2765. $watchers.on(scrollEvent, function (ev) {
  2766. var position = $(this).data('select2-scroll-position');
  2767. $(this).scrollTop(position.y);
  2768. });
  2769. $(window).on(scrollEvent + ' ' + resizeEvent + ' ' + orientationEvent,
  2770. function (e) {
  2771. self._positionDropdown();
  2772. self._resizeDropdown();
  2773. });
  2774. };
  2775. AttachBody.prototype._detachPositioningHandler = function (container) {
  2776. var scrollEvent = 'scroll.select2.' + container.id;
  2777. var resizeEvent = 'resize.select2.' + container.id;
  2778. var orientationEvent = 'orientationchange.select2.' + container.id;
  2779. var $watchers = this.$container.parents().filter(Utils.hasScroll);
  2780. $watchers.off(scrollEvent);
  2781. $(window).off(scrollEvent + ' ' + resizeEvent + ' ' + orientationEvent);
  2782. };
  2783. AttachBody.prototype._positionDropdown = function () {
  2784. var $window = $(window);
  2785. var isCurrentlyAbove = this.$dropdown.hasClass('select2-dropdown--above');
  2786. var isCurrentlyBelow = this.$dropdown.hasClass('select2-dropdown--below');
  2787. var newDirection = null;
  2788. var position = this.$container.position();
  2789. var offset = this.$container.offset();
  2790. offset.bottom = offset.top + this.$container.outerHeight(false);
  2791. var container = {
  2792. height: this.$container.outerHeight(false)
  2793. };
  2794. container.top = offset.top;
  2795. container.bottom = offset.top + container.height;
  2796. var dropdown = {
  2797. height: this.$dropdown.outerHeight(false)
  2798. };
  2799. var viewport = {
  2800. top: $window.scrollTop(),
  2801. bottom: $window.scrollTop() + $window.height()
  2802. };
  2803. var enoughRoomAbove = viewport.top < (offset.top - dropdown.height);
  2804. var enoughRoomBelow = viewport.bottom > (offset.bottom + dropdown.height);
  2805. var css = {
  2806. left: offset.left,
  2807. top: container.bottom
  2808. };
  2809. if (!isCurrentlyAbove && !isCurrentlyBelow) {
  2810. newDirection = 'below';
  2811. }
  2812. if (!enoughRoomBelow && enoughRoomAbove && !isCurrentlyAbove) {
  2813. newDirection = 'above';
  2814. } else if (!enoughRoomAbove && enoughRoomBelow && isCurrentlyAbove) {
  2815. newDirection = 'below';
  2816. }
  2817. if (newDirection == 'above' ||
  2818. (isCurrentlyAbove && newDirection !== 'below')) {
  2819. css.top = container.top - dropdown.height;
  2820. }
  2821. if (newDirection != null) {
  2822. this.$dropdown
  2823. .removeClass('select2-dropdown--below select2-dropdown--above')
  2824. .addClass('select2-dropdown--' + newDirection);
  2825. this.$container
  2826. .removeClass('select2-container--below select2-container--above')
  2827. .addClass('select2-container--' + newDirection);
  2828. }
  2829. this.$dropdownContainer.css(css);
  2830. };
  2831. AttachBody.prototype._resizeDropdown = function () {
  2832. this.$dropdownContainer.width();
  2833. this.$dropdown.css({
  2834. width: this.$container.outerWidth(false) + 'px'
  2835. });
  2836. };
  2837. AttachBody.prototype._showDropdown = function (decorated) {
  2838. this.$dropdownContainer.appendTo(this.$dropdownParent);
  2839. this._positionDropdown();
  2840. this._resizeDropdown();
  2841. };
  2842. return AttachBody;
  2843. });
  2844. define('select2/dropdown/minimumResultsForSearch',[
  2845. ], function () {
  2846. function countResults (data) {
  2847. var count = 0;
  2848. for (var d = 0; d < data.length; d++) {
  2849. var item = data[d];
  2850. if (item.children) {
  2851. count += countResults(item.children);
  2852. } else {
  2853. count++;
  2854. }
  2855. }
  2856. return count;
  2857. }
  2858. function MinimumResultsForSearch (decorated, $element, options, dataAdapter) {
  2859. this.minimumResultsForSearch = options.get('minimumResultsForSearch');
  2860. if (this.minimumResultsForSearch < 0) {
  2861. this.minimumResultsForSearch = Infinity;
  2862. }
  2863. decorated.call(this, $element, options, dataAdapter);
  2864. }
  2865. MinimumResultsForSearch.prototype.showSearch = function (decorated, params) {
  2866. if (countResults(params.data.results) < this.minimumResultsForSearch) {
  2867. return false;
  2868. }
  2869. return decorated.call(this, params);
  2870. };
  2871. return MinimumResultsForSearch;
  2872. });
  2873. define('select2/dropdown/selectOnClose',[
  2874. ], function () {
  2875. function SelectOnClose () { }
  2876. SelectOnClose.prototype.bind = function (decorated, container, $container) {
  2877. var self = this;
  2878. decorated.call(this, container, $container);
  2879. container.on('close', function () {
  2880. self._handleSelectOnClose();
  2881. });
  2882. };
  2883. SelectOnClose.prototype._handleSelectOnClose = function () {
  2884. var $highlightedResults = this.getHighlightedResults();
  2885. if ($highlightedResults.length < 1) {
  2886. return;
  2887. }
  2888. $highlightedResults.trigger('mouseup');
  2889. };
  2890. return SelectOnClose;
  2891. });
  2892. define('select2/dropdown/closeOnSelect',[
  2893. ], function () {
  2894. function CloseOnSelect () { }
  2895. CloseOnSelect.prototype.bind = function (decorated, container, $container) {
  2896. var self = this;
  2897. decorated.call(this, container, $container);
  2898. container.on('select', function (evt) {
  2899. var originalEvent = evt.originalEvent;
  2900. // Don't close if the control key is being held
  2901. if (originalEvent && originalEvent.ctrlKey) {
  2902. return;
  2903. }
  2904. self.trigger('close');
  2905. });
  2906. };
  2907. return CloseOnSelect;
  2908. });
  2909. define('select2/i18n/en',[],function () {
  2910. // English
  2911. return {
  2912. errorLoading: function () {
  2913. return 'The results could not be loaded.';
  2914. },
  2915. inputTooLong: function (args) {
  2916. var overChars = args.input.length - args.maximum;
  2917. var message = 'Please delete ' + overChars + ' character';
  2918. if (overChars != 1) {
  2919. message += 's';
  2920. }
  2921. return message;
  2922. },
  2923. inputTooShort: function (args) {
  2924. var remainingChars = args.minimum - args.input.length;
  2925. var message = 'Please enter ' + remainingChars + ' or more characters';
  2926. return message;
  2927. },
  2928. loadingMore: function () {
  2929. return 'Loading more results…';
  2930. },
  2931. maximumSelected: function (args) {
  2932. var message = 'You can only select ' + args.maximum + ' item';
  2933. if (args.maximum != 1) {
  2934. message += 's';
  2935. }
  2936. return message;
  2937. },
  2938. noResults: function () {
  2939. return 'No results found';
  2940. },
  2941. searching: function () {
  2942. return 'Searching…';
  2943. }
  2944. };
  2945. });
  2946. define('select2/defaults',[
  2947. 'jquery',
  2948. './results',
  2949. './selection/single',
  2950. './selection/multiple',
  2951. './selection/placeholder',
  2952. './selection/allowClear',
  2953. './selection/search',
  2954. './selection/eventRelay',
  2955. './utils',
  2956. './translation',
  2957. './diacritics',
  2958. './data/select',
  2959. './data/array',
  2960. './data/ajax',
  2961. './data/tags',
  2962. './data/tokenizer',
  2963. './data/minimumInputLength',
  2964. './data/maximumInputLength',
  2965. './data/maximumSelectionLength',
  2966. './dropdown',
  2967. './dropdown/search',
  2968. './dropdown/hidePlaceholder',
  2969. './dropdown/infiniteScroll',
  2970. './dropdown/attachBody',
  2971. './dropdown/minimumResultsForSearch',
  2972. './dropdown/selectOnClose',
  2973. './dropdown/closeOnSelect',
  2974. './i18n/en'
  2975. ], function ($, ResultsList,
  2976. SingleSelection, MultipleSelection, Placeholder, AllowClear,
  2977. SelectionSearch, EventRelay,
  2978. Utils, Translation, DIACRITICS,
  2979. SelectData, ArrayData, AjaxData, Tags, Tokenizer,
  2980. MinimumInputLength, MaximumInputLength, MaximumSelectionLength,
  2981. Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
  2982. AttachBody, MinimumResultsForSearch, SelectOnClose, CloseOnSelect,
  2983. EnglishTranslation) {
  2984. function Defaults () {
  2985. this.reset();
  2986. }
  2987. Defaults.prototype.apply = function (options) {
  2988. options = $.extend({}, this.defaults, options);
  2989. if (options.dataAdapter == null) {
  2990. if (options.ajax != null) {
  2991. options.dataAdapter = AjaxData;
  2992. } else if (options.data != null) {
  2993. options.dataAdapter = ArrayData;
  2994. } else {
  2995. options.dataAdapter = SelectData;
  2996. }
  2997. if (options.minimumInputLength > 0) {
  2998. options.dataAdapter = Utils.Decorate(
  2999. options.dataAdapter,
  3000. MinimumInputLength
  3001. );
  3002. }
  3003. if (options.maximumInputLength > 0) {
  3004. options.dataAdapter = Utils.Decorate(
  3005. options.dataAdapter,
  3006. MaximumInputLength
  3007. );
  3008. }
  3009. if (options.maximumSelectionLength > 0) {
  3010. options.dataAdapter = Utils.Decorate(
  3011. options.dataAdapter,
  3012. MaximumSelectionLength
  3013. );
  3014. }
  3015. if (options.tags != null) {
  3016. options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
  3017. }
  3018. if (options.tokenSeparators != null || options.tokenizer != null) {
  3019. options.dataAdapter = Utils.Decorate(
  3020. options.dataAdapter,
  3021. Tokenizer
  3022. );
  3023. }
  3024. if (options.query != null) {
  3025. var Query = require(options.amdBase + 'compat/query');
  3026. options.dataAdapter = Utils.Decorate(
  3027. options.dataAdapter,
  3028. Query
  3029. );
  3030. }
  3031. if (options.initSelection != null) {
  3032. var InitSelection = require(options.amdBase + 'compat/initSelection');
  3033. options.dataAdapter = Utils.Decorate(
  3034. options.dataAdapter,
  3035. InitSelection
  3036. );
  3037. }
  3038. }
  3039. if (options.resultsAdapter == null) {
  3040. options.resultsAdapter = ResultsList;
  3041. if (options.ajax != null) {
  3042. options.resultsAdapter = Utils.Decorate(
  3043. options.resultsAdapter,
  3044. InfiniteScroll
  3045. );
  3046. }
  3047. if (options.placeholder != null) {
  3048. options.resultsAdapter = Utils.Decorate(
  3049. options.resultsAdapter,
  3050. HidePlaceholder
  3051. );
  3052. }
  3053. if (options.selectOnClose) {
  3054. options.resultsAdapter = Utils.Decorate(
  3055. options.resultsAdapter,
  3056. SelectOnClose
  3057. );
  3058. }
  3059. }
  3060. if (options.dropdownAdapter == null) {
  3061. if (options.multiple) {
  3062. options.dropdownAdapter = Dropdown;
  3063. } else {
  3064. var SearchableDropdown = Utils.Decorate(Dropdown, DropdownSearch);
  3065. options.dropdownAdapter = SearchableDropdown;
  3066. }
  3067. if (options.minimumResultsForSearch > 0) {
  3068. options.dropdownAdapter = Utils.Decorate(
  3069. options.dropdownAdapter,
  3070. MinimumResultsForSearch
  3071. );
  3072. }
  3073. if (options.closeOnSelect) {
  3074. options.dropdownAdapter = Utils.Decorate(
  3075. options.dropdownAdapter,
  3076. CloseOnSelect
  3077. );
  3078. }
  3079. options.dropdownAdapter = Utils.Decorate(
  3080. options.dropdownAdapter,
  3081. AttachBody
  3082. );
  3083. }
  3084. if (options.selectionAdapter == null) {
  3085. if (options.multiple) {
  3086. options.selectionAdapter = MultipleSelection;
  3087. } else {
  3088. options.selectionAdapter = SingleSelection;
  3089. }
  3090. // Add the placeholder mixin if a placeholder was specified
  3091. if (options.placeholder != null) {
  3092. options.selectionAdapter = Utils.Decorate(
  3093. options.selectionAdapter,
  3094. Placeholder
  3095. );
  3096. }
  3097. if (options.allowClear) {
  3098. options.selectionAdapter = Utils.Decorate(
  3099. options.selectionAdapter,
  3100. AllowClear
  3101. );
  3102. }
  3103. if (options.multiple) {
  3104. options.selectionAdapter = Utils.Decorate(
  3105. options.selectionAdapter,
  3106. SelectionSearch
  3107. );
  3108. }
  3109. options.selectionAdapter = Utils.Decorate(
  3110. options.selectionAdapter,
  3111. EventRelay
  3112. );
  3113. }
  3114. if (typeof options.language === 'string') {
  3115. // Check if the lanugage is specified with a region
  3116. if (options.language.indexOf('-') > 0) {
  3117. // Extract the region information if it is included
  3118. var languageParts = options.language.split('-');
  3119. var baseLanguage = languageParts[0];
  3120. options.language = [options.language, baseLanguage];
  3121. } else {
  3122. options.language = [options.language];
  3123. }
  3124. }
  3125. if ($.isArray(options.language)) {
  3126. var languages = new Translation();
  3127. options.language.push('en');
  3128. var languageNames = options.language;
  3129. for (var l = 0; l < languageNames.length; l++) {
  3130. var name = languageNames[l];
  3131. var language = {};
  3132. try {
  3133. // Try to load it with the original name
  3134. language = Translation.loadPath(name);
  3135. } catch (e) {
  3136. try {
  3137. // If we couldn't load it, check if it wasn't the full path
  3138. name = this.defaults.amdLanguageBase + name;
  3139. language = Translation.loadPath(name);
  3140. } catch (ex) {
  3141. // The translation could not be loaded at all. Sometimes this is
  3142. // because of a configuration problem, other times this can be
  3143. // because of how Select2 helps load all possible translation files.
  3144. if (window.console && console.warn) {
  3145. console.warn(
  3146. 'Select2: The lanugage file for "' + name + '" could not be ' +
  3147. 'automatically loaded. A fallback will be used instead.'
  3148. );
  3149. }
  3150. continue;
  3151. }
  3152. }
  3153. languages.extend(language);
  3154. }
  3155. options.translations = languages;
  3156. } else {
  3157. options.translations = new Translation(options.language);
  3158. }
  3159. return options;
  3160. };
  3161. Defaults.prototype.reset = function () {
  3162. function stripDiacritics (text) {
  3163. // Used 'uni range + named function' from http://jsperf.com/diacritics/18
  3164. function match(a) {
  3165. return DIACRITICS[a] || a;
  3166. }
  3167. return text.replace(/[^\u0000-\u007E]/g, match);
  3168. }
  3169. function matcher (params, data) {
  3170. // Always return the object if there is nothing to compare
  3171. if ($.trim(params.term) === '') {
  3172. return data;
  3173. }
  3174. // Do a recursive check for options with children
  3175. if (data.children && data.children.length > 0) {
  3176. // Clone the data object if there are children
  3177. // This is required as we modify the object to remove any non-matches
  3178. var match = $.extend(true, {}, data);
  3179. // Check each child of the option
  3180. for (var c = data.children.length - 1; c >= 0; c--) {
  3181. var child = data.children[c];
  3182. var matches = matcher(params, child);
  3183. // If there wasn't a match, remove the object in the array
  3184. if (matches == null) {
  3185. match.children.splice(c, 1);
  3186. }
  3187. }
  3188. // If any children matched, return the new object
  3189. if (match.children.length > 0) {
  3190. return match;
  3191. }
  3192. // If there were no matching children, check just the plain object
  3193. return matcher(params, match);
  3194. }
  3195. var original = stripDiacritics(data.text).toUpperCase();
  3196. var term = stripDiacritics(params.term).toUpperCase();
  3197. // Check if the text contains the term
  3198. if (original.indexOf(term) > -1) {
  3199. return data;
  3200. }
  3201. // If it doesn't contain the term, don't return anything
  3202. return null;
  3203. }
  3204. this.defaults = {
  3205. amdBase: 'select2/',
  3206. amdLanguageBase: 'select2/i18n/',
  3207. closeOnSelect: true,
  3208. escapeMarkup: Utils.escapeMarkup,
  3209. language: EnglishTranslation,
  3210. matcher: matcher,
  3211. minimumInputLength: 0,
  3212. maximumInputLength: 0,
  3213. maximumSelectionLength: 0,
  3214. minimumResultsForSearch: 0,
  3215. selectOnClose: false,
  3216. sorter: function (data) {
  3217. return data;
  3218. },
  3219. templateResult: function (result) {
  3220. return result.text;
  3221. },
  3222. templateSelection: function (selection) {
  3223. return selection.text;
  3224. },
  3225. theme: 'default',
  3226. width: 'resolve'
  3227. };
  3228. };
  3229. Defaults.prototype.set = function (key, value) {
  3230. var camelKey = $.camelCase(key);
  3231. var data = {};
  3232. data[camelKey] = value;
  3233. var convertedData = Utils._convertData(data);
  3234. $.extend(this.defaults, convertedData);
  3235. };
  3236. var defaults = new Defaults();
  3237. return defaults;
  3238. });
  3239. define('select2/options',[
  3240. 'jquery',
  3241. './defaults',
  3242. './utils'
  3243. ], function ($, Defaults, Utils) {
  3244. function Options (options, $element) {
  3245. this.options = options;
  3246. if ($element != null) {
  3247. this.fromElement($element);
  3248. }
  3249. this.options = Defaults.apply(this.options);
  3250. }
  3251. Options.prototype.fromElement = function ($e) {
  3252. var excludedData = ['select2'];
  3253. if (this.options.multiple == null) {
  3254. this.options.multiple = $e.prop('multiple');
  3255. }
  3256. if (this.options.disabled == null) {
  3257. this.options.disabled = $e.prop('disabled');
  3258. }
  3259. if (this.options.language == null) {
  3260. if ($e.prop('lang')) {
  3261. this.options.language = $e.prop('lang').toLowerCase();
  3262. } else if ($e.closest('[lang]').prop('lang')) {
  3263. this.options.language = $e.closest('[lang]').prop('lang');
  3264. }
  3265. }
  3266. if (this.options.dir == null) {
  3267. if ($e.prop('dir')) {
  3268. this.options.dir = $e.prop('dir');
  3269. } else if ($e.closest('[dir]').prop('dir')) {
  3270. this.options.dir = $e.closest('[dir]').prop('dir');
  3271. } else {
  3272. this.options.dir = 'ltr';
  3273. }
  3274. }
  3275. $e.prop('disabled', this.options.disabled);
  3276. $e.prop('multiple', this.options.multiple);
  3277. if ($e.data('select2-tags')) {
  3278. if (window.console && console.warn) {
  3279. console.warn(
  3280. 'Select2: The `data-select2-tags` attribute has been changed to ' +
  3281. 'use the `data-data` and `data-tags="true"` attributes and will be ' +
  3282. 'removed in future versions of Select2.'
  3283. );
  3284. }
  3285. $e.data('data', $e.data('select2-tags'));
  3286. $e.data('tags', true);
  3287. }
  3288. if ($e.data('ajax-url')) {
  3289. if (window.console && console.warn) {
  3290. console.warn(
  3291. 'Select2: The `data-ajax-url` attribute has been changed to ' +
  3292. '`data-ajax--url` and support for the old attribute will be removed' +
  3293. ' in future versions of Select2.'
  3294. );
  3295. }
  3296. $e.data('ajax--url', $e.data('ajax-url'));
  3297. }
  3298. var data = $e.data();
  3299. data = Utils._convertData(data);
  3300. for (var key in data) {
  3301. if ($.inArray(key, excludedData) > -1) {
  3302. continue;
  3303. }
  3304. if ($.isPlainObject(this.options[key])) {
  3305. $.extend(this.options[key], data[key]);
  3306. } else {
  3307. this.options[key] = data[key];
  3308. }
  3309. }
  3310. return this;
  3311. };
  3312. Options.prototype.get = function (key) {
  3313. return this.options[key];
  3314. };
  3315. Options.prototype.set = function (key, val) {
  3316. this.options[key] = val;
  3317. };
  3318. return Options;
  3319. });
  3320. define('select2/core',[
  3321. 'jquery',
  3322. './options',
  3323. './utils',
  3324. './keys'
  3325. ], function ($, Options, Utils, KEYS) {
  3326. var Select2 = function ($element, options) {
  3327. if ($element.data('select2') != null) {
  3328. $element.data('select2').destroy();
  3329. }
  3330. this.$element = $element;
  3331. this.id = this._generateId($element);
  3332. options = options || {};
  3333. this.options = new Options(options, $element);
  3334. Select2.__super__.constructor.call(this);
  3335. // Set up the tabindex
  3336. var tabindex = $element.attr('tabindex') || 0;
  3337. $element.data('old-tabindex', tabindex);
  3338. $element.attr('tabindex', '-1');
  3339. // Set up containers and adapters
  3340. var DataAdapter = this.options.get('dataAdapter');
  3341. this.data = new DataAdapter($element, this.options);
  3342. var $container = this.render();
  3343. this._placeContainer($container);
  3344. var SelectionAdapter = this.options.get('selectionAdapter');
  3345. this.selection = new SelectionAdapter($element, this.options);
  3346. this.$selection = this.selection.render();
  3347. this.selection.position(this.$selection, $container);
  3348. var DropdownAdapter = this.options.get('dropdownAdapter');
  3349. this.dropdown = new DropdownAdapter($element, this.options);
  3350. this.$dropdown = this.dropdown.render();
  3351. this.dropdown.position(this.$dropdown, $container);
  3352. var ResultsAdapter = this.options.get('resultsAdapter');
  3353. this.results = new ResultsAdapter($element, this.options, this.data);
  3354. this.$results = this.results.render();
  3355. this.results.position(this.$results, this.$dropdown);
  3356. // Bind events
  3357. var self = this;
  3358. // Bind the container to all of the adapters
  3359. this._bindAdapters();
  3360. // Register any DOM event handlers
  3361. this._registerDomEvents();
  3362. // Register any internal event handlers
  3363. this._registerDataEvents();
  3364. this._registerSelectionEvents();
  3365. this._registerDropdownEvents();
  3366. this._registerResultsEvents();
  3367. this._registerEvents();
  3368. // Set the initial state
  3369. this.data.current(function (initialData) {
  3370. self.trigger('selection:update', {
  3371. data: initialData
  3372. });
  3373. });
  3374. // Hide the original select
  3375. $element.hide();
  3376. // Synchronize any monitored attributes
  3377. this._syncAttributes();
  3378. $element.data('select2', this);
  3379. };
  3380. Utils.Extend(Select2, Utils.Observable);
  3381. Select2.prototype._generateId = function ($element) {
  3382. var id = '';
  3383. if ($element.attr('id') != null) {
  3384. id = $element.attr('id');
  3385. } else if ($element.attr('name') != null) {
  3386. id = $element.attr('name') + '-' + Utils.generateChars(2);
  3387. } else {
  3388. id = Utils.generateChars(4);
  3389. }
  3390. id = 'select2-' + id;
  3391. return id;
  3392. };
  3393. Select2.prototype._placeContainer = function ($container) {
  3394. $container.insertAfter(this.$element);
  3395. var width = this._resolveWidth(this.$element, this.options.get('width'));
  3396. if (width != null) {
  3397. $container.css('width', width);
  3398. }
  3399. };
  3400. Select2.prototype._resolveWidth = function ($element, method) {
  3401. var WIDTH = /^width:(([-+]?([0-9]*\.)?[0-9]+)(px|em|ex|%|in|cm|mm|pt|pc))/i;
  3402. if (method == 'resolve') {
  3403. var styleWidth = this._resolveWidth($element, 'style');
  3404. if (styleWidth != null) {
  3405. return styleWidth;
  3406. }
  3407. return this._resolveWidth($element, 'element');
  3408. }
  3409. if (method == 'element') {
  3410. var elementWidth = $element.outerWidth(false);
  3411. if (elementWidth <= 0) {
  3412. return 'auto';
  3413. }
  3414. return elementWidth + 'px';
  3415. }
  3416. if (method == 'style') {
  3417. var style = $element.attr('style');
  3418. if (typeof(style) !== 'string') {
  3419. return null;
  3420. }
  3421. var attrs = style.split(';');
  3422. for (var i = 0, l = attrs.length; i < l; i = i + 1) {
  3423. var attr = attrs[i].replace(/\s/g, '');
  3424. var matches = attr.match(WIDTH);
  3425. if (matches !== null && matches.length >= 1) {
  3426. return matches[1];
  3427. }
  3428. }
  3429. return null;
  3430. }
  3431. return method;
  3432. };
  3433. Select2.prototype._bindAdapters = function () {
  3434. this.data.bind(this, this.$container);
  3435. this.selection.bind(this, this.$container);
  3436. this.dropdown.bind(this, this.$container);
  3437. this.results.bind(this, this.$container);
  3438. };
  3439. Select2.prototype._registerDomEvents = function () {
  3440. var self = this;
  3441. this.$element.on('change.select2', function () {
  3442. self.data.current(function (data) {
  3443. self.trigger('selection:update', {
  3444. data: data
  3445. });
  3446. });
  3447. });
  3448. this._sync = Utils.bind(this._syncAttributes, this);
  3449. if (this.$element[0].attachEvent) {
  3450. this.$element[0].attachEvent('onpropertychange', this._sync);
  3451. }
  3452. var observer = window.MutationObserver ||
  3453. window.WebKitMutationObserver ||
  3454. window.MozMutationObserver
  3455. ;
  3456. if (observer != null) {
  3457. this._observer = new observer(function (mutations) {
  3458. $.each(mutations, self._sync);
  3459. });
  3460. this._observer.observe(this.$element[0], {
  3461. attributes: true,
  3462. subtree: false
  3463. });
  3464. } else if (this.$element[0].addEventListener) {
  3465. this.$element[0].addEventListener('DOMAttrModified', self._sync, false);
  3466. }
  3467. };
  3468. Select2.prototype._registerDataEvents = function () {
  3469. var self = this;
  3470. this.data.on('*', function (name, params) {
  3471. self.trigger(name, params);
  3472. });
  3473. };
  3474. Select2.prototype._registerSelectionEvents = function () {
  3475. var self = this;
  3476. var nonRelayEvents = ['toggle'];
  3477. this.selection.on('toggle', function () {
  3478. self.toggleDropdown();
  3479. });
  3480. this.selection.on('*', function (name, params) {
  3481. if ($.inArray(name, nonRelayEvents) !== -1) {
  3482. return;
  3483. }
  3484. self.trigger(name, params);
  3485. });
  3486. };
  3487. Select2.prototype._registerDropdownEvents = function () {
  3488. var self = this;
  3489. this.dropdown.on('*', function (name, params) {
  3490. self.trigger(name, params);
  3491. });
  3492. };
  3493. Select2.prototype._registerResultsEvents = function () {
  3494. var self = this;
  3495. this.results.on('*', function (name, params) {
  3496. self.trigger(name, params);
  3497. });
  3498. };
  3499. Select2.prototype._registerEvents = function () {
  3500. var self = this;
  3501. this.on('open', function () {
  3502. self.$container.addClass('select2-container--open');
  3503. });
  3504. this.on('close', function () {
  3505. self.$container.removeClass('select2-container--open');
  3506. });
  3507. this.on('enable', function () {
  3508. self.$container.removeClass('select2-container--disabled');
  3509. });
  3510. this.on('disable', function () {
  3511. self.$container.addClass('select2-container--disabled');
  3512. });
  3513. this.on('focus', function () {
  3514. self.$container.addClass('select2-container--focus');
  3515. });
  3516. this.on('blur', function () {
  3517. self.$container.removeClass('select2-container--focus');
  3518. });
  3519. this.on('query', function (params) {
  3520. this.data.query(params, function (data) {
  3521. self.trigger('results:all', {
  3522. data: data,
  3523. query: params
  3524. });
  3525. });
  3526. });
  3527. this.on('query:append', function (params) {
  3528. this.data.query(params, function (data) {
  3529. self.trigger('results:append', {
  3530. data: data,
  3531. query: params
  3532. });
  3533. });
  3534. });
  3535. this.on('keypress', function (evt) {
  3536. var key = evt.which;
  3537. if (self.isOpen()) {
  3538. if (key === KEYS.ENTER) {
  3539. self.trigger('results:select');
  3540. evt.preventDefault();
  3541. } else if (key === KEYS.UP) {
  3542. self.trigger('results:previous');
  3543. evt.preventDefault();
  3544. } else if (key === KEYS.DOWN) {
  3545. self.trigger('results:next');
  3546. evt.preventDefault();
  3547. } else if (key === KEYS.ESC || key === KEYS.TAB) {
  3548. self.close();
  3549. evt.preventDefault();
  3550. }
  3551. } else {
  3552. if (key === KEYS.ENTER || key === KEYS.SPACE ||
  3553. ((key === KEYS.DOWN || key === KEYS.UP) && evt.altKey)) {
  3554. self.open();
  3555. evt.preventDefault();
  3556. }
  3557. }
  3558. });
  3559. };
  3560. Select2.prototype._syncAttributes = function () {
  3561. this.options.set('disabled', this.$element.prop('disabled'));
  3562. if (this.options.get('disabled')) {
  3563. if (this.isOpen()) {
  3564. this.close();
  3565. }
  3566. this.trigger('disable');
  3567. } else {
  3568. this.trigger('enable');
  3569. }
  3570. };
  3571. /**
  3572. * Override the trigger method to automatically trigger pre-events when
  3573. * there are events that can be prevented.
  3574. */
  3575. Select2.prototype.trigger = function (name, args) {
  3576. var actualTrigger = Select2.__super__.trigger;
  3577. var preTriggerMap = {
  3578. 'open': 'opening',
  3579. 'close': 'closing',
  3580. 'select': 'selecting',
  3581. 'unselect': 'unselecting'
  3582. };
  3583. if (name in preTriggerMap) {
  3584. var preTriggerName = preTriggerMap[name];
  3585. var preTriggerArgs = {
  3586. prevented: false,
  3587. name: name,
  3588. args: args
  3589. };
  3590. actualTrigger.call(this, preTriggerName, preTriggerArgs);
  3591. if (preTriggerArgs.prevented) {
  3592. args.prevented = true;
  3593. return;
  3594. }
  3595. }
  3596. actualTrigger.call(this, name, args);
  3597. };
  3598. Select2.prototype.toggleDropdown = function () {
  3599. if (this.options.get('disabled')) {
  3600. return;
  3601. }
  3602. if (this.isOpen()) {
  3603. this.close();
  3604. } else {
  3605. this.open();
  3606. }
  3607. };
  3608. Select2.prototype.open = function () {
  3609. if (this.isOpen()) {
  3610. return;
  3611. }
  3612. this.trigger('query', {});
  3613. this.trigger('open');
  3614. };
  3615. Select2.prototype.close = function () {
  3616. if (!this.isOpen()) {
  3617. return;
  3618. }
  3619. this.trigger('close');
  3620. };
  3621. Select2.prototype.isOpen = function () {
  3622. return this.$container.hasClass('select2-container--open');
  3623. };
  3624. Select2.prototype.enable = function (args) {
  3625. if (window.console && console.warn) {
  3626. console.warn(
  3627. 'Select2: The `select2("enable")` method has been deprecated and will' +
  3628. ' be removed in later Select2 versions. Use $element.prop("disabled")' +
  3629. ' instead.'
  3630. );
  3631. }
  3632. if (args.length === 0) {
  3633. args = [true];
  3634. }
  3635. var disabled = !args[0];
  3636. this.$element.prop('disabled', disabled);
  3637. };
  3638. Select2.prototype.data = function () {
  3639. if (arguments.length > 0 && window.console && console.warn) {
  3640. console.warn(
  3641. 'Select2: Data can no longer be set using `select2("data")`. You ' +
  3642. 'should consider setting the value instead using `$element.val()`.'
  3643. );
  3644. }
  3645. var data = [];
  3646. this.dataAdpater.current(function (currentData) {
  3647. data = currentData;
  3648. });
  3649. return data;
  3650. };
  3651. Select2.prototype.val = function (args) {
  3652. if (window.console && console.warn) {
  3653. console.warn(
  3654. 'Select2: The `select2("val")` method has been deprecated and will be' +
  3655. ' removed in later Select2 versions. Use $element.val() instead.'
  3656. );
  3657. }
  3658. if (args.length === 0) {
  3659. return this.$element.val();
  3660. }
  3661. var newVal = args[0];
  3662. if ($.isArray(newVal)) {
  3663. newVal = $.map(newVal, function (obj) {
  3664. return obj.toString();
  3665. });
  3666. }
  3667. this.$element.val(newVal).trigger('change');
  3668. };
  3669. Select2.prototype.destroy = function () {
  3670. this.$container.remove();
  3671. if (this.$element[0].detachEvent) {
  3672. this.$element[0].detachEvent('onpropertychange', this._sync);
  3673. }
  3674. if (this._observer != null) {
  3675. this._observer.disconnect();
  3676. this._observer = null;
  3677. } else if (this.$element[0].removeEventListener) {
  3678. this.$element[0]
  3679. .removeEventListener('DOMAttrModified', this._sync, false);
  3680. }
  3681. this._sync = null;
  3682. this.$element.off('.select2');
  3683. this.$element.attr('tabindex', this.$element.data('old-tabindex'));
  3684. this.$element.show();
  3685. this.$element.removeData('select2');
  3686. this.data.destroy();
  3687. this.selection.destroy();
  3688. this.dropdown.destroy();
  3689. this.results.destroy();
  3690. this.data = null;
  3691. this.selection = null;
  3692. this.dropdown = null;
  3693. this.results = null;
  3694. };
  3695. Select2.prototype.render = function () {
  3696. var $container = $(
  3697. '<span class="select2 select2-container">' +
  3698. '<span class="selection"></span>' +
  3699. '<span class="dropdown-wrapper" aria-hidden="true"></span>' +
  3700. '</span>'
  3701. );
  3702. $container.attr('dir', this.options.get('dir'));
  3703. this.$container = $container;
  3704. this.$container.addClass('select2-container--' + this.options.get('theme'));
  3705. $container.data('element', this.$element);
  3706. return $container;
  3707. };
  3708. return Select2;
  3709. });
  3710. /*!
  3711. * jQuery Mousewheel 3.1.12
  3712. *
  3713. * Copyright 2014 jQuery Foundation and other contributors
  3714. * Released under the MIT license.
  3715. * http://jquery.org/license
  3716. */
  3717. (function (factory) {
  3718. if ( typeof define === 'function' && define.amd ) {
  3719. // AMD. Register as an anonymous module.
  3720. define('jquery.mousewheel',['jquery'], factory);
  3721. } else if (typeof exports === 'object') {
  3722. // Node/CommonJS style for Browserify
  3723. module.exports = factory;
  3724. } else {
  3725. // Browser globals
  3726. factory(jQuery);
  3727. }
  3728. }(function ($) {
  3729. var toFix = ['wheel', 'mousewheel', 'DOMMouseScroll', 'MozMousePixelScroll'],
  3730. toBind = ( 'onwheel' in document || document.documentMode >= 9 ) ?
  3731. ['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'],
  3732. slice = Array.prototype.slice,
  3733. nullLowestDeltaTimeout, lowestDelta;
  3734. if ( $.event.fixHooks ) {
  3735. for ( var i = toFix.length; i; ) {
  3736. $.event.fixHooks[ toFix[--i] ] = $.event.mouseHooks;
  3737. }
  3738. }
  3739. var special = $.event.special.mousewheel = {
  3740. version: '3.1.12',
  3741. setup: function() {
  3742. if ( this.addEventListener ) {
  3743. for ( var i = toBind.length; i; ) {
  3744. this.addEventListener( toBind[--i], handler, false );
  3745. }
  3746. } else {
  3747. this.onmousewheel = handler;
  3748. }
  3749. // Store the line height and page height for this particular element
  3750. $.data(this, 'mousewheel-line-height', special.getLineHeight(this));
  3751. $.data(this, 'mousewheel-page-height', special.getPageHeight(this));
  3752. },
  3753. teardown: function() {
  3754. if ( this.removeEventListener ) {
  3755. for ( var i = toBind.length; i; ) {
  3756. this.removeEventListener( toBind[--i], handler, false );
  3757. }
  3758. } else {
  3759. this.onmousewheel = null;
  3760. }
  3761. // Clean up the data we added to the element
  3762. $.removeData(this, 'mousewheel-line-height');
  3763. $.removeData(this, 'mousewheel-page-height');
  3764. },
  3765. getLineHeight: function(elem) {
  3766. var $elem = $(elem),
  3767. $parent = $elem['offsetParent' in $.fn ? 'offsetParent' : 'parent']();
  3768. if (!$parent.length) {
  3769. $parent = $('body');
  3770. }
  3771. return parseInt($parent.css('fontSize'), 10) || parseInt($elem.css('fontSize'), 10) || 16;
  3772. },
  3773. getPageHeight: function(elem) {
  3774. return $(elem).height();
  3775. },
  3776. settings: {
  3777. adjustOldDeltas: true, // see shouldAdjustOldDeltas() below
  3778. normalizeOffset: true // calls getBoundingClientRect for each event
  3779. }
  3780. };
  3781. $.fn.extend({
  3782. mousewheel: function(fn) {
  3783. return fn ? this.bind('mousewheel', fn) : this.trigger('mousewheel');
  3784. },
  3785. unmousewheel: function(fn) {
  3786. return this.unbind('mousewheel', fn);
  3787. }
  3788. });
  3789. function handler(event) {
  3790. var orgEvent = event || window.event,
  3791. args = slice.call(arguments, 1),
  3792. delta = 0,
  3793. deltaX = 0,
  3794. deltaY = 0,
  3795. absDelta = 0,
  3796. offsetX = 0,
  3797. offsetY = 0;
  3798. event = $.event.fix(orgEvent);
  3799. event.type = 'mousewheel';
  3800. // Old school scrollwheel delta
  3801. if ( 'detail' in orgEvent ) { deltaY = orgEvent.detail * -1; }
  3802. if ( 'wheelDelta' in orgEvent ) { deltaY = orgEvent.wheelDelta; }
  3803. if ( 'wheelDeltaY' in orgEvent ) { deltaY = orgEvent.wheelDeltaY; }
  3804. if ( 'wheelDeltaX' in orgEvent ) { deltaX = orgEvent.wheelDeltaX * -1; }
  3805. // Firefox < 17 horizontal scrolling related to DOMMouseScroll event
  3806. if ( 'axis' in orgEvent && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) {
  3807. deltaX = deltaY * -1;
  3808. deltaY = 0;
  3809. }
  3810. // Set delta to be deltaY or deltaX if deltaY is 0 for backwards compatabilitiy
  3811. delta = deltaY === 0 ? deltaX : deltaY;
  3812. // New school wheel delta (wheel event)
  3813. if ( 'deltaY' in orgEvent ) {
  3814. deltaY = orgEvent.deltaY * -1;
  3815. delta = deltaY;
  3816. }
  3817. if ( 'deltaX' in orgEvent ) {
  3818. deltaX = orgEvent.deltaX;
  3819. if ( deltaY === 0 ) { delta = deltaX * -1; }
  3820. }
  3821. // No change actually happened, no reason to go any further
  3822. if ( deltaY === 0 && deltaX === 0 ) { return; }
  3823. // Need to convert lines and pages to pixels if we aren't already in pixels
  3824. // There are three delta modes:
  3825. // * deltaMode 0 is by pixels, nothing to do
  3826. // * deltaMode 1 is by lines
  3827. // * deltaMode 2 is by pages
  3828. if ( orgEvent.deltaMode === 1 ) {
  3829. var lineHeight = $.data(this, 'mousewheel-line-height');
  3830. delta *= lineHeight;
  3831. deltaY *= lineHeight;
  3832. deltaX *= lineHeight;
  3833. } else if ( orgEvent.deltaMode === 2 ) {
  3834. var pageHeight = $.data(this, 'mousewheel-page-height');
  3835. delta *= pageHeight;
  3836. deltaY *= pageHeight;
  3837. deltaX *= pageHeight;
  3838. }
  3839. // Store lowest absolute delta to normalize the delta values
  3840. absDelta = Math.max( Math.abs(deltaY), Math.abs(deltaX) );
  3841. if ( !lowestDelta || absDelta < lowestDelta ) {
  3842. lowestDelta = absDelta;
  3843. // Adjust older deltas if necessary
  3844. if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) {
  3845. lowestDelta /= 40;
  3846. }
  3847. }
  3848. // Adjust older deltas if necessary
  3849. if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) {
  3850. // Divide all the things by 40!
  3851. delta /= 40;
  3852. deltaX /= 40;
  3853. deltaY /= 40;
  3854. }
  3855. // Get a whole, normalized value for the deltas
  3856. delta = Math[ delta >= 1 ? 'floor' : 'ceil' ](delta / lowestDelta);
  3857. deltaX = Math[ deltaX >= 1 ? 'floor' : 'ceil' ](deltaX / lowestDelta);
  3858. deltaY = Math[ deltaY >= 1 ? 'floor' : 'ceil' ](deltaY / lowestDelta);
  3859. // Normalise offsetX and offsetY properties
  3860. if ( special.settings.normalizeOffset && this.getBoundingClientRect ) {
  3861. var boundingRect = this.getBoundingClientRect();
  3862. offsetX = event.clientX - boundingRect.left;
  3863. offsetY = event.clientY - boundingRect.top;
  3864. }
  3865. // Add information to the event object
  3866. event.deltaX = deltaX;
  3867. event.deltaY = deltaY;
  3868. event.deltaFactor = lowestDelta;
  3869. event.offsetX = offsetX;
  3870. event.offsetY = offsetY;
  3871. // Go ahead and set deltaMode to 0 since we converted to pixels
  3872. // Although this is a little odd since we overwrite the deltaX/Y
  3873. // properties with normalized deltas.
  3874. event.deltaMode = 0;
  3875. // Add event and delta to the front of the arguments
  3876. args.unshift(event, delta, deltaX, deltaY);
  3877. // Clearout lowestDelta after sometime to better
  3878. // handle multiple device types that give different
  3879. // a different lowestDelta
  3880. // Ex: trackpad = 3 and mouse wheel = 120
  3881. if (nullLowestDeltaTimeout) { clearTimeout(nullLowestDeltaTimeout); }
  3882. nullLowestDeltaTimeout = setTimeout(nullLowestDelta, 200);
  3883. return ($.event.dispatch || $.event.handle).apply(this, args);
  3884. }
  3885. function nullLowestDelta() {
  3886. lowestDelta = null;
  3887. }
  3888. function shouldAdjustOldDeltas(orgEvent, absDelta) {
  3889. // If this is an older event and the delta is divisable by 120,
  3890. // then we are assuming that the browser is treating this as an
  3891. // older mouse wheel event and that we should divide the deltas
  3892. // by 40 to try and get a more usable deltaFactor.
  3893. // Side note, this actually impacts the reported scroll distance
  3894. // in older browsers and can cause scrolling to be slower than native.
  3895. // Turn this off by setting $.event.special.mousewheel.settings.adjustOldDeltas to false.
  3896. return special.settings.adjustOldDeltas && orgEvent.type === 'mousewheel' && absDelta % 120 === 0;
  3897. }
  3898. }));
  3899. define('select2/compat/matcher',[
  3900. 'jquery'
  3901. ], function ($) {
  3902. function oldMatcher (matcher) {
  3903. function wrappedMatcher (params, data) {
  3904. var match = $.extend(true, {}, data);
  3905. if (params.term == null || $.trim(params.term) === '') {
  3906. return match;
  3907. }
  3908. if (data.children) {
  3909. for (var c = data.children.length - 1; c >= 0; c--) {
  3910. var child = data.children[c];
  3911. // Check if the child object matches
  3912. // The old matcher returned a boolean true or false
  3913. var doesMatch = matcher(params.term, child.text, child);
  3914. // If the child didn't match, pop it off
  3915. if (!doesMatch) {
  3916. match.children.splice(c, 1);
  3917. }
  3918. }
  3919. if (match.children.length > 0) {
  3920. return match;
  3921. }
  3922. }
  3923. if (matcher(params.term, data.text, data)) {
  3924. return match;
  3925. }
  3926. return null;
  3927. }
  3928. return wrappedMatcher;
  3929. }
  3930. return oldMatcher;
  3931. });
  3932. define('select2/compat/initSelection',[
  3933. 'jquery'
  3934. ], function ($) {
  3935. function InitSelection (decorated, $element, options) {
  3936. if (window.console && console.warn) {
  3937. console.warn(
  3938. 'Select2: The `initSelection` option has been deprecated in favor' +
  3939. ' of a custom data adapter that overrides the `current` method. ' +
  3940. 'This method is now called multiple times instead of a single ' +
  3941. 'time when the instance is initialized. Support will be removed ' +
  3942. 'for the `initSelection` option in future versions of Select2'
  3943. );
  3944. }
  3945. this.initSelection = options.get('initSelection');
  3946. this._isInitialized = false;
  3947. decorated.call(this, $element, options);
  3948. }
  3949. InitSelection.prototype.current = function (decorated, callback) {
  3950. var self = this;
  3951. if (this._isInitialized) {
  3952. decorated.call(this, callback);
  3953. return;
  3954. }
  3955. this.initSelection.call(null, this.$element, function (data) {
  3956. self._isInitialized = true;
  3957. if (!$.isArray(data)) {
  3958. data = [data];
  3959. }
  3960. callback(data);
  3961. });
  3962. };
  3963. return InitSelection;
  3964. });
  3965. define('select2/compat/query',[
  3966. ], function () {
  3967. function Query (decorated, $element, options) {
  3968. if (window.console && console.warn) {
  3969. console.warn(
  3970. 'Select2: The `query` option has been deprecated in favor of a ' +
  3971. 'custom data adapter that overrides the `query` method. Support ' +
  3972. 'will be removed for the `query` option in future versions of ' +
  3973. 'Select2.'
  3974. );
  3975. }
  3976. decorated.call(this, $element, options);
  3977. }
  3978. Query.prototype.query = function (_, params, callback) {
  3979. params.callback = callback;
  3980. var query = this.options.get('query');
  3981. query.call(null, params);
  3982. };
  3983. return Query;
  3984. });
  3985. define('select2/dropdown/attachContainer',[
  3986. ], function () {
  3987. function AttachContainer (decorated, $element, options) {
  3988. decorated.call(this, $element, options);
  3989. }
  3990. AttachContainer.prototype.position =
  3991. function (decorated, $dropdown, $container) {
  3992. var $dropdownContainer = $container.find('.dropdown-wrapper');
  3993. $dropdownContainer.append($dropdown);
  3994. $dropdown.addClass('select2-dropdown--below');
  3995. $container.addClass('select2-container--below');
  3996. };
  3997. return AttachContainer;
  3998. });
  3999. define('select2/dropdown/stopPropagation',[
  4000. ], function () {
  4001. function StopPropagation () { }
  4002. StopPropagation.prototype.bind = function (decorated, container, $container) {
  4003. decorated.call(this, container, $container);
  4004. var stoppedEvents = [
  4005. 'blur',
  4006. 'change',
  4007. 'click',
  4008. 'dblclick',
  4009. 'focus',
  4010. 'focusin',
  4011. 'focusout',
  4012. 'input',
  4013. 'keydown',
  4014. 'keyup',
  4015. 'keypress',
  4016. 'mousedown',
  4017. 'mouseenter',
  4018. 'mouseleave',
  4019. 'mousemove',
  4020. 'mouseover',
  4021. 'mouseup',
  4022. 'search',
  4023. 'touchend',
  4024. 'touchstart'
  4025. ];
  4026. this.$dropdown.on(stoppedEvents.join(' '), function (evt) {
  4027. evt.stopPropagation();
  4028. });
  4029. };
  4030. return StopPropagation;
  4031. });
  4032. define('select2/selection/stopPropagation',[
  4033. ], function () {
  4034. function StopPropagation () { }
  4035. StopPropagation.prototype.bind = function (decorated, container, $container) {
  4036. decorated.call(this, container, $container);
  4037. var stoppedEvents = [
  4038. 'blur',
  4039. 'change',
  4040. 'click',
  4041. 'dblclick',
  4042. 'focus',
  4043. 'focusin',
  4044. 'focusout',
  4045. 'input',
  4046. 'keydown',
  4047. 'keyup',
  4048. 'keypress',
  4049. 'mousedown',
  4050. 'mouseenter',
  4051. 'mouseleave',
  4052. 'mousemove',
  4053. 'mouseover',
  4054. 'mouseup',
  4055. 'search',
  4056. 'touchend',
  4057. 'touchstart'
  4058. ];
  4059. this.$selection.on(stoppedEvents.join(' '), function (evt) {
  4060. evt.stopPropagation();
  4061. });
  4062. };
  4063. return StopPropagation;
  4064. });
  4065. define('jquery.select2',[
  4066. 'jquery',
  4067. './select2/core',
  4068. './select2/defaults'
  4069. ], function ($, Select2, Defaults) {
  4070. // Force jQuery.mousewheel to be loaded if it hasn't already
  4071. try {
  4072. require('jquery.mousewheel');
  4073. } catch (Exception) { }
  4074. if ($.fn.select2 == null) {
  4075. $.fn.select2 = function (options) {
  4076. options = options || {};
  4077. if (typeof options === 'object') {
  4078. this.each(function () {
  4079. var instanceOptions = $.extend({}, options, true);
  4080. var instance = new Select2($(this), instanceOptions);
  4081. });
  4082. return this;
  4083. } else if (typeof options === 'string') {
  4084. var instance = this.data('select2');
  4085. var args = Array.prototype.slice.call(arguments, 1);
  4086. return instance[options](args);
  4087. } else {
  4088. throw new Error('Invalid arguments for Select2: ' + options);
  4089. }
  4090. };
  4091. }
  4092. if ($.fn.select2.defaults == null) {
  4093. $.fn.select2.defaults = Defaults;
  4094. }
  4095. return Select2;
  4096. });
  4097. return require('jquery.select2'); });