select2.js 126 KB

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