select2.full.js 151 KB

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