select2.full.js 178 KB

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