select2.full.js 149 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114
  1. /*!
  2. * Select2 4.0.0
  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. // Append an array of jQuery nodes to a given element.
  600. Utils.appendMany = function ($element, $nodes) {
  601. // jQuery 1.7.x does not support $.fn.append() with an array
  602. // Fall back to a jQuery object collection using $.fn.add()
  603. if ($.fn.jquery.substr(0, 3) === '1.7') {
  604. var $jqNodes = $();
  605. $.map($nodes, function (node) {
  606. $jqNodes = $jqNodes.add(node);
  607. });
  608. $nodes = $jqNodes;
  609. }
  610. $element.append($nodes);
  611. };
  612. return Utils;
  613. });
  614. S2.define('select2/results',[
  615. 'jquery',
  616. './utils'
  617. ], function ($, Utils) {
  618. function Results ($element, options, dataAdapter) {
  619. this.$element = $element;
  620. this.data = dataAdapter;
  621. this.options = options;
  622. Results.__super__.constructor.call(this);
  623. }
  624. Utils.Extend(Results, Utils.Observable);
  625. Results.prototype.render = function () {
  626. var $results = $(
  627. '<ul class="select2-results__options" role="tree"></ul>'
  628. );
  629. if (this.options.get('multiple')) {
  630. $results.attr('aria-multiselectable', 'true');
  631. }
  632. this.$results = $results;
  633. return $results;
  634. };
  635. Results.prototype.clear = function () {
  636. this.$results.empty();
  637. };
  638. Results.prototype.displayMessage = function (params) {
  639. var escapeMarkup = this.options.get('escapeMarkup');
  640. this.clear();
  641. this.hideLoading();
  642. var $message = $(
  643. '<li role="treeitem" class="select2-results__option"></li>'
  644. );
  645. var message = this.options.get('translations').get(params.message);
  646. $message.append(
  647. escapeMarkup(
  648. message(params.args)
  649. )
  650. );
  651. this.$results.append($message);
  652. };
  653. Results.prototype.append = function (data) {
  654. this.hideLoading();
  655. var $options = [];
  656. if (data.results == null || data.results.length === 0) {
  657. if (this.$results.children().length === 0) {
  658. this.trigger('results:message', {
  659. message: 'noResults'
  660. });
  661. }
  662. return;
  663. }
  664. data.results = this.sort(data.results);
  665. for (var d = 0; d < data.results.length; d++) {
  666. var item = data.results[d];
  667. var $option = this.option(item);
  668. $options.push($option);
  669. }
  670. this.$results.append($options);
  671. };
  672. Results.prototype.position = function ($results, $dropdown) {
  673. var $resultsContainer = $dropdown.find('.select2-results');
  674. $resultsContainer.append($results);
  675. };
  676. Results.prototype.sort = function (data) {
  677. var sorter = this.options.get('sorter');
  678. return sorter(data);
  679. };
  680. Results.prototype.setClasses = function () {
  681. var self = this;
  682. this.data.current(function (selected) {
  683. var selectedIds = $.map(selected, function (s) {
  684. return s.id.toString();
  685. });
  686. var $options = self.$results
  687. .find('.select2-results__option[aria-selected]');
  688. $options.each(function () {
  689. var $option = $(this);
  690. var item = $.data(this, 'data');
  691. // id needs to be converted to a string when comparing
  692. var id = '' + item.id;
  693. if ((item.element != null && item.element.selected) ||
  694. (item.element == null && $.inArray(id, selectedIds) > -1)) {
  695. $option.attr('aria-selected', 'true');
  696. } else {
  697. $option.attr('aria-selected', 'false');
  698. }
  699. });
  700. var $selected = $options.filter('[aria-selected=true]');
  701. // Check if there are any selected options
  702. if ($selected.length > 0) {
  703. // If there are selected options, highlight the first
  704. $selected.first().trigger('mouseenter');
  705. } else {
  706. // If there are no selected options, highlight the first option
  707. // in the dropdown
  708. $options.first().trigger('mouseenter');
  709. }
  710. });
  711. };
  712. Results.prototype.showLoading = function (params) {
  713. this.hideLoading();
  714. var loadingMore = this.options.get('translations').get('searching');
  715. var loading = {
  716. disabled: true,
  717. loading: true,
  718. text: loadingMore(params)
  719. };
  720. var $loading = this.option(loading);
  721. $loading.className += ' loading-results';
  722. this.$results.prepend($loading);
  723. };
  724. Results.prototype.hideLoading = function () {
  725. this.$results.find('.loading-results').remove();
  726. };
  727. Results.prototype.option = function (data) {
  728. var option = document.createElement('li');
  729. option.className = 'select2-results__option';
  730. var attrs = {
  731. 'role': 'treeitem',
  732. 'aria-selected': 'false'
  733. };
  734. if (data.disabled) {
  735. delete attrs['aria-selected'];
  736. attrs['aria-disabled'] = 'true';
  737. }
  738. if (data.id == null) {
  739. delete attrs['aria-selected'];
  740. }
  741. if (data._resultId != null) {
  742. option.id = data._resultId;
  743. }
  744. if (data.title) {
  745. option.title = data.title;
  746. }
  747. if (data.children) {
  748. attrs.role = 'group';
  749. attrs['aria-label'] = data.text;
  750. delete attrs['aria-selected'];
  751. }
  752. for (var attr in attrs) {
  753. var val = attrs[attr];
  754. option.setAttribute(attr, val);
  755. }
  756. if (data.children) {
  757. var $option = $(option);
  758. var label = document.createElement('strong');
  759. label.className = 'select2-results__group';
  760. var $label = $(label);
  761. this.template(data, label);
  762. var $children = [];
  763. for (var c = 0; c < data.children.length; c++) {
  764. var child = data.children[c];
  765. var $child = this.option(child);
  766. $children.push($child);
  767. }
  768. var $childrenContainer = $('<ul></ul>', {
  769. 'class': 'select2-results__options select2-results__options--nested'
  770. });
  771. $childrenContainer.append($children);
  772. $option.append(label);
  773. $option.append($childrenContainer);
  774. } else {
  775. this.template(data, option);
  776. }
  777. $.data(option, 'data', data);
  778. return option;
  779. };
  780. Results.prototype.bind = function (container, $container) {
  781. var self = this;
  782. var id = container.id + '-results';
  783. this.$results.attr('id', id);
  784. container.on('results:all', function (params) {
  785. self.clear();
  786. self.append(params.data);
  787. if (container.isOpen()) {
  788. self.setClasses();
  789. }
  790. });
  791. container.on('results:append', function (params) {
  792. self.append(params.data);
  793. if (container.isOpen()) {
  794. self.setClasses();
  795. }
  796. });
  797. container.on('query', function (params) {
  798. self.showLoading(params);
  799. });
  800. container.on('select', function () {
  801. if (!container.isOpen()) {
  802. return;
  803. }
  804. self.setClasses();
  805. });
  806. container.on('unselect', function () {
  807. if (!container.isOpen()) {
  808. return;
  809. }
  810. self.setClasses();
  811. });
  812. container.on('open', function () {
  813. // When the dropdown is open, aria-expended="true"
  814. self.$results.attr('aria-expanded', 'true');
  815. self.$results.attr('aria-hidden', 'false');
  816. self.setClasses();
  817. self.ensureHighlightVisible();
  818. });
  819. container.on('close', function () {
  820. // When the dropdown is closed, aria-expended="false"
  821. self.$results.attr('aria-expanded', 'false');
  822. self.$results.attr('aria-hidden', 'true');
  823. self.$results.removeAttr('aria-activedescendant');
  824. });
  825. container.on('results:toggle', function () {
  826. var $highlighted = self.getHighlightedResults();
  827. if ($highlighted.length === 0) {
  828. return;
  829. }
  830. $highlighted.trigger('mouseup');
  831. });
  832. container.on('results:select', function () {
  833. var $highlighted = self.getHighlightedResults();
  834. if ($highlighted.length === 0) {
  835. return;
  836. }
  837. var data = $highlighted.data('data');
  838. if ($highlighted.attr('aria-selected') == 'true') {
  839. self.trigger('close');
  840. } else {
  841. self.trigger('select', {
  842. data: data
  843. });
  844. }
  845. });
  846. container.on('results:previous', function () {
  847. var $highlighted = self.getHighlightedResults();
  848. var $options = self.$results.find('[aria-selected]');
  849. var currentIndex = $options.index($highlighted);
  850. // If we are already at te top, don't move further
  851. if (currentIndex === 0) {
  852. return;
  853. }
  854. var nextIndex = currentIndex - 1;
  855. // If none are highlighted, highlight the first
  856. if ($highlighted.length === 0) {
  857. nextIndex = 0;
  858. }
  859. var $next = $options.eq(nextIndex);
  860. $next.trigger('mouseenter');
  861. var currentOffset = self.$results.offset().top;
  862. var nextTop = $next.offset().top;
  863. var nextOffset = self.$results.scrollTop() + (nextTop - currentOffset);
  864. if (nextIndex === 0) {
  865. self.$results.scrollTop(0);
  866. } else if (nextTop - currentOffset < 0) {
  867. self.$results.scrollTop(nextOffset);
  868. }
  869. });
  870. container.on('results:next', function () {
  871. var $highlighted = self.getHighlightedResults();
  872. var $options = self.$results.find('[aria-selected]');
  873. var currentIndex = $options.index($highlighted);
  874. var nextIndex = currentIndex + 1;
  875. // If we are at the last option, stay there
  876. if (nextIndex >= $options.length) {
  877. return;
  878. }
  879. var $next = $options.eq(nextIndex);
  880. $next.trigger('mouseenter');
  881. var currentOffset = self.$results.offset().top +
  882. self.$results.outerHeight(false);
  883. var nextBottom = $next.offset().top + $next.outerHeight(false);
  884. var nextOffset = self.$results.scrollTop() + nextBottom - currentOffset;
  885. if (nextIndex === 0) {
  886. self.$results.scrollTop(0);
  887. } else if (nextBottom > currentOffset) {
  888. self.$results.scrollTop(nextOffset);
  889. }
  890. });
  891. container.on('results:focus', function (params) {
  892. params.element.addClass('select2-results__option--highlighted');
  893. });
  894. container.on('results:message', function (params) {
  895. self.displayMessage(params);
  896. });
  897. if ($.fn.mousewheel) {
  898. this.$results.on('mousewheel', function (e) {
  899. var top = self.$results.scrollTop();
  900. var bottom = (
  901. self.$results.get(0).scrollHeight -
  902. self.$results.scrollTop() +
  903. e.deltaY
  904. );
  905. var isAtTop = e.deltaY > 0 && top - e.deltaY <= 0;
  906. var isAtBottom = e.deltaY < 0 && bottom <= self.$results.height();
  907. if (isAtTop) {
  908. self.$results.scrollTop(0);
  909. e.preventDefault();
  910. e.stopPropagation();
  911. } else if (isAtBottom) {
  912. self.$results.scrollTop(
  913. self.$results.get(0).scrollHeight - self.$results.height()
  914. );
  915. e.preventDefault();
  916. e.stopPropagation();
  917. }
  918. });
  919. }
  920. this.$results.on('mouseup', '.select2-results__option[aria-selected]',
  921. function (evt) {
  922. var $this = $(this);
  923. var data = $this.data('data');
  924. if ($this.attr('aria-selected') === 'true') {
  925. if (self.options.get('multiple')) {
  926. self.trigger('unselect', {
  927. originalEvent: evt,
  928. data: data
  929. });
  930. } else {
  931. self.trigger('close');
  932. }
  933. return;
  934. }
  935. self.trigger('select', {
  936. originalEvent: evt,
  937. data: data
  938. });
  939. });
  940. this.$results.on('mouseenter', '.select2-results__option[aria-selected]',
  941. function (evt) {
  942. var data = $(this).data('data');
  943. self.getHighlightedResults()
  944. .removeClass('select2-results__option--highlighted');
  945. self.trigger('results:focus', {
  946. data: data,
  947. element: $(this)
  948. });
  949. });
  950. };
  951. Results.prototype.getHighlightedResults = function () {
  952. var $highlighted = this.$results
  953. .find('.select2-results__option--highlighted');
  954. return $highlighted;
  955. };
  956. Results.prototype.destroy = function () {
  957. this.$results.remove();
  958. };
  959. Results.prototype.ensureHighlightVisible = function () {
  960. var $highlighted = this.getHighlightedResults();
  961. if ($highlighted.length === 0) {
  962. return;
  963. }
  964. var $options = this.$results.find('[aria-selected]');
  965. var currentIndex = $options.index($highlighted);
  966. var currentOffset = this.$results.offset().top;
  967. var nextTop = $highlighted.offset().top;
  968. var nextOffset = this.$results.scrollTop() + (nextTop - currentOffset);
  969. var offsetDelta = nextTop - currentOffset;
  970. nextOffset -= $highlighted.outerHeight(false) * 2;
  971. if (currentIndex <= 2) {
  972. this.$results.scrollTop(0);
  973. } else if (offsetDelta > this.$results.outerHeight() || offsetDelta < 0) {
  974. this.$results.scrollTop(nextOffset);
  975. }
  976. };
  977. Results.prototype.template = function (result, container) {
  978. var template = this.options.get('templateResult');
  979. var escapeMarkup = this.options.get('escapeMarkup');
  980. var content = template(result);
  981. if (content == null) {
  982. container.style.display = 'none';
  983. } else if (typeof content === 'string') {
  984. container.innerHTML = escapeMarkup(content);
  985. } else {
  986. $(container).append(content);
  987. }
  988. };
  989. return Results;
  990. });
  991. S2.define('select2/keys',[
  992. ], function () {
  993. var KEYS = {
  994. BACKSPACE: 8,
  995. TAB: 9,
  996. ENTER: 13,
  997. SHIFT: 16,
  998. CTRL: 17,
  999. ALT: 18,
  1000. ESC: 27,
  1001. SPACE: 32,
  1002. PAGE_UP: 33,
  1003. PAGE_DOWN: 34,
  1004. END: 35,
  1005. HOME: 36,
  1006. LEFT: 37,
  1007. UP: 38,
  1008. RIGHT: 39,
  1009. DOWN: 40,
  1010. DELETE: 46
  1011. };
  1012. return KEYS;
  1013. });
  1014. S2.define('select2/selection/base',[
  1015. 'jquery',
  1016. '../utils',
  1017. '../keys'
  1018. ], function ($, Utils, KEYS) {
  1019. function BaseSelection ($element, options) {
  1020. this.$element = $element;
  1021. this.options = options;
  1022. BaseSelection.__super__.constructor.call(this);
  1023. }
  1024. Utils.Extend(BaseSelection, Utils.Observable);
  1025. BaseSelection.prototype.render = function () {
  1026. var $selection = $(
  1027. '<span class="select2-selection" role="combobox" ' +
  1028. 'aria-autocomplete="list" aria-haspopup="true" aria-expanded="false">' +
  1029. '</span>'
  1030. );
  1031. this._tabindex = 0;
  1032. if (this.$element.data('old-tabindex') != null) {
  1033. this._tabindex = this.$element.data('old-tabindex');
  1034. } else if (this.$element.attr('tabindex') != null) {
  1035. this._tabindex = this.$element.attr('tabindex');
  1036. }
  1037. $selection.attr('title', this.$element.attr('title'));
  1038. $selection.attr('tabindex', this._tabindex);
  1039. this.$selection = $selection;
  1040. return $selection;
  1041. };
  1042. BaseSelection.prototype.bind = function (container, $container) {
  1043. var self = this;
  1044. var id = container.id + '-container';
  1045. var resultsId = container.id + '-results';
  1046. this.container = container;
  1047. this.$selection.on('focus', function (evt) {
  1048. self.trigger('focus', evt);
  1049. });
  1050. this.$selection.on('blur', function (evt) {
  1051. self.trigger('blur', evt);
  1052. });
  1053. this.$selection.on('keydown', function (evt) {
  1054. self.trigger('keypress', evt);
  1055. if (evt.which === KEYS.SPACE) {
  1056. evt.preventDefault();
  1057. }
  1058. });
  1059. container.on('results:focus', function (params) {
  1060. self.$selection.attr('aria-activedescendant', params.data._resultId);
  1061. });
  1062. container.on('selection:update', function (params) {
  1063. self.update(params.data);
  1064. });
  1065. container.on('open', function () {
  1066. // When the dropdown is open, aria-expanded="true"
  1067. self.$selection.attr('aria-expanded', 'true');
  1068. self.$selection.attr('aria-owns', resultsId);
  1069. self._attachCloseHandler(container);
  1070. });
  1071. container.on('close', function () {
  1072. // When the dropdown is closed, aria-expanded="false"
  1073. self.$selection.attr('aria-expanded', 'false');
  1074. self.$selection.removeAttr('aria-activedescendant');
  1075. self.$selection.removeAttr('aria-owns');
  1076. self.$selection.focus();
  1077. self._detachCloseHandler(container);
  1078. });
  1079. container.on('enable', function () {
  1080. self.$selection.attr('tabindex', self._tabindex);
  1081. });
  1082. container.on('disable', function () {
  1083. self.$selection.attr('tabindex', '-1');
  1084. });
  1085. };
  1086. BaseSelection.prototype._attachCloseHandler = function (container) {
  1087. var self = this;
  1088. $(document.body).on('mousedown.select2.' + container.id, function (e) {
  1089. var $target = $(e.target);
  1090. var $select = $target.closest('.select2');
  1091. var $all = $('.select2.select2-container--open');
  1092. $all.each(function () {
  1093. var $this = $(this);
  1094. if (this == $select[0]) {
  1095. return;
  1096. }
  1097. var $element = $this.data('element');
  1098. $element.select2('close');
  1099. });
  1100. });
  1101. };
  1102. BaseSelection.prototype._detachCloseHandler = function (container) {
  1103. $(document.body).off('mousedown.select2.' + container.id);
  1104. };
  1105. BaseSelection.prototype.position = function ($selection, $container) {
  1106. var $selectionContainer = $container.find('.selection');
  1107. $selectionContainer.append($selection);
  1108. };
  1109. BaseSelection.prototype.destroy = function () {
  1110. this._detachCloseHandler(this.container);
  1111. };
  1112. BaseSelection.prototype.update = function (data) {
  1113. throw new Error('The `update` method must be defined in child classes.');
  1114. };
  1115. return BaseSelection;
  1116. });
  1117. S2.define('select2/selection/single',[
  1118. 'jquery',
  1119. './base',
  1120. '../utils',
  1121. '../keys'
  1122. ], function ($, BaseSelection, Utils, KEYS) {
  1123. function SingleSelection () {
  1124. SingleSelection.__super__.constructor.apply(this, arguments);
  1125. }
  1126. Utils.Extend(SingleSelection, BaseSelection);
  1127. SingleSelection.prototype.render = function () {
  1128. var $selection = SingleSelection.__super__.render.call(this);
  1129. $selection.addClass('select2-selection--single');
  1130. $selection.html(
  1131. '<span class="select2-selection__rendered"></span>' +
  1132. '<span class="select2-selection__arrow" role="presentation">' +
  1133. '<b role="presentation"></b>' +
  1134. '</span>'
  1135. );
  1136. return $selection;
  1137. };
  1138. SingleSelection.prototype.bind = function (container, $container) {
  1139. var self = this;
  1140. SingleSelection.__super__.bind.apply(this, arguments);
  1141. var id = container.id + '-container';
  1142. this.$selection.find('.select2-selection__rendered').attr('id', id);
  1143. this.$selection.attr('aria-labelledby', id);
  1144. this.$selection.on('mousedown', function (evt) {
  1145. // Only respond to left clicks
  1146. if (evt.which !== 1) {
  1147. return;
  1148. }
  1149. self.trigger('toggle', {
  1150. originalEvent: evt
  1151. });
  1152. });
  1153. this.$selection.on('focus', function (evt) {
  1154. // User focuses on the container
  1155. });
  1156. this.$selection.on('blur', function (evt) {
  1157. // User exits the container
  1158. });
  1159. container.on('selection:update', function (params) {
  1160. self.update(params.data);
  1161. });
  1162. };
  1163. SingleSelection.prototype.clear = function () {
  1164. this.$selection.find('.select2-selection__rendered').empty();
  1165. };
  1166. SingleSelection.prototype.display = function (data) {
  1167. var template = this.options.get('templateSelection');
  1168. var escapeMarkup = this.options.get('escapeMarkup');
  1169. return escapeMarkup(template(data));
  1170. };
  1171. SingleSelection.prototype.selectionContainer = function () {
  1172. return $('<span></span>');
  1173. };
  1174. SingleSelection.prototype.update = function (data) {
  1175. if (data.length === 0) {
  1176. this.clear();
  1177. return;
  1178. }
  1179. var selection = data[0];
  1180. var formatted = this.display(selection);
  1181. var $rendered = this.$selection.find('.select2-selection__rendered');
  1182. $rendered.empty().append(formatted);
  1183. $rendered.prop('title', selection.title || selection.text);
  1184. };
  1185. return SingleSelection;
  1186. });
  1187. S2.define('select2/selection/multiple',[
  1188. 'jquery',
  1189. './base',
  1190. '../utils'
  1191. ], function ($, BaseSelection, Utils) {
  1192. function MultipleSelection ($element, options) {
  1193. MultipleSelection.__super__.constructor.apply(this, arguments);
  1194. }
  1195. Utils.Extend(MultipleSelection, BaseSelection);
  1196. MultipleSelection.prototype.render = function () {
  1197. var $selection = MultipleSelection.__super__.render.call(this);
  1198. $selection.addClass('select2-selection--multiple');
  1199. $selection.html(
  1200. '<ul class="select2-selection__rendered"></ul>'
  1201. );
  1202. return $selection;
  1203. };
  1204. MultipleSelection.prototype.bind = function (container, $container) {
  1205. var self = this;
  1206. MultipleSelection.__super__.bind.apply(this, arguments);
  1207. this.$selection.on('click', function (evt) {
  1208. self.trigger('toggle', {
  1209. originalEvent: evt
  1210. });
  1211. });
  1212. this.$selection.on('click', '.select2-selection__choice__remove',
  1213. function (evt) {
  1214. var $remove = $(this);
  1215. var $selection = $remove.parent();
  1216. var data = $selection.data('data');
  1217. self.trigger('unselect', {
  1218. originalEvent: evt,
  1219. data: data
  1220. });
  1221. });
  1222. };
  1223. MultipleSelection.prototype.clear = function () {
  1224. this.$selection.find('.select2-selection__rendered').empty();
  1225. };
  1226. MultipleSelection.prototype.display = function (data) {
  1227. var template = this.options.get('templateSelection');
  1228. var escapeMarkup = this.options.get('escapeMarkup');
  1229. return escapeMarkup(template(data));
  1230. };
  1231. MultipleSelection.prototype.selectionContainer = function () {
  1232. var $container = $(
  1233. '<li class="select2-selection__choice">' +
  1234. '<span class="select2-selection__choice__remove" role="presentation">' +
  1235. '&times;' +
  1236. '</span>' +
  1237. '</li>'
  1238. );
  1239. return $container;
  1240. };
  1241. MultipleSelection.prototype.update = function (data) {
  1242. this.clear();
  1243. if (data.length === 0) {
  1244. return;
  1245. }
  1246. var $selections = [];
  1247. for (var d = 0; d < data.length; d++) {
  1248. var selection = data[d];
  1249. var formatted = this.display(selection);
  1250. var $selection = this.selectionContainer();
  1251. $selection.append(formatted);
  1252. $selection.prop('title', selection.title || selection.text);
  1253. $selection.data('data', selection);
  1254. $selections.push($selection);
  1255. }
  1256. var $rendered = this.$selection.find('.select2-selection__rendered');
  1257. Utils.appendMany($rendered, $selections);
  1258. };
  1259. return MultipleSelection;
  1260. });
  1261. S2.define('select2/selection/placeholder',[
  1262. '../utils'
  1263. ], function (Utils) {
  1264. function Placeholder (decorated, $element, options) {
  1265. this.placeholder = this.normalizePlaceholder(options.get('placeholder'));
  1266. decorated.call(this, $element, options);
  1267. }
  1268. Placeholder.prototype.normalizePlaceholder = function (_, placeholder) {
  1269. if (typeof placeholder === 'string') {
  1270. placeholder = {
  1271. id: '',
  1272. text: placeholder
  1273. };
  1274. }
  1275. return placeholder;
  1276. };
  1277. Placeholder.prototype.createPlaceholder = function (decorated, placeholder) {
  1278. var $placeholder = this.selectionContainer();
  1279. $placeholder.html(this.display(placeholder));
  1280. $placeholder.addClass('select2-selection__placeholder')
  1281. .removeClass('select2-selection__choice');
  1282. return $placeholder;
  1283. };
  1284. Placeholder.prototype.update = function (decorated, data) {
  1285. var singlePlaceholder = (
  1286. data.length == 1 && data[0].id != this.placeholder.id
  1287. );
  1288. var multipleSelections = data.length > 1;
  1289. if (multipleSelections || singlePlaceholder) {
  1290. return decorated.call(this, data);
  1291. }
  1292. this.clear();
  1293. var $placeholder = this.createPlaceholder(this.placeholder);
  1294. this.$selection.find('.select2-selection__rendered').append($placeholder);
  1295. };
  1296. return Placeholder;
  1297. });
  1298. S2.define('select2/selection/allowClear',[
  1299. 'jquery',
  1300. '../keys'
  1301. ], function ($, KEYS) {
  1302. function AllowClear () { }
  1303. AllowClear.prototype.bind = function (decorated, container, $container) {
  1304. var self = this;
  1305. decorated.call(this, container, $container);
  1306. if (this.placeholder == null) {
  1307. if (this.options.get('debug') && window.console && console.error) {
  1308. console.error(
  1309. 'Select2: The `allowClear` option should be used in combination ' +
  1310. 'with the `placeholder` option.'
  1311. );
  1312. }
  1313. }
  1314. this.$selection.on('mousedown', '.select2-selection__clear',
  1315. function (evt) {
  1316. self._handleClear(evt);
  1317. });
  1318. container.on('keypress', function (evt) {
  1319. self._handleKeyboardClear(evt, container);
  1320. });
  1321. };
  1322. AllowClear.prototype._handleClear = function (_, evt) {
  1323. // Ignore the event if it is disabled
  1324. if (this.options.get('disabled')) {
  1325. return;
  1326. }
  1327. var $clear = this.$selection.find('.select2-selection__clear');
  1328. // Ignore the event if nothing has been selected
  1329. if ($clear.length === 0) {
  1330. return;
  1331. }
  1332. evt.stopPropagation();
  1333. var data = $clear.data('data');
  1334. for (var d = 0; d < data.length; d++) {
  1335. var unselectData = {
  1336. data: data[d]
  1337. };
  1338. // Trigger the `unselect` event, so people can prevent it from being
  1339. // cleared.
  1340. this.trigger('unselect', unselectData);
  1341. // If the event was prevented, don't clear it out.
  1342. if (unselectData.prevented) {
  1343. return;
  1344. }
  1345. }
  1346. this.$element.val(this.placeholder.id).trigger('change');
  1347. this.trigger('toggle');
  1348. };
  1349. AllowClear.prototype._handleKeyboardClear = function (_, evt, container) {
  1350. if (container.isOpen()) {
  1351. return;
  1352. }
  1353. if (evt.which == KEYS.DELETE || evt.which == KEYS.BACKSPACE) {
  1354. this._handleClear(evt);
  1355. }
  1356. };
  1357. AllowClear.prototype.update = function (decorated, data) {
  1358. decorated.call(this, data);
  1359. if (this.$selection.find('.select2-selection__placeholder').length > 0 ||
  1360. data.length === 0) {
  1361. return;
  1362. }
  1363. var $remove = $(
  1364. '<span class="select2-selection__clear">' +
  1365. '&times;' +
  1366. '</span>'
  1367. );
  1368. $remove.data('data', data);
  1369. this.$selection.find('.select2-selection__rendered').prepend($remove);
  1370. };
  1371. return AllowClear;
  1372. });
  1373. S2.define('select2/selection/search',[
  1374. 'jquery',
  1375. '../utils',
  1376. '../keys'
  1377. ], function ($, Utils, KEYS) {
  1378. function Search (decorated, $element, options) {
  1379. decorated.call(this, $element, options);
  1380. }
  1381. Search.prototype.render = function (decorated) {
  1382. var $search = $(
  1383. '<li class="select2-search select2-search--inline">' +
  1384. '<input class="select2-search__field" type="search" tabindex="-1"' +
  1385. ' autocomplete="off" autocorrect="off" autocapitalize="off"' +
  1386. ' spellcheck="false" role="textbox" />' +
  1387. '</li>'
  1388. );
  1389. this.$searchContainer = $search;
  1390. this.$search = $search.find('input');
  1391. var $rendered = decorated.call(this);
  1392. return $rendered;
  1393. };
  1394. Search.prototype.bind = function (decorated, container, $container) {
  1395. var self = this;
  1396. decorated.call(this, container, $container);
  1397. container.on('open', function () {
  1398. self.$search.attr('tabindex', 0);
  1399. self.$search.focus();
  1400. });
  1401. container.on('close', function () {
  1402. self.$search.attr('tabindex', -1);
  1403. self.$search.val('');
  1404. self.$search.focus();
  1405. });
  1406. container.on('enable', function () {
  1407. self.$search.prop('disabled', false);
  1408. });
  1409. container.on('disable', function () {
  1410. self.$search.prop('disabled', true);
  1411. });
  1412. this.$selection.on('focusin', '.select2-search--inline', function (evt) {
  1413. self.trigger('focus', evt);
  1414. });
  1415. this.$selection.on('focusout', '.select2-search--inline', function (evt) {
  1416. self.trigger('blur', evt);
  1417. });
  1418. this.$selection.on('keydown', '.select2-search--inline', function (evt) {
  1419. evt.stopPropagation();
  1420. self.trigger('keypress', evt);
  1421. self._keyUpPrevented = evt.isDefaultPrevented();
  1422. var key = evt.which;
  1423. if (key === KEYS.BACKSPACE && self.$search.val() === '') {
  1424. var $previousChoice = self.$searchContainer
  1425. .prev('.select2-selection__choice');
  1426. if ($previousChoice.length > 0) {
  1427. var item = $previousChoice.data('data');
  1428. self.searchRemoveChoice(item);
  1429. evt.preventDefault();
  1430. }
  1431. }
  1432. });
  1433. // Workaround for browsers which do not support the `input` event
  1434. // This will prevent double-triggering of events for browsers which support
  1435. // both the `keyup` and `input` events.
  1436. this.$selection.on('input', '.select2-search--inline', function (evt) {
  1437. // Unbind the duplicated `keyup` event
  1438. self.$selection.off('keyup.search');
  1439. });
  1440. this.$selection.on('keyup.search input', '.select2-search--inline',
  1441. function (evt) {
  1442. self.handleSearch(evt);
  1443. });
  1444. };
  1445. Search.prototype.createPlaceholder = function (decorated, placeholder) {
  1446. this.$search.attr('placeholder', placeholder.text);
  1447. };
  1448. Search.prototype.update = function (decorated, data) {
  1449. this.$search.attr('placeholder', '');
  1450. decorated.call(this, data);
  1451. this.$selection.find('.select2-selection__rendered')
  1452. .append(this.$searchContainer);
  1453. this.resizeSearch();
  1454. };
  1455. Search.prototype.handleSearch = function () {
  1456. this.resizeSearch();
  1457. if (!this._keyUpPrevented) {
  1458. var input = this.$search.val();
  1459. this.trigger('query', {
  1460. term: input
  1461. });
  1462. }
  1463. this._keyUpPrevented = false;
  1464. };
  1465. Search.prototype.searchRemoveChoice = function (decorated, item) {
  1466. this.trigger('unselect', {
  1467. data: item
  1468. });
  1469. this.trigger('open');
  1470. this.$search.val(item.text + ' ');
  1471. };
  1472. Search.prototype.resizeSearch = function () {
  1473. this.$search.css('width', '25px');
  1474. var width = '';
  1475. if (this.$search.attr('placeholder') !== '') {
  1476. width = this.$selection.find('.select2-selection__rendered').innerWidth();
  1477. } else {
  1478. var minimumWidth = this.$search.val().length + 1;
  1479. width = (minimumWidth * 0.75) + 'em';
  1480. }
  1481. this.$search.css('width', width);
  1482. };
  1483. return Search;
  1484. });
  1485. S2.define('select2/selection/eventRelay',[
  1486. 'jquery'
  1487. ], function ($) {
  1488. function EventRelay () { }
  1489. EventRelay.prototype.bind = function (decorated, container, $container) {
  1490. var self = this;
  1491. var relayEvents = [
  1492. 'open', 'opening',
  1493. 'close', 'closing',
  1494. 'select', 'selecting',
  1495. 'unselect', 'unselecting'
  1496. ];
  1497. var preventableEvents = ['opening', 'closing', 'selecting', 'unselecting'];
  1498. decorated.call(this, container, $container);
  1499. container.on('*', function (name, params) {
  1500. // Ignore events that should not be relayed
  1501. if ($.inArray(name, relayEvents) === -1) {
  1502. return;
  1503. }
  1504. // The parameters should always be an object
  1505. params = params || {};
  1506. // Generate the jQuery event for the Select2 event
  1507. var evt = $.Event('select2:' + name, {
  1508. params: params
  1509. });
  1510. self.$element.trigger(evt);
  1511. // Only handle preventable events if it was one
  1512. if ($.inArray(name, preventableEvents) === -1) {
  1513. return;
  1514. }
  1515. params.prevented = evt.isDefaultPrevented();
  1516. });
  1517. };
  1518. return EventRelay;
  1519. });
  1520. S2.define('select2/translation',[
  1521. 'jquery',
  1522. 'require'
  1523. ], function ($, require) {
  1524. function Translation (dict) {
  1525. this.dict = dict || {};
  1526. }
  1527. Translation.prototype.all = function () {
  1528. return this.dict;
  1529. };
  1530. Translation.prototype.get = function (key) {
  1531. return this.dict[key];
  1532. };
  1533. Translation.prototype.extend = function (translation) {
  1534. this.dict = $.extend({}, translation.all(), this.dict);
  1535. };
  1536. // Static functions
  1537. Translation._cache = {};
  1538. Translation.loadPath = function (path) {
  1539. if (!(path in Translation._cache)) {
  1540. var translations = require(path);
  1541. Translation._cache[path] = translations;
  1542. }
  1543. return new Translation(Translation._cache[path]);
  1544. };
  1545. return Translation;
  1546. });
  1547. S2.define('select2/diacritics',[
  1548. ], function () {
  1549. var diacritics = {
  1550. '\u24B6': 'A',
  1551. '\uFF21': 'A',
  1552. '\u00C0': 'A',
  1553. '\u00C1': 'A',
  1554. '\u00C2': 'A',
  1555. '\u1EA6': 'A',
  1556. '\u1EA4': 'A',
  1557. '\u1EAA': 'A',
  1558. '\u1EA8': 'A',
  1559. '\u00C3': 'A',
  1560. '\u0100': 'A',
  1561. '\u0102': 'A',
  1562. '\u1EB0': 'A',
  1563. '\u1EAE': 'A',
  1564. '\u1EB4': 'A',
  1565. '\u1EB2': 'A',
  1566. '\u0226': 'A',
  1567. '\u01E0': 'A',
  1568. '\u00C4': 'A',
  1569. '\u01DE': 'A',
  1570. '\u1EA2': 'A',
  1571. '\u00C5': 'A',
  1572. '\u01FA': 'A',
  1573. '\u01CD': 'A',
  1574. '\u0200': 'A',
  1575. '\u0202': 'A',
  1576. '\u1EA0': 'A',
  1577. '\u1EAC': 'A',
  1578. '\u1EB6': 'A',
  1579. '\u1E00': 'A',
  1580. '\u0104': 'A',
  1581. '\u023A': 'A',
  1582. '\u2C6F': 'A',
  1583. '\uA732': 'AA',
  1584. '\u00C6': 'AE',
  1585. '\u01FC': 'AE',
  1586. '\u01E2': 'AE',
  1587. '\uA734': 'AO',
  1588. '\uA736': 'AU',
  1589. '\uA738': 'AV',
  1590. '\uA73A': 'AV',
  1591. '\uA73C': 'AY',
  1592. '\u24B7': 'B',
  1593. '\uFF22': 'B',
  1594. '\u1E02': 'B',
  1595. '\u1E04': 'B',
  1596. '\u1E06': 'B',
  1597. '\u0243': 'B',
  1598. '\u0182': 'B',
  1599. '\u0181': 'B',
  1600. '\u24B8': 'C',
  1601. '\uFF23': 'C',
  1602. '\u0106': 'C',
  1603. '\u0108': 'C',
  1604. '\u010A': 'C',
  1605. '\u010C': 'C',
  1606. '\u00C7': 'C',
  1607. '\u1E08': 'C',
  1608. '\u0187': 'C',
  1609. '\u023B': 'C',
  1610. '\uA73E': 'C',
  1611. '\u24B9': 'D',
  1612. '\uFF24': 'D',
  1613. '\u1E0A': 'D',
  1614. '\u010E': 'D',
  1615. '\u1E0C': 'D',
  1616. '\u1E10': 'D',
  1617. '\u1E12': 'D',
  1618. '\u1E0E': 'D',
  1619. '\u0110': 'D',
  1620. '\u018B': 'D',
  1621. '\u018A': 'D',
  1622. '\u0189': 'D',
  1623. '\uA779': 'D',
  1624. '\u01F1': 'DZ',
  1625. '\u01C4': 'DZ',
  1626. '\u01F2': 'Dz',
  1627. '\u01C5': 'Dz',
  1628. '\u24BA': 'E',
  1629. '\uFF25': 'E',
  1630. '\u00C8': 'E',
  1631. '\u00C9': 'E',
  1632. '\u00CA': 'E',
  1633. '\u1EC0': 'E',
  1634. '\u1EBE': 'E',
  1635. '\u1EC4': 'E',
  1636. '\u1EC2': 'E',
  1637. '\u1EBC': 'E',
  1638. '\u0112': 'E',
  1639. '\u1E14': 'E',
  1640. '\u1E16': 'E',
  1641. '\u0114': 'E',
  1642. '\u0116': 'E',
  1643. '\u00CB': 'E',
  1644. '\u1EBA': 'E',
  1645. '\u011A': 'E',
  1646. '\u0204': 'E',
  1647. '\u0206': 'E',
  1648. '\u1EB8': 'E',
  1649. '\u1EC6': 'E',
  1650. '\u0228': 'E',
  1651. '\u1E1C': 'E',
  1652. '\u0118': 'E',
  1653. '\u1E18': 'E',
  1654. '\u1E1A': 'E',
  1655. '\u0190': 'E',
  1656. '\u018E': 'E',
  1657. '\u24BB': 'F',
  1658. '\uFF26': 'F',
  1659. '\u1E1E': 'F',
  1660. '\u0191': 'F',
  1661. '\uA77B': 'F',
  1662. '\u24BC': 'G',
  1663. '\uFF27': 'G',
  1664. '\u01F4': 'G',
  1665. '\u011C': 'G',
  1666. '\u1E20': 'G',
  1667. '\u011E': 'G',
  1668. '\u0120': 'G',
  1669. '\u01E6': 'G',
  1670. '\u0122': 'G',
  1671. '\u01E4': 'G',
  1672. '\u0193': 'G',
  1673. '\uA7A0': 'G',
  1674. '\uA77D': 'G',
  1675. '\uA77E': 'G',
  1676. '\u24BD': 'H',
  1677. '\uFF28': 'H',
  1678. '\u0124': 'H',
  1679. '\u1E22': 'H',
  1680. '\u1E26': 'H',
  1681. '\u021E': 'H',
  1682. '\u1E24': 'H',
  1683. '\u1E28': 'H',
  1684. '\u1E2A': 'H',
  1685. '\u0126': 'H',
  1686. '\u2C67': 'H',
  1687. '\u2C75': 'H',
  1688. '\uA78D': 'H',
  1689. '\u24BE': 'I',
  1690. '\uFF29': 'I',
  1691. '\u00CC': 'I',
  1692. '\u00CD': 'I',
  1693. '\u00CE': 'I',
  1694. '\u0128': 'I',
  1695. '\u012A': 'I',
  1696. '\u012C': 'I',
  1697. '\u0130': 'I',
  1698. '\u00CF': 'I',
  1699. '\u1E2E': 'I',
  1700. '\u1EC8': 'I',
  1701. '\u01CF': 'I',
  1702. '\u0208': 'I',
  1703. '\u020A': 'I',
  1704. '\u1ECA': 'I',
  1705. '\u012E': 'I',
  1706. '\u1E2C': 'I',
  1707. '\u0197': 'I',
  1708. '\u24BF': 'J',
  1709. '\uFF2A': 'J',
  1710. '\u0134': 'J',
  1711. '\u0248': 'J',
  1712. '\u24C0': 'K',
  1713. '\uFF2B': 'K',
  1714. '\u1E30': 'K',
  1715. '\u01E8': 'K',
  1716. '\u1E32': 'K',
  1717. '\u0136': 'K',
  1718. '\u1E34': 'K',
  1719. '\u0198': 'K',
  1720. '\u2C69': 'K',
  1721. '\uA740': 'K',
  1722. '\uA742': 'K',
  1723. '\uA744': 'K',
  1724. '\uA7A2': 'K',
  1725. '\u24C1': 'L',
  1726. '\uFF2C': 'L',
  1727. '\u013F': 'L',
  1728. '\u0139': 'L',
  1729. '\u013D': 'L',
  1730. '\u1E36': 'L',
  1731. '\u1E38': 'L',
  1732. '\u013B': 'L',
  1733. '\u1E3C': 'L',
  1734. '\u1E3A': 'L',
  1735. '\u0141': 'L',
  1736. '\u023D': 'L',
  1737. '\u2C62': 'L',
  1738. '\u2C60': 'L',
  1739. '\uA748': 'L',
  1740. '\uA746': 'L',
  1741. '\uA780': 'L',
  1742. '\u01C7': 'LJ',
  1743. '\u01C8': 'Lj',
  1744. '\u24C2': 'M',
  1745. '\uFF2D': 'M',
  1746. '\u1E3E': 'M',
  1747. '\u1E40': 'M',
  1748. '\u1E42': 'M',
  1749. '\u2C6E': 'M',
  1750. '\u019C': 'M',
  1751. '\u24C3': 'N',
  1752. '\uFF2E': 'N',
  1753. '\u01F8': 'N',
  1754. '\u0143': 'N',
  1755. '\u00D1': 'N',
  1756. '\u1E44': 'N',
  1757. '\u0147': 'N',
  1758. '\u1E46': 'N',
  1759. '\u0145': 'N',
  1760. '\u1E4A': 'N',
  1761. '\u1E48': 'N',
  1762. '\u0220': 'N',
  1763. '\u019D': 'N',
  1764. '\uA790': 'N',
  1765. '\uA7A4': 'N',
  1766. '\u01CA': 'NJ',
  1767. '\u01CB': 'Nj',
  1768. '\u24C4': 'O',
  1769. '\uFF2F': 'O',
  1770. '\u00D2': 'O',
  1771. '\u00D3': 'O',
  1772. '\u00D4': 'O',
  1773. '\u1ED2': 'O',
  1774. '\u1ED0': 'O',
  1775. '\u1ED6': 'O',
  1776. '\u1ED4': 'O',
  1777. '\u00D5': 'O',
  1778. '\u1E4C': 'O',
  1779. '\u022C': 'O',
  1780. '\u1E4E': 'O',
  1781. '\u014C': 'O',
  1782. '\u1E50': 'O',
  1783. '\u1E52': 'O',
  1784. '\u014E': 'O',
  1785. '\u022E': 'O',
  1786. '\u0230': 'O',
  1787. '\u00D6': 'O',
  1788. '\u022A': 'O',
  1789. '\u1ECE': 'O',
  1790. '\u0150': 'O',
  1791. '\u01D1': 'O',
  1792. '\u020C': 'O',
  1793. '\u020E': 'O',
  1794. '\u01A0': 'O',
  1795. '\u1EDC': 'O',
  1796. '\u1EDA': 'O',
  1797. '\u1EE0': 'O',
  1798. '\u1EDE': 'O',
  1799. '\u1EE2': 'O',
  1800. '\u1ECC': 'O',
  1801. '\u1ED8': 'O',
  1802. '\u01EA': 'O',
  1803. '\u01EC': 'O',
  1804. '\u00D8': 'O',
  1805. '\u01FE': 'O',
  1806. '\u0186': 'O',
  1807. '\u019F': 'O',
  1808. '\uA74A': 'O',
  1809. '\uA74C': 'O',
  1810. '\u01A2': 'OI',
  1811. '\uA74E': 'OO',
  1812. '\u0222': 'OU',
  1813. '\u24C5': 'P',
  1814. '\uFF30': 'P',
  1815. '\u1E54': 'P',
  1816. '\u1E56': 'P',
  1817. '\u01A4': 'P',
  1818. '\u2C63': 'P',
  1819. '\uA750': 'P',
  1820. '\uA752': 'P',
  1821. '\uA754': 'P',
  1822. '\u24C6': 'Q',
  1823. '\uFF31': 'Q',
  1824. '\uA756': 'Q',
  1825. '\uA758': 'Q',
  1826. '\u024A': 'Q',
  1827. '\u24C7': 'R',
  1828. '\uFF32': 'R',
  1829. '\u0154': 'R',
  1830. '\u1E58': 'R',
  1831. '\u0158': 'R',
  1832. '\u0210': 'R',
  1833. '\u0212': 'R',
  1834. '\u1E5A': 'R',
  1835. '\u1E5C': 'R',
  1836. '\u0156': 'R',
  1837. '\u1E5E': 'R',
  1838. '\u024C': 'R',
  1839. '\u2C64': 'R',
  1840. '\uA75A': 'R',
  1841. '\uA7A6': 'R',
  1842. '\uA782': 'R',
  1843. '\u24C8': 'S',
  1844. '\uFF33': 'S',
  1845. '\u1E9E': 'S',
  1846. '\u015A': 'S',
  1847. '\u1E64': 'S',
  1848. '\u015C': 'S',
  1849. '\u1E60': 'S',
  1850. '\u0160': 'S',
  1851. '\u1E66': 'S',
  1852. '\u1E62': 'S',
  1853. '\u1E68': 'S',
  1854. '\u0218': 'S',
  1855. '\u015E': 'S',
  1856. '\u2C7E': 'S',
  1857. '\uA7A8': 'S',
  1858. '\uA784': 'S',
  1859. '\u24C9': 'T',
  1860. '\uFF34': 'T',
  1861. '\u1E6A': 'T',
  1862. '\u0164': 'T',
  1863. '\u1E6C': 'T',
  1864. '\u021A': 'T',
  1865. '\u0162': 'T',
  1866. '\u1E70': 'T',
  1867. '\u1E6E': 'T',
  1868. '\u0166': 'T',
  1869. '\u01AC': 'T',
  1870. '\u01AE': 'T',
  1871. '\u023E': 'T',
  1872. '\uA786': 'T',
  1873. '\uA728': 'TZ',
  1874. '\u24CA': 'U',
  1875. '\uFF35': 'U',
  1876. '\u00D9': 'U',
  1877. '\u00DA': 'U',
  1878. '\u00DB': 'U',
  1879. '\u0168': 'U',
  1880. '\u1E78': 'U',
  1881. '\u016A': 'U',
  1882. '\u1E7A': 'U',
  1883. '\u016C': 'U',
  1884. '\u00DC': 'U',
  1885. '\u01DB': 'U',
  1886. '\u01D7': 'U',
  1887. '\u01D5': 'U',
  1888. '\u01D9': 'U',
  1889. '\u1EE6': 'U',
  1890. '\u016E': 'U',
  1891. '\u0170': 'U',
  1892. '\u01D3': 'U',
  1893. '\u0214': 'U',
  1894. '\u0216': 'U',
  1895. '\u01AF': 'U',
  1896. '\u1EEA': 'U',
  1897. '\u1EE8': 'U',
  1898. '\u1EEE': 'U',
  1899. '\u1EEC': 'U',
  1900. '\u1EF0': 'U',
  1901. '\u1EE4': 'U',
  1902. '\u1E72': 'U',
  1903. '\u0172': 'U',
  1904. '\u1E76': 'U',
  1905. '\u1E74': 'U',
  1906. '\u0244': 'U',
  1907. '\u24CB': 'V',
  1908. '\uFF36': 'V',
  1909. '\u1E7C': 'V',
  1910. '\u1E7E': 'V',
  1911. '\u01B2': 'V',
  1912. '\uA75E': 'V',
  1913. '\u0245': 'V',
  1914. '\uA760': 'VY',
  1915. '\u24CC': 'W',
  1916. '\uFF37': 'W',
  1917. '\u1E80': 'W',
  1918. '\u1E82': 'W',
  1919. '\u0174': 'W',
  1920. '\u1E86': 'W',
  1921. '\u1E84': 'W',
  1922. '\u1E88': 'W',
  1923. '\u2C72': 'W',
  1924. '\u24CD': 'X',
  1925. '\uFF38': 'X',
  1926. '\u1E8A': 'X',
  1927. '\u1E8C': 'X',
  1928. '\u24CE': 'Y',
  1929. '\uFF39': 'Y',
  1930. '\u1EF2': 'Y',
  1931. '\u00DD': 'Y',
  1932. '\u0176': 'Y',
  1933. '\u1EF8': 'Y',
  1934. '\u0232': 'Y',
  1935. '\u1E8E': 'Y',
  1936. '\u0178': 'Y',
  1937. '\u1EF6': 'Y',
  1938. '\u1EF4': 'Y',
  1939. '\u01B3': 'Y',
  1940. '\u024E': 'Y',
  1941. '\u1EFE': 'Y',
  1942. '\u24CF': 'Z',
  1943. '\uFF3A': 'Z',
  1944. '\u0179': 'Z',
  1945. '\u1E90': 'Z',
  1946. '\u017B': 'Z',
  1947. '\u017D': 'Z',
  1948. '\u1E92': 'Z',
  1949. '\u1E94': 'Z',
  1950. '\u01B5': 'Z',
  1951. '\u0224': 'Z',
  1952. '\u2C7F': 'Z',
  1953. '\u2C6B': 'Z',
  1954. '\uA762': 'Z',
  1955. '\u24D0': 'a',
  1956. '\uFF41': 'a',
  1957. '\u1E9A': 'a',
  1958. '\u00E0': 'a',
  1959. '\u00E1': 'a',
  1960. '\u00E2': 'a',
  1961. '\u1EA7': 'a',
  1962. '\u1EA5': 'a',
  1963. '\u1EAB': 'a',
  1964. '\u1EA9': 'a',
  1965. '\u00E3': 'a',
  1966. '\u0101': 'a',
  1967. '\u0103': 'a',
  1968. '\u1EB1': 'a',
  1969. '\u1EAF': 'a',
  1970. '\u1EB5': 'a',
  1971. '\u1EB3': 'a',
  1972. '\u0227': 'a',
  1973. '\u01E1': 'a',
  1974. '\u00E4': 'a',
  1975. '\u01DF': 'a',
  1976. '\u1EA3': 'a',
  1977. '\u00E5': 'a',
  1978. '\u01FB': 'a',
  1979. '\u01CE': 'a',
  1980. '\u0201': 'a',
  1981. '\u0203': 'a',
  1982. '\u1EA1': 'a',
  1983. '\u1EAD': 'a',
  1984. '\u1EB7': 'a',
  1985. '\u1E01': 'a',
  1986. '\u0105': 'a',
  1987. '\u2C65': 'a',
  1988. '\u0250': 'a',
  1989. '\uA733': 'aa',
  1990. '\u00E6': 'ae',
  1991. '\u01FD': 'ae',
  1992. '\u01E3': 'ae',
  1993. '\uA735': 'ao',
  1994. '\uA737': 'au',
  1995. '\uA739': 'av',
  1996. '\uA73B': 'av',
  1997. '\uA73D': 'ay',
  1998. '\u24D1': 'b',
  1999. '\uFF42': 'b',
  2000. '\u1E03': 'b',
  2001. '\u1E05': 'b',
  2002. '\u1E07': 'b',
  2003. '\u0180': 'b',
  2004. '\u0183': 'b',
  2005. '\u0253': 'b',
  2006. '\u24D2': 'c',
  2007. '\uFF43': 'c',
  2008. '\u0107': 'c',
  2009. '\u0109': 'c',
  2010. '\u010B': 'c',
  2011. '\u010D': 'c',
  2012. '\u00E7': 'c',
  2013. '\u1E09': 'c',
  2014. '\u0188': 'c',
  2015. '\u023C': 'c',
  2016. '\uA73F': 'c',
  2017. '\u2184': 'c',
  2018. '\u24D3': 'd',
  2019. '\uFF44': 'd',
  2020. '\u1E0B': 'd',
  2021. '\u010F': 'd',
  2022. '\u1E0D': 'd',
  2023. '\u1E11': 'd',
  2024. '\u1E13': 'd',
  2025. '\u1E0F': 'd',
  2026. '\u0111': 'd',
  2027. '\u018C': 'd',
  2028. '\u0256': 'd',
  2029. '\u0257': 'd',
  2030. '\uA77A': 'd',
  2031. '\u01F3': 'dz',
  2032. '\u01C6': 'dz',
  2033. '\u24D4': 'e',
  2034. '\uFF45': 'e',
  2035. '\u00E8': 'e',
  2036. '\u00E9': 'e',
  2037. '\u00EA': 'e',
  2038. '\u1EC1': 'e',
  2039. '\u1EBF': 'e',
  2040. '\u1EC5': 'e',
  2041. '\u1EC3': 'e',
  2042. '\u1EBD': 'e',
  2043. '\u0113': 'e',
  2044. '\u1E15': 'e',
  2045. '\u1E17': 'e',
  2046. '\u0115': 'e',
  2047. '\u0117': 'e',
  2048. '\u00EB': 'e',
  2049. '\u1EBB': 'e',
  2050. '\u011B': 'e',
  2051. '\u0205': 'e',
  2052. '\u0207': 'e',
  2053. '\u1EB9': 'e',
  2054. '\u1EC7': 'e',
  2055. '\u0229': 'e',
  2056. '\u1E1D': 'e',
  2057. '\u0119': 'e',
  2058. '\u1E19': 'e',
  2059. '\u1E1B': 'e',
  2060. '\u0247': 'e',
  2061. '\u025B': 'e',
  2062. '\u01DD': 'e',
  2063. '\u24D5': 'f',
  2064. '\uFF46': 'f',
  2065. '\u1E1F': 'f',
  2066. '\u0192': 'f',
  2067. '\uA77C': 'f',
  2068. '\u24D6': 'g',
  2069. '\uFF47': 'g',
  2070. '\u01F5': 'g',
  2071. '\u011D': 'g',
  2072. '\u1E21': 'g',
  2073. '\u011F': 'g',
  2074. '\u0121': 'g',
  2075. '\u01E7': 'g',
  2076. '\u0123': 'g',
  2077. '\u01E5': 'g',
  2078. '\u0260': 'g',
  2079. '\uA7A1': 'g',
  2080. '\u1D79': 'g',
  2081. '\uA77F': 'g',
  2082. '\u24D7': 'h',
  2083. '\uFF48': 'h',
  2084. '\u0125': 'h',
  2085. '\u1E23': 'h',
  2086. '\u1E27': 'h',
  2087. '\u021F': 'h',
  2088. '\u1E25': 'h',
  2089. '\u1E29': 'h',
  2090. '\u1E2B': 'h',
  2091. '\u1E96': 'h',
  2092. '\u0127': 'h',
  2093. '\u2C68': 'h',
  2094. '\u2C76': 'h',
  2095. '\u0265': 'h',
  2096. '\u0195': 'hv',
  2097. '\u24D8': 'i',
  2098. '\uFF49': 'i',
  2099. '\u00EC': 'i',
  2100. '\u00ED': 'i',
  2101. '\u00EE': 'i',
  2102. '\u0129': 'i',
  2103. '\u012B': 'i',
  2104. '\u012D': 'i',
  2105. '\u00EF': 'i',
  2106. '\u1E2F': 'i',
  2107. '\u1EC9': 'i',
  2108. '\u01D0': 'i',
  2109. '\u0209': 'i',
  2110. '\u020B': 'i',
  2111. '\u1ECB': 'i',
  2112. '\u012F': 'i',
  2113. '\u1E2D': 'i',
  2114. '\u0268': 'i',
  2115. '\u0131': 'i',
  2116. '\u24D9': 'j',
  2117. '\uFF4A': 'j',
  2118. '\u0135': 'j',
  2119. '\u01F0': 'j',
  2120. '\u0249': 'j',
  2121. '\u24DA': 'k',
  2122. '\uFF4B': 'k',
  2123. '\u1E31': 'k',
  2124. '\u01E9': 'k',
  2125. '\u1E33': 'k',
  2126. '\u0137': 'k',
  2127. '\u1E35': 'k',
  2128. '\u0199': 'k',
  2129. '\u2C6A': 'k',
  2130. '\uA741': 'k',
  2131. '\uA743': 'k',
  2132. '\uA745': 'k',
  2133. '\uA7A3': 'k',
  2134. '\u24DB': 'l',
  2135. '\uFF4C': 'l',
  2136. '\u0140': 'l',
  2137. '\u013A': 'l',
  2138. '\u013E': 'l',
  2139. '\u1E37': 'l',
  2140. '\u1E39': 'l',
  2141. '\u013C': 'l',
  2142. '\u1E3D': 'l',
  2143. '\u1E3B': 'l',
  2144. '\u017F': 'l',
  2145. '\u0142': 'l',
  2146. '\u019A': 'l',
  2147. '\u026B': 'l',
  2148. '\u2C61': 'l',
  2149. '\uA749': 'l',
  2150. '\uA781': 'l',
  2151. '\uA747': 'l',
  2152. '\u01C9': 'lj',
  2153. '\u24DC': 'm',
  2154. '\uFF4D': 'm',
  2155. '\u1E3F': 'm',
  2156. '\u1E41': 'm',
  2157. '\u1E43': 'm',
  2158. '\u0271': 'm',
  2159. '\u026F': 'm',
  2160. '\u24DD': 'n',
  2161. '\uFF4E': 'n',
  2162. '\u01F9': 'n',
  2163. '\u0144': 'n',
  2164. '\u00F1': 'n',
  2165. '\u1E45': 'n',
  2166. '\u0148': 'n',
  2167. '\u1E47': 'n',
  2168. '\u0146': 'n',
  2169. '\u1E4B': 'n',
  2170. '\u1E49': 'n',
  2171. '\u019E': 'n',
  2172. '\u0272': 'n',
  2173. '\u0149': 'n',
  2174. '\uA791': 'n',
  2175. '\uA7A5': 'n',
  2176. '\u01CC': 'nj',
  2177. '\u24DE': 'o',
  2178. '\uFF4F': 'o',
  2179. '\u00F2': 'o',
  2180. '\u00F3': 'o',
  2181. '\u00F4': 'o',
  2182. '\u1ED3': 'o',
  2183. '\u1ED1': 'o',
  2184. '\u1ED7': 'o',
  2185. '\u1ED5': 'o',
  2186. '\u00F5': 'o',
  2187. '\u1E4D': 'o',
  2188. '\u022D': 'o',
  2189. '\u1E4F': 'o',
  2190. '\u014D': 'o',
  2191. '\u1E51': 'o',
  2192. '\u1E53': 'o',
  2193. '\u014F': 'o',
  2194. '\u022F': 'o',
  2195. '\u0231': 'o',
  2196. '\u00F6': 'o',
  2197. '\u022B': 'o',
  2198. '\u1ECF': 'o',
  2199. '\u0151': 'o',
  2200. '\u01D2': 'o',
  2201. '\u020D': 'o',
  2202. '\u020F': 'o',
  2203. '\u01A1': 'o',
  2204. '\u1EDD': 'o',
  2205. '\u1EDB': 'o',
  2206. '\u1EE1': 'o',
  2207. '\u1EDF': 'o',
  2208. '\u1EE3': 'o',
  2209. '\u1ECD': 'o',
  2210. '\u1ED9': 'o',
  2211. '\u01EB': 'o',
  2212. '\u01ED': 'o',
  2213. '\u00F8': 'o',
  2214. '\u01FF': 'o',
  2215. '\u0254': 'o',
  2216. '\uA74B': 'o',
  2217. '\uA74D': 'o',
  2218. '\u0275': 'o',
  2219. '\u01A3': 'oi',
  2220. '\u0223': 'ou',
  2221. '\uA74F': 'oo',
  2222. '\u24DF': 'p',
  2223. '\uFF50': 'p',
  2224. '\u1E55': 'p',
  2225. '\u1E57': 'p',
  2226. '\u01A5': 'p',
  2227. '\u1D7D': 'p',
  2228. '\uA751': 'p',
  2229. '\uA753': 'p',
  2230. '\uA755': 'p',
  2231. '\u24E0': 'q',
  2232. '\uFF51': 'q',
  2233. '\u024B': 'q',
  2234. '\uA757': 'q',
  2235. '\uA759': 'q',
  2236. '\u24E1': 'r',
  2237. '\uFF52': 'r',
  2238. '\u0155': 'r',
  2239. '\u1E59': 'r',
  2240. '\u0159': 'r',
  2241. '\u0211': 'r',
  2242. '\u0213': 'r',
  2243. '\u1E5B': 'r',
  2244. '\u1E5D': 'r',
  2245. '\u0157': 'r',
  2246. '\u1E5F': 'r',
  2247. '\u024D': 'r',
  2248. '\u027D': 'r',
  2249. '\uA75B': 'r',
  2250. '\uA7A7': 'r',
  2251. '\uA783': 'r',
  2252. '\u24E2': 's',
  2253. '\uFF53': 's',
  2254. '\u00DF': 's',
  2255. '\u015B': 's',
  2256. '\u1E65': 's',
  2257. '\u015D': 's',
  2258. '\u1E61': 's',
  2259. '\u0161': 's',
  2260. '\u1E67': 's',
  2261. '\u1E63': 's',
  2262. '\u1E69': 's',
  2263. '\u0219': 's',
  2264. '\u015F': 's',
  2265. '\u023F': 's',
  2266. '\uA7A9': 's',
  2267. '\uA785': 's',
  2268. '\u1E9B': 's',
  2269. '\u24E3': 't',
  2270. '\uFF54': 't',
  2271. '\u1E6B': 't',
  2272. '\u1E97': 't',
  2273. '\u0165': 't',
  2274. '\u1E6D': 't',
  2275. '\u021B': 't',
  2276. '\u0163': 't',
  2277. '\u1E71': 't',
  2278. '\u1E6F': 't',
  2279. '\u0167': 't',
  2280. '\u01AD': 't',
  2281. '\u0288': 't',
  2282. '\u2C66': 't',
  2283. '\uA787': 't',
  2284. '\uA729': 'tz',
  2285. '\u24E4': 'u',
  2286. '\uFF55': 'u',
  2287. '\u00F9': 'u',
  2288. '\u00FA': 'u',
  2289. '\u00FB': 'u',
  2290. '\u0169': 'u',
  2291. '\u1E79': 'u',
  2292. '\u016B': 'u',
  2293. '\u1E7B': 'u',
  2294. '\u016D': 'u',
  2295. '\u00FC': 'u',
  2296. '\u01DC': 'u',
  2297. '\u01D8': 'u',
  2298. '\u01D6': 'u',
  2299. '\u01DA': 'u',
  2300. '\u1EE7': 'u',
  2301. '\u016F': 'u',
  2302. '\u0171': 'u',
  2303. '\u01D4': 'u',
  2304. '\u0215': 'u',
  2305. '\u0217': 'u',
  2306. '\u01B0': 'u',
  2307. '\u1EEB': 'u',
  2308. '\u1EE9': 'u',
  2309. '\u1EEF': 'u',
  2310. '\u1EED': 'u',
  2311. '\u1EF1': 'u',
  2312. '\u1EE5': 'u',
  2313. '\u1E73': 'u',
  2314. '\u0173': 'u',
  2315. '\u1E77': 'u',
  2316. '\u1E75': 'u',
  2317. '\u0289': 'u',
  2318. '\u24E5': 'v',
  2319. '\uFF56': 'v',
  2320. '\u1E7D': 'v',
  2321. '\u1E7F': 'v',
  2322. '\u028B': 'v',
  2323. '\uA75F': 'v',
  2324. '\u028C': 'v',
  2325. '\uA761': 'vy',
  2326. '\u24E6': 'w',
  2327. '\uFF57': 'w',
  2328. '\u1E81': 'w',
  2329. '\u1E83': 'w',
  2330. '\u0175': 'w',
  2331. '\u1E87': 'w',
  2332. '\u1E85': 'w',
  2333. '\u1E98': 'w',
  2334. '\u1E89': 'w',
  2335. '\u2C73': 'w',
  2336. '\u24E7': 'x',
  2337. '\uFF58': 'x',
  2338. '\u1E8B': 'x',
  2339. '\u1E8D': 'x',
  2340. '\u24E8': 'y',
  2341. '\uFF59': 'y',
  2342. '\u1EF3': 'y',
  2343. '\u00FD': 'y',
  2344. '\u0177': 'y',
  2345. '\u1EF9': 'y',
  2346. '\u0233': 'y',
  2347. '\u1E8F': 'y',
  2348. '\u00FF': 'y',
  2349. '\u1EF7': 'y',
  2350. '\u1E99': 'y',
  2351. '\u1EF5': 'y',
  2352. '\u01B4': 'y',
  2353. '\u024F': 'y',
  2354. '\u1EFF': 'y',
  2355. '\u24E9': 'z',
  2356. '\uFF5A': 'z',
  2357. '\u017A': 'z',
  2358. '\u1E91': 'z',
  2359. '\u017C': 'z',
  2360. '\u017E': 'z',
  2361. '\u1E93': 'z',
  2362. '\u1E95': 'z',
  2363. '\u01B6': 'z',
  2364. '\u0225': 'z',
  2365. '\u0240': 'z',
  2366. '\u2C6C': 'z',
  2367. '\uA763': 'z',
  2368. '\u0386': '\u0391',
  2369. '\u0388': '\u0395',
  2370. '\u0389': '\u0397',
  2371. '\u038A': '\u0399',
  2372. '\u03AA': '\u0399',
  2373. '\u038C': '\u039F',
  2374. '\u038E': '\u03A5',
  2375. '\u03AB': '\u03A5',
  2376. '\u038F': '\u03A9',
  2377. '\u03AC': '\u03B1',
  2378. '\u03AD': '\u03B5',
  2379. '\u03AE': '\u03B7',
  2380. '\u03AF': '\u03B9',
  2381. '\u03CA': '\u03B9',
  2382. '\u0390': '\u03B9',
  2383. '\u03CC': '\u03BF',
  2384. '\u03CD': '\u03C5',
  2385. '\u03CB': '\u03C5',
  2386. '\u03B0': '\u03C5',
  2387. '\u03C9': '\u03C9',
  2388. '\u03C2': '\u03C3'
  2389. };
  2390. return diacritics;
  2391. });
  2392. S2.define('select2/data/base',[
  2393. '../utils'
  2394. ], function (Utils) {
  2395. function BaseAdapter ($element, options) {
  2396. BaseAdapter.__super__.constructor.call(this);
  2397. }
  2398. Utils.Extend(BaseAdapter, Utils.Observable);
  2399. BaseAdapter.prototype.current = function (callback) {
  2400. throw new Error('The `current` method must be defined in child classes.');
  2401. };
  2402. BaseAdapter.prototype.query = function (params, callback) {
  2403. throw new Error('The `query` method must be defined in child classes.');
  2404. };
  2405. BaseAdapter.prototype.bind = function (container, $container) {
  2406. // Can be implemented in subclasses
  2407. };
  2408. BaseAdapter.prototype.destroy = function () {
  2409. // Can be implemented in subclasses
  2410. };
  2411. BaseAdapter.prototype.generateResultId = function (container, data) {
  2412. var id = container.id + '-result-';
  2413. id += Utils.generateChars(4);
  2414. if (data.id != null) {
  2415. id += '-' + data.id.toString();
  2416. } else {
  2417. id += '-' + Utils.generateChars(4);
  2418. }
  2419. return id;
  2420. };
  2421. return BaseAdapter;
  2422. });
  2423. S2.define('select2/data/select',[
  2424. './base',
  2425. '../utils',
  2426. 'jquery'
  2427. ], function (BaseAdapter, Utils, $) {
  2428. function SelectAdapter ($element, options) {
  2429. this.$element = $element;
  2430. this.options = options;
  2431. SelectAdapter.__super__.constructor.call(this);
  2432. }
  2433. Utils.Extend(SelectAdapter, BaseAdapter);
  2434. SelectAdapter.prototype.current = function (callback) {
  2435. var data = [];
  2436. var self = this;
  2437. this.$element.find(':selected').each(function () {
  2438. var $option = $(this);
  2439. var option = self.item($option);
  2440. data.push(option);
  2441. });
  2442. callback(data);
  2443. };
  2444. SelectAdapter.prototype.select = function (data) {
  2445. var self = this;
  2446. data.selected = true;
  2447. // If data.element is a DOM node, use it instead
  2448. if ($(data.element).is('option')) {
  2449. data.element.selected = true;
  2450. this.$element.trigger('change');
  2451. return;
  2452. }
  2453. if (this.$element.prop('multiple')) {
  2454. this.current(function (currentData) {
  2455. var val = [];
  2456. data = [data];
  2457. data.push.apply(data, currentData);
  2458. for (var d = 0; d < data.length; d++) {
  2459. var id = data[d].id;
  2460. if ($.inArray(id, val) === -1) {
  2461. val.push(id);
  2462. }
  2463. }
  2464. self.$element.val(val);
  2465. self.$element.trigger('change');
  2466. });
  2467. } else {
  2468. var val = data.id;
  2469. this.$element.val(val);
  2470. this.$element.trigger('change');
  2471. }
  2472. };
  2473. SelectAdapter.prototype.unselect = function (data) {
  2474. var self = this;
  2475. if (!this.$element.prop('multiple')) {
  2476. return;
  2477. }
  2478. data.selected = false;
  2479. if ($(data.element).is('option')) {
  2480. data.element.selected = false;
  2481. this.$element.trigger('change');
  2482. return;
  2483. }
  2484. this.current(function (currentData) {
  2485. var val = [];
  2486. for (var d = 0; d < currentData.length; d++) {
  2487. var id = currentData[d].id;
  2488. if (id !== data.id && $.inArray(id, val) === -1) {
  2489. val.push(id);
  2490. }
  2491. }
  2492. self.$element.val(val);
  2493. self.$element.trigger('change');
  2494. });
  2495. };
  2496. SelectAdapter.prototype.bind = function (container, $container) {
  2497. var self = this;
  2498. this.container = container;
  2499. container.on('select', function (params) {
  2500. self.select(params.data);
  2501. });
  2502. container.on('unselect', function (params) {
  2503. self.unselect(params.data);
  2504. });
  2505. };
  2506. SelectAdapter.prototype.destroy = function () {
  2507. // Remove anything added to child elements
  2508. this.$element.find('*').each(function () {
  2509. // Remove any custom data set by Select2
  2510. $.removeData(this, 'data');
  2511. });
  2512. };
  2513. SelectAdapter.prototype.query = function (params, callback) {
  2514. var data = [];
  2515. var self = this;
  2516. var $options = this.$element.children();
  2517. $options.each(function () {
  2518. var $option = $(this);
  2519. if (!$option.is('option') && !$option.is('optgroup')) {
  2520. return;
  2521. }
  2522. var option = self.item($option);
  2523. var matches = self.matches(params, option);
  2524. if (matches !== null) {
  2525. data.push(matches);
  2526. }
  2527. });
  2528. callback({
  2529. results: data
  2530. });
  2531. };
  2532. SelectAdapter.prototype.addOptions = function ($options) {
  2533. Utils.appendMany(this.$element, $options);
  2534. };
  2535. SelectAdapter.prototype.option = function (data) {
  2536. var option;
  2537. if (data.children) {
  2538. option = document.createElement('optgroup');
  2539. option.label = data.text;
  2540. } else {
  2541. option = document.createElement('option');
  2542. if (option.textContent !== undefined) {
  2543. option.textContent = data.text;
  2544. } else {
  2545. option.innerText = data.text;
  2546. }
  2547. }
  2548. if (data.id) {
  2549. option.value = data.id;
  2550. }
  2551. if (data.disabled) {
  2552. option.disabled = true;
  2553. }
  2554. if (data.selected) {
  2555. option.selected = true;
  2556. }
  2557. if (data.title) {
  2558. option.title = data.title;
  2559. }
  2560. var $option = $(option);
  2561. var normalizedData = this._normalizeItem(data);
  2562. normalizedData.element = option;
  2563. // Override the option's data with the combined data
  2564. $.data(option, 'data', normalizedData);
  2565. return $option;
  2566. };
  2567. SelectAdapter.prototype.item = function ($option) {
  2568. var data = {};
  2569. data = $.data($option[0], 'data');
  2570. if (data != null) {
  2571. return data;
  2572. }
  2573. if ($option.is('option')) {
  2574. data = {
  2575. id: $option.val(),
  2576. text: $option.text(),
  2577. disabled: $option.prop('disabled'),
  2578. selected: $option.prop('selected'),
  2579. title: $option.prop('title')
  2580. };
  2581. } else if ($option.is('optgroup')) {
  2582. data = {
  2583. text: $option.prop('label'),
  2584. children: [],
  2585. title: $option.prop('title')
  2586. };
  2587. var $children = $option.children('option');
  2588. var children = [];
  2589. for (var c = 0; c < $children.length; c++) {
  2590. var $child = $($children[c]);
  2591. var child = this.item($child);
  2592. children.push(child);
  2593. }
  2594. data.children = children;
  2595. }
  2596. data = this._normalizeItem(data);
  2597. data.element = $option[0];
  2598. $.data($option[0], 'data', data);
  2599. return data;
  2600. };
  2601. SelectAdapter.prototype._normalizeItem = function (item) {
  2602. if (!$.isPlainObject(item)) {
  2603. item = {
  2604. id: item,
  2605. text: item
  2606. };
  2607. }
  2608. item = $.extend({}, {
  2609. text: ''
  2610. }, item);
  2611. var defaults = {
  2612. selected: false,
  2613. disabled: false
  2614. };
  2615. if (item.id != null) {
  2616. item.id = item.id.toString();
  2617. }
  2618. if (item.text != null) {
  2619. item.text = item.text.toString();
  2620. }
  2621. if (item._resultId == null && item.id && this.container != null) {
  2622. item._resultId = this.generateResultId(this.container, item);
  2623. }
  2624. return $.extend({}, defaults, item);
  2625. };
  2626. SelectAdapter.prototype.matches = function (params, data) {
  2627. var matcher = this.options.get('matcher');
  2628. return matcher(params, data);
  2629. };
  2630. return SelectAdapter;
  2631. });
  2632. S2.define('select2/data/array',[
  2633. './select',
  2634. '../utils',
  2635. 'jquery'
  2636. ], function (SelectAdapter, Utils, $) {
  2637. function ArrayAdapter ($element, options) {
  2638. var data = options.get('data') || [];
  2639. ArrayAdapter.__super__.constructor.call(this, $element, options);
  2640. this.addOptions(this.convertToOptions(data));
  2641. }
  2642. Utils.Extend(ArrayAdapter, SelectAdapter);
  2643. ArrayAdapter.prototype.select = function (data) {
  2644. var $option = this.$element.find('option').filter(function (i, elm) {
  2645. return elm.value == data.id.toString();
  2646. });
  2647. if ($option.length === 0) {
  2648. $option = this.option(data);
  2649. this.addOptions($option);
  2650. }
  2651. ArrayAdapter.__super__.select.call(this, data);
  2652. };
  2653. ArrayAdapter.prototype.convertToOptions = function (data) {
  2654. var self = this;
  2655. var $existing = this.$element.find('option');
  2656. var existingIds = $existing.map(function () {
  2657. return self.item($(this)).id;
  2658. }).get();
  2659. var $options = [];
  2660. // Filter out all items except for the one passed in the argument
  2661. function onlyItem (item) {
  2662. return function () {
  2663. return $(this).val() == item.id;
  2664. };
  2665. }
  2666. for (var d = 0; d < data.length; d++) {
  2667. var item = this._normalizeItem(data[d]);
  2668. // Skip items which were pre-loaded, only merge the data
  2669. if ($.inArray(item.id, existingIds) >= 0) {
  2670. var $existingOption = $existing.filter(onlyItem(item));
  2671. var existingData = this.item($existingOption);
  2672. var newData = $.extend(true, {}, existingData, item);
  2673. var $newOption = this.option(existingData);
  2674. $existingOption.replaceWith($newOption);
  2675. continue;
  2676. }
  2677. var $option = this.option(item);
  2678. if (item.children) {
  2679. var $children = this.convertToOptions(item.children);
  2680. Utils.appendMany($option, $children);
  2681. }
  2682. $options.push($option);
  2683. }
  2684. return $options;
  2685. };
  2686. return ArrayAdapter;
  2687. });
  2688. S2.define('select2/data/ajax',[
  2689. './array',
  2690. '../utils',
  2691. 'jquery'
  2692. ], function (ArrayAdapter, Utils, $) {
  2693. function AjaxAdapter ($element, options) {
  2694. this.ajaxOptions = this._applyDefaults(options.get('ajax'));
  2695. if (this.ajaxOptions.processResults != null) {
  2696. this.processResults = this.ajaxOptions.processResults;
  2697. }
  2698. ArrayAdapter.__super__.constructor.call(this, $element, options);
  2699. }
  2700. Utils.Extend(AjaxAdapter, ArrayAdapter);
  2701. AjaxAdapter.prototype._applyDefaults = function (options) {
  2702. var defaults = {
  2703. data: function (params) {
  2704. return {
  2705. q: params.term
  2706. };
  2707. },
  2708. transport: function (params, success, failure) {
  2709. var $request = $.ajax(params);
  2710. $request.then(success);
  2711. $request.fail(failure);
  2712. return $request;
  2713. }
  2714. };
  2715. return $.extend({}, defaults, options, true);
  2716. };
  2717. AjaxAdapter.prototype.processResults = function (results) {
  2718. return results;
  2719. };
  2720. AjaxAdapter.prototype.query = function (params, callback) {
  2721. var matches = [];
  2722. var self = this;
  2723. if (this._request != null) {
  2724. // JSONP requests cannot always be aborted
  2725. if ($.isFunction(this._request.abort)) {
  2726. this._request.abort();
  2727. }
  2728. this._request = null;
  2729. }
  2730. var options = $.extend({
  2731. type: 'GET'
  2732. }, this.ajaxOptions);
  2733. if (typeof options.url === 'function') {
  2734. options.url = options.url(params);
  2735. }
  2736. if (typeof options.data === 'function') {
  2737. options.data = options.data(params);
  2738. }
  2739. function request () {
  2740. var $request = options.transport(options, function (data) {
  2741. var results = self.processResults(data, params);
  2742. if (self.options.get('debug') && window.console && console.error) {
  2743. // Check to make sure that the response included a `results` key.
  2744. if (!results || !results.results || !$.isArray(results.results)) {
  2745. console.error(
  2746. 'Select2: The AJAX results did not return an array in the ' +
  2747. '`results` key of the response.'
  2748. );
  2749. }
  2750. }
  2751. callback(results);
  2752. }, function () {
  2753. // TODO: Handle AJAX errors
  2754. });
  2755. self._request = $request;
  2756. }
  2757. if (this.ajaxOptions.delay && params.term !== '') {
  2758. if (this._queryTimeout) {
  2759. window.clearTimeout(this._queryTimeout);
  2760. }
  2761. this._queryTimeout = window.setTimeout(request, this.ajaxOptions.delay);
  2762. } else {
  2763. request();
  2764. }
  2765. };
  2766. return AjaxAdapter;
  2767. });
  2768. S2.define('select2/data/tags',[
  2769. 'jquery'
  2770. ], function ($) {
  2771. function Tags (decorated, $element, options) {
  2772. var tags = options.get('tags');
  2773. var createTag = options.get('createTag');
  2774. if (createTag !== undefined) {
  2775. this.createTag = createTag;
  2776. }
  2777. decorated.call(this, $element, options);
  2778. if ($.isArray(tags)) {
  2779. for (var t = 0; t < tags.length; t++) {
  2780. var tag = tags[t];
  2781. var item = this._normalizeItem(tag);
  2782. var $option = this.option(item);
  2783. this.$element.append($option);
  2784. }
  2785. }
  2786. }
  2787. Tags.prototype.query = function (decorated, params, callback) {
  2788. var self = this;
  2789. this._removeOldTags();
  2790. if (params.term == null || params.page != null) {
  2791. decorated.call(this, params, callback);
  2792. return;
  2793. }
  2794. function wrapper (obj, child) {
  2795. var data = obj.results;
  2796. for (var i = 0; i < data.length; i++) {
  2797. var option = data[i];
  2798. var checkChildren = (
  2799. option.children != null &&
  2800. !wrapper({
  2801. results: option.children
  2802. }, true)
  2803. );
  2804. var checkText = option.text === params.term;
  2805. if (checkText || checkChildren) {
  2806. if (child) {
  2807. return false;
  2808. }
  2809. obj.data = data;
  2810. callback(obj);
  2811. return;
  2812. }
  2813. }
  2814. if (child) {
  2815. return true;
  2816. }
  2817. var tag = self.createTag(params);
  2818. if (tag != null) {
  2819. var $option = self.option(tag);
  2820. $option.attr('data-select2-tag', true);
  2821. self.addOptions([$option]);
  2822. self.insertTag(data, tag);
  2823. }
  2824. obj.results = data;
  2825. callback(obj);
  2826. }
  2827. decorated.call(this, params, wrapper);
  2828. };
  2829. Tags.prototype.createTag = function (decorated, params) {
  2830. var term = $.trim(params.term);
  2831. if (term === '') {
  2832. return null;
  2833. }
  2834. return {
  2835. id: term,
  2836. text: term
  2837. };
  2838. };
  2839. Tags.prototype.insertTag = function (_, data, tag) {
  2840. data.unshift(tag);
  2841. };
  2842. Tags.prototype._removeOldTags = function (_) {
  2843. var tag = this._lastTag;
  2844. var $options = this.$element.find('option[data-select2-tag]');
  2845. $options.each(function () {
  2846. if (this.selected) {
  2847. return;
  2848. }
  2849. $(this).remove();
  2850. });
  2851. };
  2852. return Tags;
  2853. });
  2854. S2.define('select2/data/tokenizer',[
  2855. 'jquery'
  2856. ], function ($) {
  2857. function Tokenizer (decorated, $element, options) {
  2858. var tokenizer = options.get('tokenizer');
  2859. if (tokenizer !== undefined) {
  2860. this.tokenizer = tokenizer;
  2861. }
  2862. decorated.call(this, $element, options);
  2863. }
  2864. Tokenizer.prototype.bind = function (decorated, container, $container) {
  2865. decorated.call(this, container, $container);
  2866. this.$search = container.dropdown.$search || container.selection.$search ||
  2867. $container.find('.select2-search__field');
  2868. };
  2869. Tokenizer.prototype.query = function (decorated, params, callback) {
  2870. var self = this;
  2871. function select (data) {
  2872. self.select(data);
  2873. }
  2874. params.term = params.term || '';
  2875. var tokenData = this.tokenizer(params, this.options, select);
  2876. if (tokenData.term !== params.term) {
  2877. // Replace the search term if we have the search box
  2878. if (this.$search.length) {
  2879. this.$search.val(tokenData.term);
  2880. this.$search.focus();
  2881. }
  2882. params.term = tokenData.term;
  2883. }
  2884. decorated.call(this, params, callback);
  2885. };
  2886. Tokenizer.prototype.tokenizer = function (_, params, options, callback) {
  2887. var separators = options.get('tokenSeparators') || [];
  2888. var term = params.term;
  2889. var i = 0;
  2890. var createTag = this.createTag || function (params) {
  2891. return {
  2892. id: params.term,
  2893. text: params.term
  2894. };
  2895. };
  2896. while (i < term.length) {
  2897. var termChar = term[i];
  2898. if ($.inArray(termChar, separators) === -1) {
  2899. i++;
  2900. continue;
  2901. }
  2902. var part = term.substr(0, i);
  2903. var partParams = $.extend({}, params, {
  2904. term: part
  2905. });
  2906. var data = createTag(partParams);
  2907. callback(data);
  2908. // Reset the term to not include the tokenized portion
  2909. term = term.substr(i + 1) || '';
  2910. i = 0;
  2911. }
  2912. return {
  2913. term: term
  2914. };
  2915. };
  2916. return Tokenizer;
  2917. });
  2918. S2.define('select2/data/minimumInputLength',[
  2919. ], function () {
  2920. function MinimumInputLength (decorated, $e, options) {
  2921. this.minimumInputLength = options.get('minimumInputLength');
  2922. decorated.call(this, $e, options);
  2923. }
  2924. MinimumInputLength.prototype.query = function (decorated, params, callback) {
  2925. params.term = params.term || '';
  2926. if (params.term.length < this.minimumInputLength) {
  2927. this.trigger('results:message', {
  2928. message: 'inputTooShort',
  2929. args: {
  2930. minimum: this.minimumInputLength,
  2931. input: params.term,
  2932. params: params
  2933. }
  2934. });
  2935. return;
  2936. }
  2937. decorated.call(this, params, callback);
  2938. };
  2939. return MinimumInputLength;
  2940. });
  2941. S2.define('select2/data/maximumInputLength',[
  2942. ], function () {
  2943. function MaximumInputLength (decorated, $e, options) {
  2944. this.maximumInputLength = options.get('maximumInputLength');
  2945. decorated.call(this, $e, options);
  2946. }
  2947. MaximumInputLength.prototype.query = function (decorated, params, callback) {
  2948. params.term = params.term || '';
  2949. if (this.maximumInputLength > 0 &&
  2950. params.term.length > this.maximumInputLength) {
  2951. this.trigger('results:message', {
  2952. message: 'inputTooLong',
  2953. args: {
  2954. maximum: this.maximumInputLength,
  2955. input: params.term,
  2956. params: params
  2957. }
  2958. });
  2959. return;
  2960. }
  2961. decorated.call(this, params, callback);
  2962. };
  2963. return MaximumInputLength;
  2964. });
  2965. S2.define('select2/data/maximumSelectionLength',[
  2966. ], function (){
  2967. function MaximumSelectionLength (decorated, $e, options) {
  2968. this.maximumSelectionLength = options.get('maximumSelectionLength');
  2969. decorated.call(this, $e, options);
  2970. }
  2971. MaximumSelectionLength.prototype.query =
  2972. function (decorated, params, callback) {
  2973. var self = this;
  2974. this.current(function (currentData) {
  2975. var count = currentData != null ? currentData.length : 0;
  2976. if (self.maximumSelectionLength > 0 &&
  2977. count >= self.maximumSelectionLength) {
  2978. self.trigger('results:message', {
  2979. message: 'maximumSelected',
  2980. args: {
  2981. maximum: self.maximumSelectionLength
  2982. }
  2983. });
  2984. return;
  2985. }
  2986. decorated.call(self, params, callback);
  2987. });
  2988. };
  2989. return MaximumSelectionLength;
  2990. });
  2991. S2.define('select2/dropdown',[
  2992. 'jquery',
  2993. './utils'
  2994. ], function ($, Utils) {
  2995. function Dropdown ($element, options) {
  2996. this.$element = $element;
  2997. this.options = options;
  2998. Dropdown.__super__.constructor.call(this);
  2999. }
  3000. Utils.Extend(Dropdown, Utils.Observable);
  3001. Dropdown.prototype.render = function () {
  3002. var $dropdown = $(
  3003. '<span class="select2-dropdown">' +
  3004. '<span class="select2-results"></span>' +
  3005. '</span>'
  3006. );
  3007. $dropdown.attr('dir', this.options.get('dir'));
  3008. this.$dropdown = $dropdown;
  3009. return $dropdown;
  3010. };
  3011. Dropdown.prototype.position = function ($dropdown, $container) {
  3012. // Should be implmented in subclasses
  3013. };
  3014. Dropdown.prototype.destroy = function () {
  3015. // Remove the dropdown from the DOM
  3016. this.$dropdown.remove();
  3017. };
  3018. return Dropdown;
  3019. });
  3020. S2.define('select2/dropdown/search',[
  3021. 'jquery',
  3022. '../utils'
  3023. ], function ($, Utils) {
  3024. function Search () { }
  3025. Search.prototype.render = function (decorated) {
  3026. var $rendered = decorated.call(this);
  3027. var $search = $(
  3028. '<span class="select2-search select2-search--dropdown">' +
  3029. '<input class="select2-search__field" type="search" tabindex="-1"' +
  3030. ' autocomplete="off" autocorrect="off" autocapitalize="off"' +
  3031. ' spellcheck="false" role="textbox" />' +
  3032. '</span>'
  3033. );
  3034. this.$searchContainer = $search;
  3035. this.$search = $search.find('input');
  3036. $rendered.prepend($search);
  3037. return $rendered;
  3038. };
  3039. Search.prototype.bind = function (decorated, container, $container) {
  3040. var self = this;
  3041. decorated.call(this, container, $container);
  3042. this.$search.on('keydown', function (evt) {
  3043. self.trigger('keypress', evt);
  3044. self._keyUpPrevented = evt.isDefaultPrevented();
  3045. });
  3046. // Workaround for browsers which do not support the `input` event
  3047. // This will prevent double-triggering of events for browsers which support
  3048. // both the `keyup` and `input` events.
  3049. this.$search.on('input', function (evt) {
  3050. // Unbind the duplicated `keyup` event
  3051. $(this).off('keyup');
  3052. });
  3053. this.$search.on('keyup input', function (evt) {
  3054. self.handleSearch(evt);
  3055. });
  3056. container.on('open', function () {
  3057. self.$search.attr('tabindex', 0);
  3058. self.$search.focus();
  3059. window.setTimeout(function () {
  3060. self.$search.focus();
  3061. }, 0);
  3062. });
  3063. container.on('close', function () {
  3064. self.$search.attr('tabindex', -1);
  3065. self.$search.val('');
  3066. });
  3067. container.on('results:all', function (params) {
  3068. if (params.query.term == null || params.query.term === '') {
  3069. var showSearch = self.showSearch(params);
  3070. if (showSearch) {
  3071. self.$searchContainer.removeClass('select2-search--hide');
  3072. } else {
  3073. self.$searchContainer.addClass('select2-search--hide');
  3074. }
  3075. }
  3076. });
  3077. };
  3078. Search.prototype.handleSearch = function (evt) {
  3079. if (!this._keyUpPrevented) {
  3080. var input = this.$search.val();
  3081. this.trigger('query', {
  3082. term: input
  3083. });
  3084. }
  3085. this._keyUpPrevented = false;
  3086. };
  3087. Search.prototype.showSearch = function (_, params) {
  3088. return true;
  3089. };
  3090. return Search;
  3091. });
  3092. S2.define('select2/dropdown/hidePlaceholder',[
  3093. ], function () {
  3094. function HidePlaceholder (decorated, $element, options, dataAdapter) {
  3095. this.placeholder = this.normalizePlaceholder(options.get('placeholder'));
  3096. decorated.call(this, $element, options, dataAdapter);
  3097. }
  3098. HidePlaceholder.prototype.append = function (decorated, data) {
  3099. data.results = this.removePlaceholder(data.results);
  3100. decorated.call(this, data);
  3101. };
  3102. HidePlaceholder.prototype.normalizePlaceholder = function (_, placeholder) {
  3103. if (typeof placeholder === 'string') {
  3104. placeholder = {
  3105. id: '',
  3106. text: placeholder
  3107. };
  3108. }
  3109. return placeholder;
  3110. };
  3111. HidePlaceholder.prototype.removePlaceholder = function (_, data) {
  3112. var modifiedData = data.slice(0);
  3113. for (var d = data.length - 1; d >= 0; d--) {
  3114. var item = data[d];
  3115. if (this.placeholder.id === item.id) {
  3116. modifiedData.splice(d, 1);
  3117. }
  3118. }
  3119. return modifiedData;
  3120. };
  3121. return HidePlaceholder;
  3122. });
  3123. S2.define('select2/dropdown/infiniteScroll',[
  3124. 'jquery'
  3125. ], function ($) {
  3126. function InfiniteScroll (decorated, $element, options, dataAdapter) {
  3127. this.lastParams = {};
  3128. decorated.call(this, $element, options, dataAdapter);
  3129. this.$loadingMore = this.createLoadingMore();
  3130. this.loading = false;
  3131. }
  3132. InfiniteScroll.prototype.append = function (decorated, data) {
  3133. this.$loadingMore.remove();
  3134. this.loading = false;
  3135. decorated.call(this, data);
  3136. if (this.showLoadingMore(data)) {
  3137. this.$results.append(this.$loadingMore);
  3138. }
  3139. };
  3140. InfiniteScroll.prototype.bind = function (decorated, container, $container) {
  3141. var self = this;
  3142. decorated.call(this, container, $container);
  3143. container.on('query', function (params) {
  3144. self.lastParams = params;
  3145. self.loading = true;
  3146. });
  3147. container.on('query:append', function (params) {
  3148. self.lastParams = params;
  3149. self.loading = true;
  3150. });
  3151. this.$results.on('scroll', function () {
  3152. var isLoadMoreVisible = $.contains(
  3153. document.documentElement,
  3154. self.$loadingMore[0]
  3155. );
  3156. if (self.loading || !isLoadMoreVisible) {
  3157. return;
  3158. }
  3159. var currentOffset = self.$results.offset().top +
  3160. self.$results.outerHeight(false);
  3161. var loadingMoreOffset = self.$loadingMore.offset().top +
  3162. self.$loadingMore.outerHeight(false);
  3163. if (currentOffset + 50 >= loadingMoreOffset) {
  3164. self.loadMore();
  3165. }
  3166. });
  3167. };
  3168. InfiniteScroll.prototype.loadMore = function () {
  3169. this.loading = true;
  3170. var params = $.extend({}, {page: 1}, this.lastParams);
  3171. params.page++;
  3172. this.trigger('query:append', params);
  3173. };
  3174. InfiniteScroll.prototype.showLoadingMore = function (_, data) {
  3175. return data.pagination && data.pagination.more;
  3176. };
  3177. InfiniteScroll.prototype.createLoadingMore = function () {
  3178. var $option = $(
  3179. '<li class="option load-more" role="treeitem"></li>'
  3180. );
  3181. var message = this.options.get('translations').get('loadingMore');
  3182. $option.html(message(this.lastParams));
  3183. return $option;
  3184. };
  3185. return InfiniteScroll;
  3186. });
  3187. S2.define('select2/dropdown/attachBody',[
  3188. 'jquery',
  3189. '../utils'
  3190. ], function ($, Utils) {
  3191. function AttachBody (decorated, $element, options) {
  3192. this.$dropdownParent = options.get('dropdownParent') || document.body;
  3193. decorated.call(this, $element, options);
  3194. }
  3195. AttachBody.prototype.bind = function (decorated, container, $container) {
  3196. var self = this;
  3197. var setupResultsEvents = false;
  3198. decorated.call(this, container, $container);
  3199. container.on('open', function () {
  3200. self._showDropdown();
  3201. self._attachPositioningHandler(container);
  3202. if (!setupResultsEvents) {
  3203. setupResultsEvents = true;
  3204. container.on('results:all', function () {
  3205. self._positionDropdown();
  3206. self._resizeDropdown();
  3207. });
  3208. container.on('results:append', function () {
  3209. self._positionDropdown();
  3210. self._resizeDropdown();
  3211. });
  3212. }
  3213. });
  3214. container.on('close', function () {
  3215. self._hideDropdown();
  3216. self._detachPositioningHandler(container);
  3217. });
  3218. this.$dropdownContainer.on('mousedown', function (evt) {
  3219. evt.stopPropagation();
  3220. });
  3221. };
  3222. AttachBody.prototype.position = function (decorated, $dropdown, $container) {
  3223. // Clone all of the container classes
  3224. $dropdown.attr('class', $container.attr('class'));
  3225. $dropdown.removeClass('select2');
  3226. $dropdown.addClass('select2-container--open');
  3227. $dropdown.css({
  3228. position: 'absolute',
  3229. top: -999999
  3230. });
  3231. this.$container = $container;
  3232. };
  3233. AttachBody.prototype.render = function (decorated) {
  3234. var $container = $('<span></span>');
  3235. var $dropdown = decorated.call(this);
  3236. $container.append($dropdown);
  3237. this.$dropdownContainer = $container;
  3238. return $container;
  3239. };
  3240. AttachBody.prototype._hideDropdown = function (decorated) {
  3241. this.$dropdownContainer.detach();
  3242. };
  3243. AttachBody.prototype._attachPositioningHandler = function (container) {
  3244. var self = this;
  3245. var scrollEvent = 'scroll.select2.' + container.id;
  3246. var resizeEvent = 'resize.select2.' + container.id;
  3247. var orientationEvent = 'orientationchange.select2.' + container.id;
  3248. var $watchers = this.$container.parents().filter(Utils.hasScroll);
  3249. $watchers.each(function () {
  3250. $(this).data('select2-scroll-position', {
  3251. x: $(this).scrollLeft(),
  3252. y: $(this).scrollTop()
  3253. });
  3254. });
  3255. $watchers.on(scrollEvent, function (ev) {
  3256. var position = $(this).data('select2-scroll-position');
  3257. $(this).scrollTop(position.y);
  3258. });
  3259. $(window).on(scrollEvent + ' ' + resizeEvent + ' ' + orientationEvent,
  3260. function (e) {
  3261. self._positionDropdown();
  3262. self._resizeDropdown();
  3263. });
  3264. };
  3265. AttachBody.prototype._detachPositioningHandler = function (container) {
  3266. var scrollEvent = 'scroll.select2.' + container.id;
  3267. var resizeEvent = 'resize.select2.' + container.id;
  3268. var orientationEvent = 'orientationchange.select2.' + container.id;
  3269. var $watchers = this.$container.parents().filter(Utils.hasScroll);
  3270. $watchers.off(scrollEvent);
  3271. $(window).off(scrollEvent + ' ' + resizeEvent + ' ' + orientationEvent);
  3272. };
  3273. AttachBody.prototype._positionDropdown = function () {
  3274. var $window = $(window);
  3275. var isCurrentlyAbove = this.$dropdown.hasClass('select2-dropdown--above');
  3276. var isCurrentlyBelow = this.$dropdown.hasClass('select2-dropdown--below');
  3277. var newDirection = null;
  3278. var position = this.$container.position();
  3279. var offset = this.$container.offset();
  3280. offset.bottom = offset.top + this.$container.outerHeight(false);
  3281. var container = {
  3282. height: this.$container.outerHeight(false)
  3283. };
  3284. container.top = offset.top;
  3285. container.bottom = offset.top + container.height;
  3286. var dropdown = {
  3287. height: this.$dropdown.outerHeight(false)
  3288. };
  3289. var viewport = {
  3290. top: $window.scrollTop(),
  3291. bottom: $window.scrollTop() + $window.height()
  3292. };
  3293. var enoughRoomAbove = viewport.top < (offset.top - dropdown.height);
  3294. var enoughRoomBelow = viewport.bottom > (offset.bottom + dropdown.height);
  3295. var css = {
  3296. left: offset.left,
  3297. top: container.bottom
  3298. };
  3299. if (!isCurrentlyAbove && !isCurrentlyBelow) {
  3300. newDirection = 'below';
  3301. }
  3302. if (!enoughRoomBelow && enoughRoomAbove && !isCurrentlyAbove) {
  3303. newDirection = 'above';
  3304. } else if (!enoughRoomAbove && enoughRoomBelow && isCurrentlyAbove) {
  3305. newDirection = 'below';
  3306. }
  3307. if (newDirection == 'above' ||
  3308. (isCurrentlyAbove && newDirection !== 'below')) {
  3309. css.top = container.top - dropdown.height;
  3310. }
  3311. if (newDirection != null) {
  3312. this.$dropdown
  3313. .removeClass('select2-dropdown--below select2-dropdown--above')
  3314. .addClass('select2-dropdown--' + newDirection);
  3315. this.$container
  3316. .removeClass('select2-container--below select2-container--above')
  3317. .addClass('select2-container--' + newDirection);
  3318. }
  3319. this.$dropdownContainer.css(css);
  3320. };
  3321. AttachBody.prototype._resizeDropdown = function () {
  3322. this.$dropdownContainer.width();
  3323. var css = {
  3324. width: this.$container.outerWidth(false) + 'px'
  3325. };
  3326. if (this.options.get('dropdownAutoWidth')) {
  3327. css.minWidth = css.width;
  3328. css.width = 'auto';
  3329. }
  3330. this.$dropdown.css(css);
  3331. };
  3332. AttachBody.prototype._showDropdown = function (decorated) {
  3333. this.$dropdownContainer.appendTo(this.$dropdownParent);
  3334. this._positionDropdown();
  3335. this._resizeDropdown();
  3336. };
  3337. return AttachBody;
  3338. });
  3339. S2.define('select2/dropdown/minimumResultsForSearch',[
  3340. ], function () {
  3341. function countResults (data) {
  3342. var count = 0;
  3343. for (var d = 0; d < data.length; d++) {
  3344. var item = data[d];
  3345. if (item.children) {
  3346. count += countResults(item.children);
  3347. } else {
  3348. count++;
  3349. }
  3350. }
  3351. return count;
  3352. }
  3353. function MinimumResultsForSearch (decorated, $element, options, dataAdapter) {
  3354. this.minimumResultsForSearch = options.get('minimumResultsForSearch');
  3355. if (this.minimumResultsForSearch < 0) {
  3356. this.minimumResultsForSearch = Infinity;
  3357. }
  3358. decorated.call(this, $element, options, dataAdapter);
  3359. }
  3360. MinimumResultsForSearch.prototype.showSearch = function (decorated, params) {
  3361. if (countResults(params.data.results) < this.minimumResultsForSearch) {
  3362. return false;
  3363. }
  3364. return decorated.call(this, params);
  3365. };
  3366. return MinimumResultsForSearch;
  3367. });
  3368. S2.define('select2/dropdown/selectOnClose',[
  3369. ], function () {
  3370. function SelectOnClose () { }
  3371. SelectOnClose.prototype.bind = function (decorated, container, $container) {
  3372. var self = this;
  3373. decorated.call(this, container, $container);
  3374. container.on('close', function () {
  3375. self._handleSelectOnClose();
  3376. });
  3377. };
  3378. SelectOnClose.prototype._handleSelectOnClose = function () {
  3379. var $highlightedResults = this.getHighlightedResults();
  3380. if ($highlightedResults.length < 1) {
  3381. return;
  3382. }
  3383. this.trigger('select', {
  3384. data: $highlightedResults.data('data')
  3385. });
  3386. };
  3387. return SelectOnClose;
  3388. });
  3389. S2.define('select2/dropdown/closeOnSelect',[
  3390. ], function () {
  3391. function CloseOnSelect () { }
  3392. CloseOnSelect.prototype.bind = function (decorated, container, $container) {
  3393. var self = this;
  3394. decorated.call(this, container, $container);
  3395. container.on('select', function (evt) {
  3396. self._selectTriggered(evt);
  3397. });
  3398. container.on('unselect', function (evt) {
  3399. self._selectTriggered(evt);
  3400. });
  3401. };
  3402. CloseOnSelect.prototype._selectTriggered = function (_, evt) {
  3403. var originalEvent = evt.originalEvent;
  3404. // Don't close if the control key is being held
  3405. if (originalEvent && originalEvent.ctrlKey) {
  3406. return;
  3407. }
  3408. this.trigger('close');
  3409. };
  3410. return CloseOnSelect;
  3411. });
  3412. S2.define('select2/i18n/en',[],function () {
  3413. // English
  3414. return {
  3415. errorLoading: function () {
  3416. return 'The results could not be loaded.';
  3417. },
  3418. inputTooLong: function (args) {
  3419. var overChars = args.input.length - args.maximum;
  3420. var message = 'Please delete ' + overChars + ' character';
  3421. if (overChars != 1) {
  3422. message += 's';
  3423. }
  3424. return message;
  3425. },
  3426. inputTooShort: function (args) {
  3427. var remainingChars = args.minimum - args.input.length;
  3428. var message = 'Please enter ' + remainingChars + ' or more characters';
  3429. return message;
  3430. },
  3431. loadingMore: function () {
  3432. return 'Loading more results…';
  3433. },
  3434. maximumSelected: function (args) {
  3435. var message = 'You can only select ' + args.maximum + ' item';
  3436. if (args.maximum != 1) {
  3437. message += 's';
  3438. }
  3439. return message;
  3440. },
  3441. noResults: function () {
  3442. return 'No results found';
  3443. },
  3444. searching: function () {
  3445. return 'Searching…';
  3446. }
  3447. };
  3448. });
  3449. S2.define('select2/defaults',[
  3450. 'jquery',
  3451. 'require',
  3452. './results',
  3453. './selection/single',
  3454. './selection/multiple',
  3455. './selection/placeholder',
  3456. './selection/allowClear',
  3457. './selection/search',
  3458. './selection/eventRelay',
  3459. './utils',
  3460. './translation',
  3461. './diacritics',
  3462. './data/select',
  3463. './data/array',
  3464. './data/ajax',
  3465. './data/tags',
  3466. './data/tokenizer',
  3467. './data/minimumInputLength',
  3468. './data/maximumInputLength',
  3469. './data/maximumSelectionLength',
  3470. './dropdown',
  3471. './dropdown/search',
  3472. './dropdown/hidePlaceholder',
  3473. './dropdown/infiniteScroll',
  3474. './dropdown/attachBody',
  3475. './dropdown/minimumResultsForSearch',
  3476. './dropdown/selectOnClose',
  3477. './dropdown/closeOnSelect',
  3478. './i18n/en'
  3479. ], function ($, require,
  3480. ResultsList,
  3481. SingleSelection, MultipleSelection, Placeholder, AllowClear,
  3482. SelectionSearch, EventRelay,
  3483. Utils, Translation, DIACRITICS,
  3484. SelectData, ArrayData, AjaxData, Tags, Tokenizer,
  3485. MinimumInputLength, MaximumInputLength, MaximumSelectionLength,
  3486. Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
  3487. AttachBody, MinimumResultsForSearch, SelectOnClose, CloseOnSelect,
  3488. EnglishTranslation) {
  3489. function Defaults () {
  3490. this.reset();
  3491. }
  3492. Defaults.prototype.apply = function (options) {
  3493. options = $.extend({}, this.defaults, options);
  3494. if (options.dataAdapter == null) {
  3495. if (options.ajax != null) {
  3496. options.dataAdapter = AjaxData;
  3497. } else if (options.data != null) {
  3498. options.dataAdapter = ArrayData;
  3499. } else {
  3500. options.dataAdapter = SelectData;
  3501. }
  3502. if (options.minimumInputLength > 0) {
  3503. options.dataAdapter = Utils.Decorate(
  3504. options.dataAdapter,
  3505. MinimumInputLength
  3506. );
  3507. }
  3508. if (options.maximumInputLength > 0) {
  3509. options.dataAdapter = Utils.Decorate(
  3510. options.dataAdapter,
  3511. MaximumInputLength
  3512. );
  3513. }
  3514. if (options.maximumSelectionLength > 0) {
  3515. options.dataAdapter = Utils.Decorate(
  3516. options.dataAdapter,
  3517. MaximumSelectionLength
  3518. );
  3519. }
  3520. if (options.tags) {
  3521. options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
  3522. }
  3523. if (options.tokenSeparators != null || options.tokenizer != null) {
  3524. options.dataAdapter = Utils.Decorate(
  3525. options.dataAdapter,
  3526. Tokenizer
  3527. );
  3528. }
  3529. if (options.query != null) {
  3530. var Query = require(options.amdBase + 'compat/query');
  3531. options.dataAdapter = Utils.Decorate(
  3532. options.dataAdapter,
  3533. Query
  3534. );
  3535. }
  3536. if (options.initSelection != null) {
  3537. var InitSelection = require(options.amdBase + 'compat/initSelection');
  3538. options.dataAdapter = Utils.Decorate(
  3539. options.dataAdapter,
  3540. InitSelection
  3541. );
  3542. }
  3543. }
  3544. if (options.resultsAdapter == null) {
  3545. options.resultsAdapter = ResultsList;
  3546. if (options.ajax != null) {
  3547. options.resultsAdapter = Utils.Decorate(
  3548. options.resultsAdapter,
  3549. InfiniteScroll
  3550. );
  3551. }
  3552. if (options.placeholder != null) {
  3553. options.resultsAdapter = Utils.Decorate(
  3554. options.resultsAdapter,
  3555. HidePlaceholder
  3556. );
  3557. }
  3558. if (options.selectOnClose) {
  3559. options.resultsAdapter = Utils.Decorate(
  3560. options.resultsAdapter,
  3561. SelectOnClose
  3562. );
  3563. }
  3564. }
  3565. if (options.dropdownAdapter == null) {
  3566. if (options.multiple) {
  3567. options.dropdownAdapter = Dropdown;
  3568. } else {
  3569. var SearchableDropdown = Utils.Decorate(Dropdown, DropdownSearch);
  3570. options.dropdownAdapter = SearchableDropdown;
  3571. }
  3572. if (options.minimumResultsForSearch !== 0) {
  3573. options.dropdownAdapter = Utils.Decorate(
  3574. options.dropdownAdapter,
  3575. MinimumResultsForSearch
  3576. );
  3577. }
  3578. if (options.closeOnSelect) {
  3579. options.dropdownAdapter = Utils.Decorate(
  3580. options.dropdownAdapter,
  3581. CloseOnSelect
  3582. );
  3583. }
  3584. if (
  3585. options.dropdownCssClass != null ||
  3586. options.dropdownCss != null ||
  3587. options.adaptDropdownCssClass != null
  3588. ) {
  3589. var DropdownCSS = require(options.amdBase + 'compat/dropdownCss');
  3590. options.dropdownAdapter = Utils.Decorate(
  3591. options.dropdownAdapter,
  3592. DropdownCSS
  3593. );
  3594. }
  3595. options.dropdownAdapter = Utils.Decorate(
  3596. options.dropdownAdapter,
  3597. AttachBody
  3598. );
  3599. }
  3600. if (options.selectionAdapter == null) {
  3601. if (options.multiple) {
  3602. options.selectionAdapter = MultipleSelection;
  3603. } else {
  3604. options.selectionAdapter = SingleSelection;
  3605. }
  3606. // Add the placeholder mixin if a placeholder was specified
  3607. if (options.placeholder != null) {
  3608. options.selectionAdapter = Utils.Decorate(
  3609. options.selectionAdapter,
  3610. Placeholder
  3611. );
  3612. }
  3613. if (options.allowClear) {
  3614. options.selectionAdapter = Utils.Decorate(
  3615. options.selectionAdapter,
  3616. AllowClear
  3617. );
  3618. }
  3619. if (options.multiple) {
  3620. options.selectionAdapter = Utils.Decorate(
  3621. options.selectionAdapter,
  3622. SelectionSearch
  3623. );
  3624. }
  3625. if (
  3626. options.containerCssClass != null ||
  3627. options.containerCss != null ||
  3628. options.adaptContainerCssClass != null
  3629. ) {
  3630. var ContainerCSS = require(options.amdBase + 'compat/containerCss');
  3631. options.selectionAdapter = Utils.Decorate(
  3632. options.selectionAdapter,
  3633. ContainerCSS
  3634. );
  3635. }
  3636. options.selectionAdapter = Utils.Decorate(
  3637. options.selectionAdapter,
  3638. EventRelay
  3639. );
  3640. }
  3641. if (typeof options.language === 'string') {
  3642. // Check if the language is specified with a region
  3643. if (options.language.indexOf('-') > 0) {
  3644. // Extract the region information if it is included
  3645. var languageParts = options.language.split('-');
  3646. var baseLanguage = languageParts[0];
  3647. options.language = [options.language, baseLanguage];
  3648. } else {
  3649. options.language = [options.language];
  3650. }
  3651. }
  3652. if ($.isArray(options.language)) {
  3653. var languages = new Translation();
  3654. options.language.push('en');
  3655. var languageNames = options.language;
  3656. for (var l = 0; l < languageNames.length; l++) {
  3657. var name = languageNames[l];
  3658. var language = {};
  3659. try {
  3660. // Try to load it with the original name
  3661. language = Translation.loadPath(name);
  3662. } catch (e) {
  3663. try {
  3664. // If we couldn't load it, check if it wasn't the full path
  3665. name = this.defaults.amdLanguageBase + name;
  3666. language = Translation.loadPath(name);
  3667. } catch (ex) {
  3668. // The translation could not be loaded at all. Sometimes this is
  3669. // because of a configuration problem, other times this can be
  3670. // because of how Select2 helps load all possible translation files.
  3671. if (options.debug && window.console && console.warn) {
  3672. console.warn(
  3673. 'Select2: The language file for "' + name + '" could not be ' +
  3674. 'automatically loaded. A fallback will be used instead.'
  3675. );
  3676. }
  3677. continue;
  3678. }
  3679. }
  3680. languages.extend(language);
  3681. }
  3682. options.translations = languages;
  3683. } else {
  3684. var baseTranslation = Translation.loadPath(
  3685. this.defaults.amdLanguageBase + 'en'
  3686. );
  3687. var customTranslation = new Translation(options.language);
  3688. customTranslation.extend(baseTranslation);
  3689. options.translations = customTranslation;
  3690. }
  3691. return options;
  3692. };
  3693. Defaults.prototype.reset = function () {
  3694. function stripDiacritics (text) {
  3695. // Used 'uni range + named function' from http://jsperf.com/diacritics/18
  3696. function match(a) {
  3697. return DIACRITICS[a] || a;
  3698. }
  3699. return text.replace(/[^\u0000-\u007E]/g, match);
  3700. }
  3701. function matcher (params, data) {
  3702. // Always return the object if there is nothing to compare
  3703. if ($.trim(params.term) === '') {
  3704. return data;
  3705. }
  3706. // Do a recursive check for options with children
  3707. if (data.children && data.children.length > 0) {
  3708. // Clone the data object if there are children
  3709. // This is required as we modify the object to remove any non-matches
  3710. var match = $.extend(true, {}, data);
  3711. // Check each child of the option
  3712. for (var c = data.children.length - 1; c >= 0; c--) {
  3713. var child = data.children[c];
  3714. var matches = matcher(params, child);
  3715. // If there wasn't a match, remove the object in the array
  3716. if (matches == null) {
  3717. match.children.splice(c, 1);
  3718. }
  3719. }
  3720. // If any children matched, return the new object
  3721. if (match.children.length > 0) {
  3722. return match;
  3723. }
  3724. // If there were no matching children, check just the plain object
  3725. return matcher(params, match);
  3726. }
  3727. var original = stripDiacritics(data.text).toUpperCase();
  3728. var term = stripDiacritics(params.term).toUpperCase();
  3729. // Check if the text contains the term
  3730. if (original.indexOf(term) > -1) {
  3731. return data;
  3732. }
  3733. // If it doesn't contain the term, don't return anything
  3734. return null;
  3735. }
  3736. this.defaults = {
  3737. amdBase: './',
  3738. amdLanguageBase: './i18n/',
  3739. closeOnSelect: true,
  3740. debug: false,
  3741. dropdownAutoWidth: false,
  3742. escapeMarkup: Utils.escapeMarkup,
  3743. language: EnglishTranslation,
  3744. matcher: matcher,
  3745. minimumInputLength: 0,
  3746. maximumInputLength: 0,
  3747. maximumSelectionLength: 0,
  3748. minimumResultsForSearch: 0,
  3749. selectOnClose: false,
  3750. sorter: function (data) {
  3751. return data;
  3752. },
  3753. templateResult: function (result) {
  3754. return result.text;
  3755. },
  3756. templateSelection: function (selection) {
  3757. return selection.text;
  3758. },
  3759. theme: 'default',
  3760. width: 'resolve'
  3761. };
  3762. };
  3763. Defaults.prototype.set = function (key, value) {
  3764. var camelKey = $.camelCase(key);
  3765. var data = {};
  3766. data[camelKey] = value;
  3767. var convertedData = Utils._convertData(data);
  3768. $.extend(this.defaults, convertedData);
  3769. };
  3770. var defaults = new Defaults();
  3771. return defaults;
  3772. });
  3773. S2.define('select2/options',[
  3774. 'require',
  3775. 'jquery',
  3776. './defaults',
  3777. './utils'
  3778. ], function (require, $, Defaults, Utils) {
  3779. function Options (options, $element) {
  3780. this.options = options;
  3781. if ($element != null) {
  3782. this.fromElement($element);
  3783. }
  3784. this.options = Defaults.apply(this.options);
  3785. if ($element && $element.is('input')) {
  3786. var InputCompat = require(this.get('amdBase') + 'compat/inputData');
  3787. this.options.dataAdapter = Utils.Decorate(
  3788. this.options.dataAdapter,
  3789. InputCompat
  3790. );
  3791. }
  3792. }
  3793. Options.prototype.fromElement = function ($e) {
  3794. var excludedData = ['select2'];
  3795. if (this.options.multiple == null) {
  3796. this.options.multiple = $e.prop('multiple');
  3797. }
  3798. if (this.options.disabled == null) {
  3799. this.options.disabled = $e.prop('disabled');
  3800. }
  3801. if (this.options.language == null) {
  3802. if ($e.prop('lang')) {
  3803. this.options.language = $e.prop('lang').toLowerCase();
  3804. } else if ($e.closest('[lang]').prop('lang')) {
  3805. this.options.language = $e.closest('[lang]').prop('lang');
  3806. }
  3807. }
  3808. if (this.options.dir == null) {
  3809. if ($e.prop('dir')) {
  3810. this.options.dir = $e.prop('dir');
  3811. } else if ($e.closest('[dir]').prop('dir')) {
  3812. this.options.dir = $e.closest('[dir]').prop('dir');
  3813. } else {
  3814. this.options.dir = 'ltr';
  3815. }
  3816. }
  3817. $e.prop('disabled', this.options.disabled);
  3818. $e.prop('multiple', this.options.multiple);
  3819. if ($e.data('select2Tags')) {
  3820. if (this.options.debug && window.console && console.warn) {
  3821. console.warn(
  3822. 'Select2: The `data-select2-tags` attribute has been changed to ' +
  3823. 'use the `data-data` and `data-tags="true"` attributes and will be ' +
  3824. 'removed in future versions of Select2.'
  3825. );
  3826. }
  3827. $e.data('data', $e.data('select2Tags'));
  3828. $e.data('tags', true);
  3829. }
  3830. if ($e.data('ajaxUrl')) {
  3831. if (this.options.debug && window.console && console.warn) {
  3832. console.warn(
  3833. 'Select2: The `data-ajax-url` attribute has been changed to ' +
  3834. '`data-ajax--url` and support for the old attribute will be removed' +
  3835. ' in future versions of Select2.'
  3836. );
  3837. }
  3838. $e.attr('ajax--url', $e.data('ajaxUrl'));
  3839. $e.data('ajax--url', $e.data('ajaxUrl'));
  3840. }
  3841. var dataset = {};
  3842. // Prefer the element's `dataset` attribute if it exists
  3843. // jQuery 1.x does not correctly handle data attributes with multiple dashes
  3844. if ($.fn.jquery && $.fn.jquery.substr(0, 2) == '1.' && $e[0].dataset) {
  3845. dataset = $.extend(true, {}, $e[0].dataset, $e.data());
  3846. } else {
  3847. dataset = $e.data();
  3848. }
  3849. var data = $.extend(true, {}, dataset);
  3850. data = Utils._convertData(data);
  3851. for (var key in data) {
  3852. if ($.inArray(key, excludedData) > -1) {
  3853. continue;
  3854. }
  3855. if ($.isPlainObject(this.options[key])) {
  3856. $.extend(this.options[key], data[key]);
  3857. } else {
  3858. this.options[key] = data[key];
  3859. }
  3860. }
  3861. return this;
  3862. };
  3863. Options.prototype.get = function (key) {
  3864. return this.options[key];
  3865. };
  3866. Options.prototype.set = function (key, val) {
  3867. this.options[key] = val;
  3868. };
  3869. return Options;
  3870. });
  3871. S2.define('select2/core',[
  3872. 'jquery',
  3873. './options',
  3874. './utils',
  3875. './keys'
  3876. ], function ($, Options, Utils, KEYS) {
  3877. var Select2 = function ($element, options) {
  3878. if ($element.data('select2') != null) {
  3879. $element.data('select2').destroy();
  3880. }
  3881. this.$element = $element;
  3882. this.id = this._generateId($element);
  3883. options = options || {};
  3884. this.options = new Options(options, $element);
  3885. Select2.__super__.constructor.call(this);
  3886. // Set up the tabindex
  3887. var tabindex = $element.attr('tabindex') || 0;
  3888. $element.data('old-tabindex', tabindex);
  3889. $element.attr('tabindex', '-1');
  3890. // Set up containers and adapters
  3891. var DataAdapter = this.options.get('dataAdapter');
  3892. this.dataAdapter = new DataAdapter($element, this.options);
  3893. var $container = this.render();
  3894. this._placeContainer($container);
  3895. var SelectionAdapter = this.options.get('selectionAdapter');
  3896. this.selection = new SelectionAdapter($element, this.options);
  3897. this.$selection = this.selection.render();
  3898. this.selection.position(this.$selection, $container);
  3899. var DropdownAdapter = this.options.get('dropdownAdapter');
  3900. this.dropdown = new DropdownAdapter($element, this.options);
  3901. this.$dropdown = this.dropdown.render();
  3902. this.dropdown.position(this.$dropdown, $container);
  3903. var ResultsAdapter = this.options.get('resultsAdapter');
  3904. this.results = new ResultsAdapter($element, this.options, this.dataAdapter);
  3905. this.$results = this.results.render();
  3906. this.results.position(this.$results, this.$dropdown);
  3907. // Bind events
  3908. var self = this;
  3909. // Bind the container to all of the adapters
  3910. this._bindAdapters();
  3911. // Register any DOM event handlers
  3912. this._registerDomEvents();
  3913. // Register any internal event handlers
  3914. this._registerDataEvents();
  3915. this._registerSelectionEvents();
  3916. this._registerDropdownEvents();
  3917. this._registerResultsEvents();
  3918. this._registerEvents();
  3919. // Set the initial state
  3920. this.dataAdapter.current(function (initialData) {
  3921. self.trigger('selection:update', {
  3922. data: initialData
  3923. });
  3924. });
  3925. // Hide the original select
  3926. $element.addClass('select2-hidden-accessible');
  3927. $element.attr('aria-hidden', 'true');
  3928. // Synchronize any monitored attributes
  3929. this._syncAttributes();
  3930. $element.data('select2', this);
  3931. };
  3932. Utils.Extend(Select2, Utils.Observable);
  3933. Select2.prototype._generateId = function ($element) {
  3934. var id = '';
  3935. if ($element.attr('id') != null) {
  3936. id = $element.attr('id');
  3937. } else if ($element.attr('name') != null) {
  3938. id = $element.attr('name') + '-' + Utils.generateChars(2);
  3939. } else {
  3940. id = Utils.generateChars(4);
  3941. }
  3942. id = 'select2-' + id;
  3943. return id;
  3944. };
  3945. Select2.prototype._placeContainer = function ($container) {
  3946. $container.insertAfter(this.$element);
  3947. var width = this._resolveWidth(this.$element, this.options.get('width'));
  3948. if (width != null) {
  3949. $container.css('width', width);
  3950. }
  3951. };
  3952. Select2.prototype._resolveWidth = function ($element, method) {
  3953. var WIDTH = /^width:(([-+]?([0-9]*\.)?[0-9]+)(px|em|ex|%|in|cm|mm|pt|pc))/i;
  3954. if (method == 'resolve') {
  3955. var styleWidth = this._resolveWidth($element, 'style');
  3956. if (styleWidth != null) {
  3957. return styleWidth;
  3958. }
  3959. return this._resolveWidth($element, 'element');
  3960. }
  3961. if (method == 'element') {
  3962. var elementWidth = $element.outerWidth(false);
  3963. if (elementWidth <= 0) {
  3964. return 'auto';
  3965. }
  3966. return elementWidth + 'px';
  3967. }
  3968. if (method == 'style') {
  3969. var style = $element.attr('style');
  3970. if (typeof(style) !== 'string') {
  3971. return null;
  3972. }
  3973. var attrs = style.split(';');
  3974. for (var i = 0, l = attrs.length; i < l; i = i + 1) {
  3975. var attr = attrs[i].replace(/\s/g, '');
  3976. var matches = attr.match(WIDTH);
  3977. if (matches !== null && matches.length >= 1) {
  3978. return matches[1];
  3979. }
  3980. }
  3981. return null;
  3982. }
  3983. return method;
  3984. };
  3985. Select2.prototype._bindAdapters = function () {
  3986. this.dataAdapter.bind(this, this.$container);
  3987. this.selection.bind(this, this.$container);
  3988. this.dropdown.bind(this, this.$container);
  3989. this.results.bind(this, this.$container);
  3990. };
  3991. Select2.prototype._registerDomEvents = function () {
  3992. var self = this;
  3993. this.$element.on('change.select2', function () {
  3994. self.dataAdapter.current(function (data) {
  3995. self.trigger('selection:update', {
  3996. data: data
  3997. });
  3998. });
  3999. });
  4000. this._sync = Utils.bind(this._syncAttributes, this);
  4001. if (this.$element[0].attachEvent) {
  4002. this.$element[0].attachEvent('onpropertychange', this._sync);
  4003. }
  4004. var observer = window.MutationObserver ||
  4005. window.WebKitMutationObserver ||
  4006. window.MozMutationObserver
  4007. ;
  4008. if (observer != null) {
  4009. this._observer = new observer(function (mutations) {
  4010. $.each(mutations, self._sync);
  4011. });
  4012. this._observer.observe(this.$element[0], {
  4013. attributes: true,
  4014. subtree: false
  4015. });
  4016. } else if (this.$element[0].addEventListener) {
  4017. this.$element[0].addEventListener('DOMAttrModified', self._sync, false);
  4018. }
  4019. };
  4020. Select2.prototype._registerDataEvents = function () {
  4021. var self = this;
  4022. this.dataAdapter.on('*', function (name, params) {
  4023. self.trigger(name, params);
  4024. });
  4025. };
  4026. Select2.prototype._registerSelectionEvents = function () {
  4027. var self = this;
  4028. var nonRelayEvents = ['toggle'];
  4029. this.selection.on('toggle', function () {
  4030. self.toggleDropdown();
  4031. });
  4032. this.selection.on('*', function (name, params) {
  4033. if ($.inArray(name, nonRelayEvents) !== -1) {
  4034. return;
  4035. }
  4036. self.trigger(name, params);
  4037. });
  4038. };
  4039. Select2.prototype._registerDropdownEvents = function () {
  4040. var self = this;
  4041. this.dropdown.on('*', function (name, params) {
  4042. self.trigger(name, params);
  4043. });
  4044. };
  4045. Select2.prototype._registerResultsEvents = function () {
  4046. var self = this;
  4047. this.results.on('*', function (name, params) {
  4048. self.trigger(name, params);
  4049. });
  4050. };
  4051. Select2.prototype._registerEvents = function () {
  4052. var self = this;
  4053. this.on('open', function () {
  4054. self.$container.addClass('select2-container--open');
  4055. });
  4056. this.on('close', function () {
  4057. self.$container.removeClass('select2-container--open');
  4058. });
  4059. this.on('enable', function () {
  4060. self.$container.removeClass('select2-container--disabled');
  4061. });
  4062. this.on('disable', function () {
  4063. self.$container.addClass('select2-container--disabled');
  4064. });
  4065. this.on('focus', function () {
  4066. self.$container.addClass('select2-container--focus');
  4067. });
  4068. this.on('blur', function () {
  4069. self.$container.removeClass('select2-container--focus');
  4070. });
  4071. this.on('query', function (params) {
  4072. if (!self.isOpen()) {
  4073. self.trigger('open');
  4074. }
  4075. this.dataAdapter.query(params, function (data) {
  4076. self.trigger('results:all', {
  4077. data: data,
  4078. query: params
  4079. });
  4080. });
  4081. });
  4082. this.on('query:append', function (params) {
  4083. this.dataAdapter.query(params, function (data) {
  4084. self.trigger('results:append', {
  4085. data: data,
  4086. query: params
  4087. });
  4088. });
  4089. });
  4090. this.on('keypress', function (evt) {
  4091. var key = evt.which;
  4092. if (self.isOpen()) {
  4093. if (key === KEYS.ENTER) {
  4094. self.trigger('results:select');
  4095. evt.preventDefault();
  4096. } else if ((key === KEYS.SPACE && evt.ctrlKey)) {
  4097. self.trigger('results:toggle');
  4098. evt.preventDefault();
  4099. } else if (key === KEYS.UP) {
  4100. self.trigger('results:previous');
  4101. evt.preventDefault();
  4102. } else if (key === KEYS.DOWN) {
  4103. self.trigger('results:next');
  4104. evt.preventDefault();
  4105. } else if (key === KEYS.ESC || key === KEYS.TAB) {
  4106. self.close();
  4107. evt.preventDefault();
  4108. }
  4109. } else {
  4110. if (key === KEYS.ENTER || key === KEYS.SPACE ||
  4111. ((key === KEYS.DOWN || key === KEYS.UP) && evt.altKey)) {
  4112. self.open();
  4113. evt.preventDefault();
  4114. }
  4115. }
  4116. });
  4117. };
  4118. Select2.prototype._syncAttributes = function () {
  4119. this.options.set('disabled', this.$element.prop('disabled'));
  4120. if (this.options.get('disabled')) {
  4121. if (this.isOpen()) {
  4122. this.close();
  4123. }
  4124. this.trigger('disable');
  4125. } else {
  4126. this.trigger('enable');
  4127. }
  4128. };
  4129. /**
  4130. * Override the trigger method to automatically trigger pre-events when
  4131. * there are events that can be prevented.
  4132. */
  4133. Select2.prototype.trigger = function (name, args) {
  4134. var actualTrigger = Select2.__super__.trigger;
  4135. var preTriggerMap = {
  4136. 'open': 'opening',
  4137. 'close': 'closing',
  4138. 'select': 'selecting',
  4139. 'unselect': 'unselecting'
  4140. };
  4141. if (name in preTriggerMap) {
  4142. var preTriggerName = preTriggerMap[name];
  4143. var preTriggerArgs = {
  4144. prevented: false,
  4145. name: name,
  4146. args: args
  4147. };
  4148. actualTrigger.call(this, preTriggerName, preTriggerArgs);
  4149. if (preTriggerArgs.prevented) {
  4150. args.prevented = true;
  4151. return;
  4152. }
  4153. }
  4154. actualTrigger.call(this, name, args);
  4155. };
  4156. Select2.prototype.toggleDropdown = function () {
  4157. if (this.options.get('disabled')) {
  4158. return;
  4159. }
  4160. if (this.isOpen()) {
  4161. this.close();
  4162. } else {
  4163. this.open();
  4164. }
  4165. };
  4166. Select2.prototype.open = function () {
  4167. if (this.isOpen()) {
  4168. return;
  4169. }
  4170. this.trigger('query', {});
  4171. this.trigger('open');
  4172. };
  4173. Select2.prototype.close = function () {
  4174. if (!this.isOpen()) {
  4175. return;
  4176. }
  4177. this.trigger('close');
  4178. };
  4179. Select2.prototype.isOpen = function () {
  4180. return this.$container.hasClass('select2-container--open');
  4181. };
  4182. Select2.prototype.enable = function (args) {
  4183. if (this.options.get('debug') && window.console && console.warn) {
  4184. console.warn(
  4185. 'Select2: The `select2("enable")` method has been deprecated and will' +
  4186. ' be removed in later Select2 versions. Use $element.prop("disabled")' +
  4187. ' instead.'
  4188. );
  4189. }
  4190. if (args == null || args.length === 0) {
  4191. args = [true];
  4192. }
  4193. var disabled = !args[0];
  4194. this.$element.prop('disabled', disabled);
  4195. };
  4196. Select2.prototype.data = function () {
  4197. if (this.options.get('debug') &&
  4198. arguments.length > 0 && window.console && console.warn) {
  4199. console.warn(
  4200. 'Select2: Data can no longer be set using `select2("data")`. You ' +
  4201. 'should consider setting the value instead using `$element.val()`.'
  4202. );
  4203. }
  4204. var data = [];
  4205. this.dataAdapter.current(function (currentData) {
  4206. data = currentData;
  4207. });
  4208. return data;
  4209. };
  4210. Select2.prototype.val = function (args) {
  4211. if (this.options.get('debug') && window.console && console.warn) {
  4212. console.warn(
  4213. 'Select2: The `select2("val")` method has been deprecated and will be' +
  4214. ' removed in later Select2 versions. Use $element.val() instead.'
  4215. );
  4216. }
  4217. if (args == null || args.length === 0) {
  4218. return this.$element.val();
  4219. }
  4220. var newVal = args[0];
  4221. if ($.isArray(newVal)) {
  4222. newVal = $.map(newVal, function (obj) {
  4223. return obj.toString();
  4224. });
  4225. }
  4226. this.$element.val(newVal).trigger('change');
  4227. };
  4228. Select2.prototype.destroy = function () {
  4229. this.$container.remove();
  4230. if (this.$element[0].detachEvent) {
  4231. this.$element[0].detachEvent('onpropertychange', this._sync);
  4232. }
  4233. if (this._observer != null) {
  4234. this._observer.disconnect();
  4235. this._observer = null;
  4236. } else if (this.$element[0].removeEventListener) {
  4237. this.$element[0]
  4238. .removeEventListener('DOMAttrModified', this._sync, false);
  4239. }
  4240. this._sync = null;
  4241. this.$element.off('.select2');
  4242. this.$element.attr('tabindex', this.$element.data('old-tabindex'));
  4243. this.$element.removeClass('select2-hidden-accessible');
  4244. this.$element.attr('aria-hidden', 'false');
  4245. this.$element.removeData('select2');
  4246. this.dataAdapter.destroy();
  4247. this.selection.destroy();
  4248. this.dropdown.destroy();
  4249. this.results.destroy();
  4250. this.dataAdapter = null;
  4251. this.selection = null;
  4252. this.dropdown = null;
  4253. this.results = null;
  4254. };
  4255. Select2.prototype.render = function () {
  4256. var $container = $(
  4257. '<span class="select2 select2-container">' +
  4258. '<span class="selection"></span>' +
  4259. '<span class="dropdown-wrapper" aria-hidden="true"></span>' +
  4260. '</span>'
  4261. );
  4262. $container.attr('dir', this.options.get('dir'));
  4263. this.$container = $container;
  4264. this.$container.addClass('select2-container--' + this.options.get('theme'));
  4265. $container.data('element', this.$element);
  4266. return $container;
  4267. };
  4268. return Select2;
  4269. });
  4270. S2.define('select2/compat/utils',[
  4271. 'jquery'
  4272. ], function ($) {
  4273. function syncCssClasses ($dest, $src, adapter) {
  4274. var classes, replacements = [], adapted;
  4275. classes = $.trim($dest.attr('class'));
  4276. if (classes) {
  4277. classes = '' + classes; // for IE which returns object
  4278. $(classes.split(/\s+/)).each(function () {
  4279. // Save all Select2 classes
  4280. if (this.indexOf('select2-') === 0) {
  4281. replacements.push(this);
  4282. }
  4283. });
  4284. }
  4285. classes = $.trim($src.attr('class'));
  4286. if (classes) {
  4287. classes = '' + classes; // for IE which returns object
  4288. $(classes.split(/\s+/)).each(function () {
  4289. // Only adapt non-Select2 classes
  4290. if (this.indexOf('select2-') !== 0) {
  4291. adapted = adapter(this);
  4292. if (adapted != null) {
  4293. replacements.push(adapted);
  4294. }
  4295. }
  4296. });
  4297. }
  4298. $dest.attr('class', replacements.join(' '));
  4299. }
  4300. return {
  4301. syncCssClasses: syncCssClasses
  4302. };
  4303. });
  4304. S2.define('select2/compat/containerCss',[
  4305. 'jquery',
  4306. './utils'
  4307. ], function ($, CompatUtils) {
  4308. // No-op CSS adapter that discards all classes by default
  4309. function _containerAdapter (clazz) {
  4310. return null;
  4311. }
  4312. function ContainerCSS () { }
  4313. ContainerCSS.prototype.render = function (decorated) {
  4314. var $container = decorated.call(this);
  4315. var containerCssClass = this.options.get('containerCssClass') || '';
  4316. if ($.isFunction(containerCssClass)) {
  4317. containerCssClass = containerCssClass(this.$element);
  4318. }
  4319. var containerCssAdapter = this.options.get('adaptContainerCssClass');
  4320. containerCssAdapter = containerCssAdapter || _containerAdapter;
  4321. if (containerCssClass.indexOf(':all:') !== -1) {
  4322. containerCssClass = containerCssClass.replace(':all', '');
  4323. var _cssAdapter = containerCssAdapter;
  4324. containerCssAdapter = function (clazz) {
  4325. var adapted = _cssAdapter(clazz);
  4326. if (adapted != null) {
  4327. // Append the old one along with the adapted one
  4328. return adapted + ' ' + clazz;
  4329. }
  4330. return clazz;
  4331. };
  4332. }
  4333. var containerCss = this.options.get('containerCss') || {};
  4334. if ($.isFunction(containerCss)) {
  4335. containerCss = containerCss(this.$element);
  4336. }
  4337. CompatUtils.syncCssClasses($container, this.$element, containerCssAdapter);
  4338. $container.css(containerCss);
  4339. $container.addClass(containerCssClass);
  4340. return $container;
  4341. };
  4342. return ContainerCSS;
  4343. });
  4344. S2.define('select2/compat/dropdownCss',[
  4345. 'jquery',
  4346. './utils'
  4347. ], function ($, CompatUtils) {
  4348. // No-op CSS adapter that discards all classes by default
  4349. function _dropdownAdapter (clazz) {
  4350. return null;
  4351. }
  4352. function DropdownCSS () { }
  4353. DropdownCSS.prototype.render = function (decorated) {
  4354. var $dropdown = decorated.call(this);
  4355. var dropdownCssClass = this.options.get('dropdownCssClass') || '';
  4356. if ($.isFunction(dropdownCssClass)) {
  4357. dropdownCssClass = dropdownCssClass(this.$element);
  4358. }
  4359. var dropdownCssAdapter = this.options.get('adaptDropdownCssClass');
  4360. dropdownCssAdapter = dropdownCssAdapter || _dropdownAdapter;
  4361. if (dropdownCssClass.indexOf(':all:') !== -1) {
  4362. dropdownCssClass = dropdownCssClass.replace(':all', '');
  4363. var _cssAdapter = dropdownCssAdapter;
  4364. dropdownCssAdapter = function (clazz) {
  4365. var adapted = _cssAdapter(clazz);
  4366. if (adapted != null) {
  4367. // Append the old one along with the adapted one
  4368. return adapted + ' ' + clazz;
  4369. }
  4370. return clazz;
  4371. };
  4372. }
  4373. var dropdownCss = this.options.get('dropdownCss') || {};
  4374. if ($.isFunction(dropdownCss)) {
  4375. dropdownCss = dropdownCss(this.$element);
  4376. }
  4377. CompatUtils.syncCssClasses($dropdown, this.$element, dropdownCssAdapter);
  4378. $dropdown.css(dropdownCss);
  4379. $dropdown.addClass(dropdownCssClass);
  4380. return $dropdown;
  4381. };
  4382. return DropdownCSS;
  4383. });
  4384. S2.define('select2/compat/initSelection',[
  4385. 'jquery'
  4386. ], function ($) {
  4387. function InitSelection (decorated, $element, options) {
  4388. if (options.get('debug') && window.console && console.warn) {
  4389. console.warn(
  4390. 'Select2: The `initSelection` option has been deprecated in favor' +
  4391. ' of a custom data adapter that overrides the `current` method. ' +
  4392. 'This method is now called multiple times instead of a single ' +
  4393. 'time when the instance is initialized. Support will be removed ' +
  4394. 'for the `initSelection` option in future versions of Select2'
  4395. );
  4396. }
  4397. this.initSelection = options.get('initSelection');
  4398. this._isInitialized = false;
  4399. decorated.call(this, $element, options);
  4400. }
  4401. InitSelection.prototype.current = function (decorated, callback) {
  4402. var self = this;
  4403. if (this._isInitialized) {
  4404. decorated.call(this, callback);
  4405. return;
  4406. }
  4407. this.initSelection.call(null, this.$element, function (data) {
  4408. self._isInitialized = true;
  4409. if (!$.isArray(data)) {
  4410. data = [data];
  4411. }
  4412. callback(data);
  4413. });
  4414. };
  4415. return InitSelection;
  4416. });
  4417. S2.define('select2/compat/inputData',[
  4418. 'jquery'
  4419. ], function ($) {
  4420. function InputData (decorated, $element, options) {
  4421. this._currentData = [];
  4422. this._valueSeparator = options.get('valueSeparator') || ',';
  4423. if ($element.prop('type') === 'hidden') {
  4424. if (options.get('debug') && console && console.warn) {
  4425. console.warn(
  4426. 'Select2: Using a hidden input with Select2 is no longer ' +
  4427. 'supported and may stop working in the future. It is recommended ' +
  4428. 'to use a `<select>` element instead.'
  4429. );
  4430. }
  4431. }
  4432. decorated.call(this, $element, options);
  4433. }
  4434. InputData.prototype.current = function (_, callback) {
  4435. function getSelected (data, selectedIds) {
  4436. var selected = [];
  4437. if (data.selected || $.inArray(data.id, selectedIds) !== -1) {
  4438. data.selected = true;
  4439. selected.push(data);
  4440. } else {
  4441. data.selected = false;
  4442. }
  4443. if (data.children) {
  4444. selected.push.apply(selected, getSelected(data.children, selectedIds));
  4445. }
  4446. return selected;
  4447. }
  4448. var selected = [];
  4449. for (var d = 0; d < this._currentData.length; d++) {
  4450. var data = this._currentData[d];
  4451. selected.push.apply(
  4452. selected,
  4453. getSelected(
  4454. data,
  4455. this.$element.val().split(
  4456. this._valueSeparator
  4457. )
  4458. )
  4459. );
  4460. }
  4461. callback(selected);
  4462. };
  4463. InputData.prototype.select = function (_, data) {
  4464. if (!this.options.get('multiple')) {
  4465. this.current(function (allData) {
  4466. $.map(allData, function (data) {
  4467. data.selected = false;
  4468. });
  4469. });
  4470. this.$element.val(data.id);
  4471. this.$element.trigger('change');
  4472. } else {
  4473. var value = this.$element.val();
  4474. value += this._valueSeparator + data.id;
  4475. this.$element.val(value);
  4476. this.$element.trigger('change');
  4477. }
  4478. };
  4479. InputData.prototype.unselect = function (_, data) {
  4480. var self = this;
  4481. data.selected = false;
  4482. this.current(function (allData) {
  4483. var values = [];
  4484. for (var d = 0; d < allData.length; d++) {
  4485. var item = allData[d];
  4486. if (data.id == item.id) {
  4487. continue;
  4488. }
  4489. values.push(item.id);
  4490. }
  4491. self.$element.val(values.join(self._valueSeparator));
  4492. self.$element.trigger('change');
  4493. });
  4494. };
  4495. InputData.prototype.query = function (_, params, callback) {
  4496. var results = [];
  4497. for (var d = 0; d < this._currentData.length; d++) {
  4498. var data = this._currentData[d];
  4499. var matches = this.matches(params, data);
  4500. if (matches !== null) {
  4501. results.push(matches);
  4502. }
  4503. }
  4504. callback({
  4505. results: results
  4506. });
  4507. };
  4508. InputData.prototype.addOptions = function (_, $options) {
  4509. var options = $.map($options, function ($option) {
  4510. return $.data($option[0], 'data');
  4511. });
  4512. this._currentData.push.apply(this._currentData, options);
  4513. };
  4514. return InputData;
  4515. });
  4516. S2.define('select2/compat/matcher',[
  4517. 'jquery'
  4518. ], function ($) {
  4519. function oldMatcher (matcher) {
  4520. function wrappedMatcher (params, data) {
  4521. var match = $.extend(true, {}, data);
  4522. if (params.term == null || $.trim(params.term) === '') {
  4523. return match;
  4524. }
  4525. if (data.children) {
  4526. for (var c = data.children.length - 1; c >= 0; c--) {
  4527. var child = data.children[c];
  4528. // Check if the child object matches
  4529. // The old matcher returned a boolean true or false
  4530. var doesMatch = matcher(params.term, child.text, child);
  4531. // If the child didn't match, pop it off
  4532. if (!doesMatch) {
  4533. match.children.splice(c, 1);
  4534. }
  4535. }
  4536. if (match.children.length > 0) {
  4537. return match;
  4538. }
  4539. }
  4540. if (matcher(params.term, data.text, data)) {
  4541. return match;
  4542. }
  4543. return null;
  4544. }
  4545. return wrappedMatcher;
  4546. }
  4547. return oldMatcher;
  4548. });
  4549. S2.define('select2/compat/query',[
  4550. ], function () {
  4551. function Query (decorated, $element, options) {
  4552. if (options.get('debug') && window.console && console.warn) {
  4553. console.warn(
  4554. 'Select2: The `query` option has been deprecated in favor of a ' +
  4555. 'custom data adapter that overrides the `query` method. Support ' +
  4556. 'will be removed for the `query` option in future versions of ' +
  4557. 'Select2.'
  4558. );
  4559. }
  4560. decorated.call(this, $element, options);
  4561. }
  4562. Query.prototype.query = function (_, params, callback) {
  4563. params.callback = callback;
  4564. var query = this.options.get('query');
  4565. query.call(null, params);
  4566. };
  4567. return Query;
  4568. });
  4569. S2.define('select2/dropdown/attachContainer',[
  4570. ], function () {
  4571. function AttachContainer (decorated, $element, options) {
  4572. decorated.call(this, $element, options);
  4573. }
  4574. AttachContainer.prototype.position =
  4575. function (decorated, $dropdown, $container) {
  4576. var $dropdownContainer = $container.find('.dropdown-wrapper');
  4577. $dropdownContainer.append($dropdown);
  4578. $dropdown.addClass('select2-dropdown--below');
  4579. $container.addClass('select2-container--below');
  4580. };
  4581. return AttachContainer;
  4582. });
  4583. S2.define('select2/dropdown/stopPropagation',[
  4584. ], function () {
  4585. function StopPropagation () { }
  4586. StopPropagation.prototype.bind = function (decorated, container, $container) {
  4587. decorated.call(this, container, $container);
  4588. var stoppedEvents = [
  4589. 'blur',
  4590. 'change',
  4591. 'click',
  4592. 'dblclick',
  4593. 'focus',
  4594. 'focusin',
  4595. 'focusout',
  4596. 'input',
  4597. 'keydown',
  4598. 'keyup',
  4599. 'keypress',
  4600. 'mousedown',
  4601. 'mouseenter',
  4602. 'mouseleave',
  4603. 'mousemove',
  4604. 'mouseover',
  4605. 'mouseup',
  4606. 'search',
  4607. 'touchend',
  4608. 'touchstart'
  4609. ];
  4610. this.$dropdown.on(stoppedEvents.join(' '), function (evt) {
  4611. evt.stopPropagation();
  4612. });
  4613. };
  4614. return StopPropagation;
  4615. });
  4616. S2.define('select2/selection/stopPropagation',[
  4617. ], function () {
  4618. function StopPropagation () { }
  4619. StopPropagation.prototype.bind = function (decorated, container, $container) {
  4620. decorated.call(this, container, $container);
  4621. var stoppedEvents = [
  4622. 'blur',
  4623. 'change',
  4624. 'click',
  4625. 'dblclick',
  4626. 'focus',
  4627. 'focusin',
  4628. 'focusout',
  4629. 'input',
  4630. 'keydown',
  4631. 'keyup',
  4632. 'keypress',
  4633. 'mousedown',
  4634. 'mouseenter',
  4635. 'mouseleave',
  4636. 'mousemove',
  4637. 'mouseover',
  4638. 'mouseup',
  4639. 'search',
  4640. 'touchend',
  4641. 'touchstart'
  4642. ];
  4643. this.$selection.on(stoppedEvents.join(' '), function (evt) {
  4644. evt.stopPropagation();
  4645. });
  4646. };
  4647. return StopPropagation;
  4648. });
  4649. S2.define('jquery.select2',[
  4650. 'jquery',
  4651. 'require',
  4652. './select2/core',
  4653. './select2/defaults'
  4654. ], function ($, require, Select2, Defaults) {
  4655. // Force jQuery.mousewheel to be loaded if it hasn't already
  4656. require('jquery.mousewheel');
  4657. if ($.fn.select2 == null) {
  4658. // All methods that should return the element
  4659. var thisMethods = ['open', 'close', 'destroy'];
  4660. $.fn.select2 = function (options) {
  4661. options = options || {};
  4662. if (typeof options === 'object') {
  4663. this.each(function () {
  4664. var instanceOptions = $.extend({}, options, true);
  4665. var instance = new Select2($(this), instanceOptions);
  4666. });
  4667. return this;
  4668. } else if (typeof options === 'string') {
  4669. var instance = this.data('select2');
  4670. if (instance == null && window.console && console.error) {
  4671. console.error(
  4672. 'The select2(\'' + options + '\') method was called on an ' +
  4673. 'element that is not using Select2.'
  4674. );
  4675. }
  4676. var args = Array.prototype.slice.call(arguments, 1);
  4677. var ret = instance[options](args);
  4678. // Check if we should be returning `this`
  4679. if ($.inArray(options, thisMethods) > -1) {
  4680. return this;
  4681. }
  4682. return ret;
  4683. } else {
  4684. throw new Error('Invalid arguments for Select2: ' + options);
  4685. }
  4686. };
  4687. }
  4688. if ($.fn.select2.defaults == null) {
  4689. $.fn.select2.defaults = Defaults;
  4690. }
  4691. return Select2;
  4692. });
  4693. /*!
  4694. * jQuery Mousewheel 3.1.12
  4695. *
  4696. * Copyright 2014 jQuery Foundation and other contributors
  4697. * Released under the MIT license.
  4698. * http://jquery.org/license
  4699. */
  4700. (function (factory) {
  4701. if ( typeof S2.define === 'function' && S2.define.amd ) {
  4702. // AMD. Register as an anonymous module.
  4703. S2.define('jquery.mousewheel',['jquery'], factory);
  4704. } else if (typeof exports === 'object') {
  4705. // Node/CommonJS style for Browserify
  4706. module.exports = factory;
  4707. } else {
  4708. // Browser globals
  4709. factory(jQuery);
  4710. }
  4711. }(function ($) {
  4712. var toFix = ['wheel', 'mousewheel', 'DOMMouseScroll', 'MozMousePixelScroll'],
  4713. toBind = ( 'onwheel' in document || document.documentMode >= 9 ) ?
  4714. ['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'],
  4715. slice = Array.prototype.slice,
  4716. nullLowestDeltaTimeout, lowestDelta;
  4717. if ( $.event.fixHooks ) {
  4718. for ( var i = toFix.length; i; ) {
  4719. $.event.fixHooks[ toFix[--i] ] = $.event.mouseHooks;
  4720. }
  4721. }
  4722. var special = $.event.special.mousewheel = {
  4723. version: '3.1.12',
  4724. setup: function() {
  4725. if ( this.addEventListener ) {
  4726. for ( var i = toBind.length; i; ) {
  4727. this.addEventListener( toBind[--i], handler, false );
  4728. }
  4729. } else {
  4730. this.onmousewheel = handler;
  4731. }
  4732. // Store the line height and page height for this particular element
  4733. $.data(this, 'mousewheel-line-height', special.getLineHeight(this));
  4734. $.data(this, 'mousewheel-page-height', special.getPageHeight(this));
  4735. },
  4736. teardown: function() {
  4737. if ( this.removeEventListener ) {
  4738. for ( var i = toBind.length; i; ) {
  4739. this.removeEventListener( toBind[--i], handler, false );
  4740. }
  4741. } else {
  4742. this.onmousewheel = null;
  4743. }
  4744. // Clean up the data we added to the element
  4745. $.removeData(this, 'mousewheel-line-height');
  4746. $.removeData(this, 'mousewheel-page-height');
  4747. },
  4748. getLineHeight: function(elem) {
  4749. var $elem = $(elem),
  4750. $parent = $elem['offsetParent' in $.fn ? 'offsetParent' : 'parent']();
  4751. if (!$parent.length) {
  4752. $parent = $('body');
  4753. }
  4754. return parseInt($parent.css('fontSize'), 10) || parseInt($elem.css('fontSize'), 10) || 16;
  4755. },
  4756. getPageHeight: function(elem) {
  4757. return $(elem).height();
  4758. },
  4759. settings: {
  4760. adjustOldDeltas: true, // see shouldAdjustOldDeltas() below
  4761. normalizeOffset: true // calls getBoundingClientRect for each event
  4762. }
  4763. };
  4764. $.fn.extend({
  4765. mousewheel: function(fn) {
  4766. return fn ? this.bind('mousewheel', fn) : this.trigger('mousewheel');
  4767. },
  4768. unmousewheel: function(fn) {
  4769. return this.unbind('mousewheel', fn);
  4770. }
  4771. });
  4772. function handler(event) {
  4773. var orgEvent = event || window.event,
  4774. args = slice.call(arguments, 1),
  4775. delta = 0,
  4776. deltaX = 0,
  4777. deltaY = 0,
  4778. absDelta = 0,
  4779. offsetX = 0,
  4780. offsetY = 0;
  4781. event = $.event.fix(orgEvent);
  4782. event.type = 'mousewheel';
  4783. // Old school scrollwheel delta
  4784. if ( 'detail' in orgEvent ) { deltaY = orgEvent.detail * -1; }
  4785. if ( 'wheelDelta' in orgEvent ) { deltaY = orgEvent.wheelDelta; }
  4786. if ( 'wheelDeltaY' in orgEvent ) { deltaY = orgEvent.wheelDeltaY; }
  4787. if ( 'wheelDeltaX' in orgEvent ) { deltaX = orgEvent.wheelDeltaX * -1; }
  4788. // Firefox < 17 horizontal scrolling related to DOMMouseScroll event
  4789. if ( 'axis' in orgEvent && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) {
  4790. deltaX = deltaY * -1;
  4791. deltaY = 0;
  4792. }
  4793. // Set delta to be deltaY or deltaX if deltaY is 0 for backwards compatabilitiy
  4794. delta = deltaY === 0 ? deltaX : deltaY;
  4795. // New school wheel delta (wheel event)
  4796. if ( 'deltaY' in orgEvent ) {
  4797. deltaY = orgEvent.deltaY * -1;
  4798. delta = deltaY;
  4799. }
  4800. if ( 'deltaX' in orgEvent ) {
  4801. deltaX = orgEvent.deltaX;
  4802. if ( deltaY === 0 ) { delta = deltaX * -1; }
  4803. }
  4804. // No change actually happened, no reason to go any further
  4805. if ( deltaY === 0 && deltaX === 0 ) { return; }
  4806. // Need to convert lines and pages to pixels if we aren't already in pixels
  4807. // There are three delta modes:
  4808. // * deltaMode 0 is by pixels, nothing to do
  4809. // * deltaMode 1 is by lines
  4810. // * deltaMode 2 is by pages
  4811. if ( orgEvent.deltaMode === 1 ) {
  4812. var lineHeight = $.data(this, 'mousewheel-line-height');
  4813. delta *= lineHeight;
  4814. deltaY *= lineHeight;
  4815. deltaX *= lineHeight;
  4816. } else if ( orgEvent.deltaMode === 2 ) {
  4817. var pageHeight = $.data(this, 'mousewheel-page-height');
  4818. delta *= pageHeight;
  4819. deltaY *= pageHeight;
  4820. deltaX *= pageHeight;
  4821. }
  4822. // Store lowest absolute delta to normalize the delta values
  4823. absDelta = Math.max( Math.abs(deltaY), Math.abs(deltaX) );
  4824. if ( !lowestDelta || absDelta < lowestDelta ) {
  4825. lowestDelta = absDelta;
  4826. // Adjust older deltas if necessary
  4827. if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) {
  4828. lowestDelta /= 40;
  4829. }
  4830. }
  4831. // Adjust older deltas if necessary
  4832. if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) {
  4833. // Divide all the things by 40!
  4834. delta /= 40;
  4835. deltaX /= 40;
  4836. deltaY /= 40;
  4837. }
  4838. // Get a whole, normalized value for the deltas
  4839. delta = Math[ delta >= 1 ? 'floor' : 'ceil' ](delta / lowestDelta);
  4840. deltaX = Math[ deltaX >= 1 ? 'floor' : 'ceil' ](deltaX / lowestDelta);
  4841. deltaY = Math[ deltaY >= 1 ? 'floor' : 'ceil' ](deltaY / lowestDelta);
  4842. // Normalise offsetX and offsetY properties
  4843. if ( special.settings.normalizeOffset && this.getBoundingClientRect ) {
  4844. var boundingRect = this.getBoundingClientRect();
  4845. offsetX = event.clientX - boundingRect.left;
  4846. offsetY = event.clientY - boundingRect.top;
  4847. }
  4848. // Add information to the event object
  4849. event.deltaX = deltaX;
  4850. event.deltaY = deltaY;
  4851. event.deltaFactor = lowestDelta;
  4852. event.offsetX = offsetX;
  4853. event.offsetY = offsetY;
  4854. // Go ahead and set deltaMode to 0 since we converted to pixels
  4855. // Although this is a little odd since we overwrite the deltaX/Y
  4856. // properties with normalized deltas.
  4857. event.deltaMode = 0;
  4858. // Add event and delta to the front of the arguments
  4859. args.unshift(event, delta, deltaX, deltaY);
  4860. // Clearout lowestDelta after sometime to better
  4861. // handle multiple device types that give different
  4862. // a different lowestDelta
  4863. // Ex: trackpad = 3 and mouse wheel = 120
  4864. if (nullLowestDeltaTimeout) { clearTimeout(nullLowestDeltaTimeout); }
  4865. nullLowestDeltaTimeout = setTimeout(nullLowestDelta, 200);
  4866. return ($.event.dispatch || $.event.handle).apply(this, args);
  4867. }
  4868. function nullLowestDelta() {
  4869. lowestDelta = null;
  4870. }
  4871. function shouldAdjustOldDeltas(orgEvent, absDelta) {
  4872. // If this is an older event and the delta is divisable by 120,
  4873. // then we are assuming that the browser is treating this as an
  4874. // older mouse wheel event and that we should divide the deltas
  4875. // by 40 to try and get a more usable deltaFactor.
  4876. // Side note, this actually impacts the reported scroll distance
  4877. // in older browsers and can cause scrolling to be slower than native.
  4878. // Turn this off by setting $.event.special.mousewheel.settings.adjustOldDeltas to false.
  4879. return special.settings.adjustOldDeltas && orgEvent.type === 'mousewheel' && absDelta % 120 === 0;
  4880. }
  4881. }));
  4882. // Return the AMD loader configuration so it can be used outside of this file
  4883. return {
  4884. define: S2.define,
  4885. require: S2.require
  4886. };
  4887. }());
  4888. // Autoload the jQuery bindings
  4889. // We know that all of the modules exist above this, so we're safe
  4890. var select2 = S2.require('jquery.select2');
  4891. // Hold the AMD module references on the jQuery function that was just loaded
  4892. // This allows Select2 to use the internal loader outside of this file, such
  4893. // as in the language files.
  4894. jQuery.fn.select2.amd = S2;
  4895. // Return the Select2 instance for anyone who is importing it.
  4896. return select2;
  4897. }));