select2.amd.js 102 KB

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