select2.full.js 154 KB

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