select2.amd.full.js 114 KB

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