select2.full.js 161 KB

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