select2.js 159 KB

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