select2.full.js 174 KB

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