Ei kuvausta

select2.full.js 172KB

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