select2.full.js 163 KB

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