select2.full.js 155 KB

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